成功解决ValueError:Youaretryingtoloadaweightfilecontaining4layersintoamodelwith0layers.
目录解决问题解决思路解决方法
解决问题
ValueError:Youaretryingtoloadaweightfilecontaining4layersintoamodelwith0layers.
解决思路
值错误:您试图将包含4层的权重文件加载到具有0层的模型中。 load_model(path_model),这种语句不能针对使用Merge类建立的嵌套型神经网络。因为这个神经网络是Sequential_model,即嵌套的,所以会发生这种报错!
解决方法
将
path_model='Sequential_model.keras'model.save(path_model)model=load_model(path_model)
改为
model.save_weights('Sequential_model_weights.h5')model.load_weights('Sequential_model_weights.h5',by_name=True)json_string=model.to_json()model=model_from_json(json_string)