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