anlalalu / Q-testing

22 stars 7 forks source link

ValueError: Unknown layer:layers when I load the model,how can I fix it? #12

Closed InterestingApple closed 1 year ago

InterestingApple commented 1 year ago

Code(I put it in a separate file demo.py then run it): self.model = tf.keras.models.load_model(self.bundle_dir + '/models/SiameseLSTM.h5', custom_objects={'ManDist': ManDist}) self.model.summary() x = Sequential() x.add(self.model.get_layer('lstm')) self.intermediate_model = x

Error Information: Traceback (most recent call last): File "D:/MyProject/PythonProject/QTestingProject/demo.py", line 37, in model = keras.models.load_model('D:/MyProject/PythonProject/QTestingProject/models/SiameseLSTM.h5', custom_objects={'ManDist': ManDist}) File "E:\AppPath\Python\Python27\lib\site-packages\tensorflow\python\keras_impl\keras\models.py", line 246, in load_model model = model_from_config(model_config, custom_objects=custom_objects) File "E:\AppPath\Python\Python27\lib\site-packages\tensorflow\python\keras_impl\keras\models.py", line 324, in model_from_config return layer_module.deserialize(config, custom_objects=custom_objects) File "E:\AppPath\Python\Python27\lib\site-packages\tensorflow\python\keras_impl\keras\layers\serialization.py", line 63, in deserialize printable_module_name='layer') File "E:\AppPath\Python\Python27\lib\site-packages\tensorflow\python\keras_impl\keras\utils\generic_utils.py", line 164, in deserialize_keras_object list(custom_objects.items()))) File "E:\AppPath\Python\Python27\lib\site-packages\tensorflow\python\keras_impl\keras\engine\topology.py", line 975, in from_config process_layer(layer_data) File "E:\AppPath\Python\Python27\lib\site-packages\tensorflow\python\keras_impl\keras\engine\topology.py", line 961, in process_layer layer = deserialize_layer(layer_data, custom_objects=custom_objects) File "E:\AppPath\Python\Python27\lib\site-packages\tensorflow\python\keras_impl\keras\layers\serialization.py", line 63, in deserialize printable_module_name='layer') File "E:\AppPath\Python\Python27\lib\site-packages\tensorflow\python\keras_impl\keras\utils\generic_utils.py", line 164, in deserialize_keras_object list(custom_objects.items()))) File "E:\AppPath\Python\Python27\lib\site-packages\tensorflow\python\keras_impl\keras\models.py", line 1333, in from_config layer = layer_module.deserialize(conf, custom_objects=custom_objects) File "E:\AppPath\Python\Python27\lib\site-packages\tensorflow\python\keras_impl\keras\layers\serialization.py", line 63, in deserialize printable_module_name='layer') File "E:\AppPath\Python\Python27\lib\site-packages\tensorflow\python\keras_impl\keras\utils\generic_utils.py", line 184, in deserialize_keras_object function_name) ValueError: Unknown layer:layers