错误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`.

错误NotImplementedError: Saving the model to HDF5 format requires the model to be a Functional model
错误原因:
自定义模型只保存参数(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

上一篇:Bella团队正在进行Flex Saving v2上线最后的准备工作


下一篇:【Codeforces 1443 B】Saving the City,贪心,分类讨论