Search code examples
pythontensorflowkerasevaluate

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

load model function :

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)

after saving and loading the model there is no error

loaded_1000_image_model.evaluate(val_data)

when I am trying to evaluate the loaded model then it's saying

---------------------------------------------------------------------------
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'

Solution

  • Your load_model function needs to return model