【问题标题】:AttributeError: 'NoneType' object has no attribute 'evaluate' with evaluating of loaded model in kerasAttributeError:“NoneType”对象没有属性“评估”,评估 keras 中加载的模型
【发布时间】:2021-04-09 11:00:30
【问题描述】:
# 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'

【问题讨论】:

  • 我投票结束这个问题,因为它是由拼写错误引起的,因此不太可能对本网站做出积极贡献。

标签: python tensorflow keras evaluate


【解决方案1】:

你的load_model函数需要return model

【讨论】:

    猜你喜欢
    • 2017-03-24
    • 2012-02-25
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-28
    相关资源
    最近更新 更多