如果保存用类定义的模型,那么很有可能会出现以下错误:
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`.
此时如果我们将此模型改为用函数定义,便不会再出现这个错误。