Reputation: 640
I want to use Keras ModelCheckpoint callback to monitor several parameters ( I have a multi-task network). Is it possible with just one callback ? Or do I need to do that in many callbacks ??
The ckechpoint creation :
checkpointer = ModelCheckpoint(filepath='checkpoints/weights-{epoch:02d}.hdf5', monitor='val_O1_categorical_accuracy' , verbose=1, save_best_only=True, mode='max')
The second parameter I want to monitor : val_O2_categorical_accuracy
Doing that in a list will not work. i.e.
checkpointer = ModelCheckpoint(filepath='checkpoints/weights-{epoch:02d}.hdf5', monitor=['val_O1_categorical_accuracy','val_O2_categorical_accuracy'] , verbose=1, save_best_only=True, mode='max')
TypeError: unhashable type: 'list'
Upvotes: 6
Views: 7657
Reputation: 9081
I am afraid you will have to do it in separate instances. Think about what is happening here -
checkpointer = ModelCheckpoint(filepath='checkpoints/weights-{epoch:02d}.hdf5', monitor='val_O1_categorical_accuracy' , verbose=1, save_best_only=True, mode='max')
When you are saving a model by monitoring val_O1_categorical_accuracy
, here is what it will do in pseudocode -
for each epoch:
check the val_O1_categorical_accuracy after updating weights
if this metric is better in this epoch than the previous ones:
save the model
else
pass
So really specifying multiple monitor
is out of scope. In this case it has to be an either/or choice as based on a monitor
metric only one model among other conflicting models can be the best one.
Upvotes: 2