提问人:SemenSergeevich 提问时间:11/10/2023 更新时间:11/10/2023 访问量:25
Keras load_model错误“str”对象不可调用
keras load_model error 'str' object is not callable
问:
我在 Google Colab 中编码
我已经通过Autokeras创建模型并导出并保存
model = clf.export_model()
model.save(f'{data_path}')
model.summary()
如果我在同一会话中加载模型 - 没关系
但是当我下次在新会话中不加载模型时,我出现错误
from tensorflow.keras.models import load_model
model_x = load_model(f'{data_path}')
4
----> 5 model_x = load_model('model_x.keras')
6 frames
/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_api.py in load_model(filepath, custom_objects, compile, safe_mode, **kwargs)
252 f"with the native Keras format: {list(kwargs.keys())}"
253 )
--> 254 return saving_lib.load_model(
255 filepath,
256 custom_objects=custom_objects,
/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_lib.py in load_model(filepath, custom_objects, compile, safe_mode)
279
280 except Exception as e:
--> 281 raise e
282 else:
283 return model
/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_lib.py in load_model(filepath, custom_objects, compile, safe_mode)
244 # Construct the model from the configuration file in the archive.
245 with ObjectSharingScope():
--> 246 model = deserialize_keras_object(
247 config_dict, custom_objects, safe_mode=safe_mode
248 )
/usr/local/lib/python3.10/dist-packages/keras/src/saving/serialization_lib.py in deserialize_keras_object(config, custom_objects, safe_mode, **kwargs)
726 safe_mode_scope = SafeModeScope(safe_mode)
727 with custom_obj_scope, safe_mode_scope:
--> 728 instance = cls.from_config(inner_config)
729 build_config = config.get("build_config", None)
730 if build_config:
/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py in from_config(cls, config, custom_objects)
3304 # Revive Functional model
3305 # (but not Functional subclasses with a custom __init__)
-> 3306 inputs, outputs, layers = functional.reconstruct_from_config(
3307 config, custom_objects
3308 )
/usr/local/lib/python3.10/dist-packages/keras/src/engine/functional.py in reconstruct_from_config(config, custom_objects, created_layers)
1503 while layer_nodes:
1504 node_data = layer_nodes[0]
-> 1505 if process_node(layer, node_data):
1506 layer_nodes.pop(0)
1507 else:
/usr/local/lib/python3.10/dist-packages/keras/src/engine/functional.py in process_node(layer, node_data)
1443 input_tensors
1444 )
-> 1445 output_tensors = layer(input_tensors, **kwargs)
1446
1447 # Update node index map.
TypeError: 'str' object is not callable
我在 pyCharm 中尝试了相同的方法并得到了相同的结果
答: 暂无答案
下一个:向后兼容性 301
评论