TypeError:当我训练CNN模型时,“ NoneType”对象无法下标

我是一个初学者,致力于CNN进行图像分类,并且具有以下波纹管回调函数;

class Metrics(Callback):
    def on_train_begin(self, logs = {}):
        self.val_kappas = []

    def on_epoch_end(self, epoch, logs = {}):
        X_val, y_val = self.validation_data[:2]
        y_val = y_val.sum(axis = 1) - 1

        y_pred = self.model.predict(X_val) > 0.5
        y_pred = y_pred.astype(int).sum(axis = 1) - 1

        _val_kappa = cohen_kappa_score(
            y_val,
            y_pred, 
            weights = 'quadratic'
        )

        self.val_kappas.append(_val_kappa)

        print(f"val_kappa: {_val_kappa:.4f}")

        if _val_kappa == max(self.val_kappas):
            print("Validation Kappa has improved. Saving model.")
            self.model.save('/path_to/model.h5')

        return

当我训练模型时;

kappa_metrics = Metrics()

history = model.fit(
    data_generator,
    steps_per_epoch = x_train.shape[0] / BATCH_SIZE,
    epochs = 15,
    validation_data = (x_val, y_val),
    callbacks = [kappa_metrics]
)

I get the following error; enter image description here

不幸的是,我不明白我犯了什么错误。请注意,我是CNN和Python的初学者。

评论