完整报错如下:
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
方式: