Tensorflow2.0 保存模型时出现 NotImplementedError 的解决方法

如果保存用类定义的模型,那么很有可能会出现以下错误:

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

此时如果我们将此模型改为用函数定义,便不会再出现这个错误。

你可能感兴趣的:(报错,Tensorflow,2.0,tensorflow,python)