juntang-zhuang/Adabelief-Optimizer

Model load shows error message. ValueError: Unknown optimizer: AdaBeliefOptimizer

damianospark opened this issue · 1 comments

Dear all.
I am excited to use Adabelief. And today I installed the package and tested it in my ML training successfully.
When I load the model.h5 file to in different machine, the application keep showing error message as follows even if I installed the package whose command is 'pip3 install adabelief-tf==0.2.0' in both of machine whose OS is ubuntu 18.04 and Mac OSX.

It would be appreciated if you let me know if I am missing in your installation guide.

Best regards.

---- error message in the model loading side (Mac OS)----

2021-01-11 14:53:45.527256: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-01-11 14:53:45.539315: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fc89ebcc5b0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-01-11 14:53:45.539342: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
File "drive.py", line 125, in
model = load_model(args.model)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/saving/save.py", line 182, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 193, in load_model_from_hdf5
model.compile(**saving_utils.compile_args_from_training_config(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/saving/saving_utils.py", line 211, in compile_args_from_training_config
optimizer = optimizers.deserialize(optimizer_config)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/optimizers.py", line 865, in deserialize
return deserialize_keras_object(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 346, in deserialize_keras_object
(cls, cls_config) = class_and_config_for_serialized_keras_object(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 296, in class_and_config_for_serialized_keras_object
raise ValueError('Unknown ' + printable_module_name + ': ' + class_name)
ValueError: Unknown optimizer: AdaBeliefOptimizer

Hi @damianospark, if you save a model with custom objects (like AdaBelief or some custom layers), you will also need to specify the custom objects when you are loading the model, so please try the following code to load the model:
model = tf.keras.models.load_model('./model.h5', custom_objects={'AdaBeliefOptimizer':AdaBeliefOptimizer})

Another option is to load the model without compiling, so you don't need to keep the code:
model = tf.keras.models.load_model('./model.h5', compile=False)