I tried to use load_model(model, custom_objects={'MyLayer': MyLayer})
however, it came out with the error:
model = model_from_config(model_config, custom_objects=custom_objects)
File " python2.7/site-packages/keras/models.py", line 309, in model_from_config
return layer_module.deserialize(config, custom_objects=custom_objects)
File " python2.7/site-packages/keras/layers/__init__.py", line 54, in deserialize
printable_module_name='layer')
File " python2.7/site-packages/keras/utils/generic_utils.py", line 139, in deserialize_keras_object
list(custom_objects.items())))
File " python2.7/site-packages/keras/models.py", line 1211, in from_config
layer = layer_module.deserialize(conf, custom_objects=custom_objects)
File " python2.7/site-packages/keras/layers/__init__.py", line 54, in deserialize
printable_module_name='layer')
File " /anaconda3/envs/proj1/lib/python2.7/site-packages/keras/utils/generic_utils.py", line 133, in deserialize_keras_object
': ' + class_name)
ValueError: Unknown layer: MyLayer
Should I define any names for the layer?
I also tried the following code, it also had the same error:
`
from keras.models import model_from_json
json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
tmp_model = model_from_json(loaded_model_json, custom_objects={'attention': MyLayer()})
tmp_model.load_weights("model.h5")
`
see #6529
Thanks. @xiaoleihuang I resolve it.
I think you should write like this custom_objects={'MyLayer': MyLayer()}
Most helpful comment
Thanks. @xiaoleihuang I resolve it.
I think you should write like this
custom_objects={'MyLayer': MyLayer()}