Closed twVolc closed 3 years ago
you need to mention the custom objects while loading the model. in your case mention "binary_crossentropy_plus_jaccard_loss"
@fidhaph brilliant thank you, that worked a treat.
Just to clarify in case anyone else is having this issue, you pass the loss function in a dictionary to the custom_objects
argument of load_model
. The dictionary key is the string name of the function:
tf.keras.models.load_model(model_path, custom_objects={'binary_crossentropy_plus_jaccard_loss': sm.losses.bce_jaccard_loss})
Using tensorflow version
2.2.0
I'm getting the following error when using
model = tf.keras.models.load_model(model_path)
on a model previously saved withmodel.save()
. I've tried saving the model in both Tensorflow Native format and hdf5 and I get the same error:It seems to be an issue with the segmentation-models built-in loss function binary_crossentropy_plus_jaccard_loss which I used for training my model. Have I been saving my models in the wrong way for segmentation-models or is this a bug that needs fixing? Presumably I could just save the model weights and rebuild the model that way, but it seems easier for deployment to be able to load the model with the single line of code
tf.keras.models.load_model()
.