ValueError: Unknown loss function:loss - I received this error by trying to load the model. It happened as I created my own loss and metric function. After searching many forums, I found the solution in this thread.

Imports

import tensorflow as tf
import tensorflow.keras.backend as K

Option 1

Continuation of training

# you have to define functions
def loss(y_true, y_pred):
    mse = tf.keras.losses.mean_squared_error(y_true=y_true, y_pred=y_pred)
    return mse * 4

def metric(y_true, y_pred):
    max_true = K.max(K.max(y_true, axis=0), axis=0)
    max_pred = K.max(K.max(y_pred, axis=0), axis=0)
    
    return max_pred/max_true   
# and then enter them as a dictionary
model = tf.keras.models.load_model('model.h5', custom_objects={
    'loss':loss,
    'metric': metric
})

Option 2

Only prediction

# all you need to do is set the compilation flag to False
model = tf.keras.models.load_model('model.h5', compile=False)