其他分享
首页 > 其他分享> > 错误NotImplementedError: Saving the model to HDF5 format requires the model to be a Functional model

错误NotImplementedError: Saving the model to HDF5 format requires the model to be a Functional model

作者:互联网

tf2.0训练网络,使用官方预训练模型和权重时,在保存模型和参数时,出现这个错误:
代码:

model.save('model36_5.h5')
model.save_weights('weight_tf_model36_5.h5')

报错信息


 NotImplementedError: Saving the model to HDF5 format requires the    
   model to be a Functional model or a Sequential model. It does not   
   work  for subclassed models, because such models are defined via 
   the body   of a Python method, which isn't safely serializable. Consider 
   saving to    the Tensorflow Saved Model format (by setting   
   save_format="tf") or    using `save_weights`.

在这里插入图片描述
错误原因:
自定义模型只保存参数(model_weight模型),官方模型保存参数和权重(.h5模型)
修改为:

model.save_weights('weight_tf_model36_5.h5')

完成!
参考文章:解决tf2 NotImplementedError: Saving the model to HDF5 format requires the model to be a Functional mod

标签:Saving,format,模型,HDF5,h5,model,save
来源: https://blog.csdn.net/weixin_44152421/article/details/113618206