سلام
من یه callback واسه کرس دارم که AUC رو آخر هر اپچ برای validation data حساب کنه. ولی متاسفانه با fit_generator کار نمیکنه. کد و خطا که میده رو اینجا میزارم.
# roc callsback
from keras.callbacks import Callback
from sklearn.metrics import roc_auc_score
class RocAucMetric(Callback):
def on_train_begin(self, logs={}):
# By default, self.params['metrics'] contains loss and the metric assigned in `model.compile()`
if not 'val_roc_auc' in self.params['metrics']:
self.params['metrics'].append('val_roc_auc')
logs['val_roc_auc'] = float('-inf')
def on_epoch_end(self, epoch, logs={}):
y_true = self.validation_data[1]
y_pred = self.model.predict(self.validation_data[0])
score = roc_auc_score(y_true, y_pred)
logs['val_roc_auc'] = score
history = model.fit_generator(
data_gen(train, id_label_map, batch_size, augment=True),
validation_data=data_gen(val, id_label_map, batch_size),
epochs = epoch_num_main, verbose = 1,
callbacks=[RocAucMetric(),ModelCheckpoint(h5_path, monitor='val_roc_auc', save_best_only=True, mode='max',
save_weights_only=True) , csv_logger, LR_drop],
, steps_per_epoch=len(train) // batch_size,
validation_steps=len(val) // batch_size
)
error
<ipython-input-17-2d3c64d5f908> in on_epoch_end(self, epoch, logs)
13
14 def on_epoch_end(self, epoch, logs={}):
---> 15 y_true = self.validation_data[1]
16 y_pred = self.model.predict(self.validation_data[0])
17 score = roc_auc_score(y_true, y_pred)
TypeError: 'NoneType' object is not subscriptable