AttributeError: 'NoneType' object has no attribute 'evaluate' with evaluating of loaded model in keras

AttributeError: 'NoneType' object has no attribute 'evaluate' with evaluating of loaded model in keras

# my save model function 
# saving and reloadinng the trained model 
import os 
def save_model(model,suffix = None):
    model_dir = os.path.join('./',datetime.datetime.now().strftime("%Y%m%d%H%M%s"))
    model_path = model_dir + '-' + suffix + '.h5' # save format of the model 
    print('saving model to : ' + model_path + '...')
    model.save(model_path)
    return model_path

加载模型函数:

def load_model(model_path):
    print('loading saved model from ' + model_path)
    model = tf.keras.models.load_model(model_path,custom_objects = {'KerasLayer':hub.KerasLayer},compile=False)

loaded_1000_image_model.evaluate(val_data)

当我尝试评估加载的模型时,它说

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-144-1940330b6409> in <module>
----> 1 loaded_1000_image_model.evaluate(val_data)

AttributeError: 'NoneType' object has no attribute 'evaluate'

您的 load_model 函数需要 return model