Using custom optimizer in Keras after loading model

654 Views Asked by At

I would like to use an AdamW optimizer in keras for NN training, according to: https://github.com/GLambard/AdamW_Keras

I import it and the code appears to work as advertised. Unfortunately, when I load a saved checkpoint, I get an error:

file "ResUNET.py", line 209, in <module>
'peteLoss': mc.peteLoss, 'iou_one_Metric': mc.iou_one_Metric, 'adamw': adamw})
File "/home/pete/anaconda3/lib/python3.6/site-packages/keras/engine/saving.py", line 276, in load_model
custom_objects=custom_objects)
File "/home/pete/anaconda3/lib/python3.6/site-packages/keras/optimizers.py", line 760, in deserialize
printable_module_name='optimizer')
File "/home/pete/anaconda3/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 138, in deserialize_keras_object
': ' + class_name)
ValueError: Unknown optimizer: AdamW

I do pass the custom object according to:

model = load_model(save_model_name,custom_objects={
   'my_iou_metric': mc.my_iou_metric, 
   'my_iou_metric_2': mc.my_iou_metric_2,
   'lovasz_loss': mc.lovasz_loss, 
   'peteLoss': mc.peteLoss, 
   'iou_one_Metric': mc.iou_one_Metric,
   'adamw': adamw})

This works for losses, etc but fails for the optimizer.

0

There are 0 best solutions below