Consider saving to the Tensorflow SavedModel format (by setting save_format=“tf“) or using `save_wei

完整报错如下:

Traceback (most recent call last):
  File "/ad_ctr/new_thought/tmp4.py", line 459, in <module>
    model.save(save_path.format('FCINN', 'FCINN-11-13.h5'))
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/network.py", line 1052, in save
    signatures, options)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/saving/save.py", line 128, in save_model
    'Saving the model to HDF5 format requires the model to be a '
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 SavedModel format (by setting save_format="tf") or using `save_weights`.

在这里插入图片描述
原因:自定义Keras的类是不能保存成.h5格式的,可以保存权重或者save_format="tf"

from tensorflow.keras.models import save_model, load_model

# model.save(save_path.format('FCINN', 'test_FCINN-11-13.h5'))
model.save(save_path.format('FCINN', 'test_FCINN-11-13_serving'), save_format="tf")
# model = load_model(save_path.format('FCINN', 'test_FCINN-11-13.h5'))
model = load_model(save_path.format('FCINN', 'test_FCINN-11-13_serving'))

参考:

https://my.oschina.net/u/4396881/blog/3375667

https://www.cnblogs.com/Manuel/p/13357212.html

tf.saved_model.save方式:

https://cloud.tencent.com/developer/article/1785139
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42363032/article/details/122874666