A
A
Andrei1penguin12021-02-07 17:13:45
Python
Andrei1penguin1, 2021-02-07 17:13:45

Why does keras complain about the loss function?

there is a keras model that is saved via model.save() This model uses a self-written loss function:

def contrastive_loss(y_true, y_pred):
        return K.mean(y_true * K.square(y_pred) + (1 - y_true) * K.square(K.maximum(1 - y_pred, 0)))
model.compile(loss=contrastive_loss, optimizer=rms)

There are no problems when training the model, but when loading the model:
from tensorflow.keras.models import load_model
model = load_model("model.h5")

An error is flying: ValueError: Unknown loss function:contrastive_loss
Please tell me how to fix this

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question