Sunday, 26 September 2021

How to load keras "history" object with custom loss?

So I defined my keras model and have used a custom_loss function to train the model:

model.compile(optimizer='adam', loss=custom_loss, metrics=[custom_loss])

Then I am training the model:

history = model.fit(X_train, y_train, batch_size=1024, epochs=125, validation_split=0.2, shuffle=True)

Then I save this history object using the following code:

with open('history.pkl', 'wb') as file:  
   pickle.dump(history, file)

Now, when I am trying to read the history object as follows:

with open('history.pkl', 'rb') as file:
    history = pickle.load(file)

I get the following error:

ValueError: Unknown loss function:custom_loss

How can I read the history object? I don't get this error when I am not using custom_loss function. I am using keras 2.2.4 and tensorflow 1.15.5

Edit: Complete error traceback as requested: enter image description here



from How to load keras "history" object with custom loss?

No comments:

Post a Comment