qubvel / segmentation_models

Segmentation models with pretrained backbones. Keras and TensorFlow Keras.
MIT License
4.77k stars 1.03k forks source link

Jaccard Loss - Unknown Loss Function Error #518

Closed johnfoxy closed 2 years ago

johnfoxy commented 2 years ago

I am trying to train my Unet Model, but I keep ending up with this error (below). Other losses work but not Jaccard, any help please?

"ValueError: Unknown loss function: bce_jaccard_loss. Please ensure this object is passed to the custom_objects argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details."

My code snippet failing...

`model = sm.Unet(BACKBONE, encoder_weights='imagenet') model.compile(optimizer='Adam', loss='bce_jaccard_loss', metrics=['iou_score'])

print(model.summary())

history=model.fit(x_train[0:500], y_train[0:500], batch_size=2, epochs=1000, verbose=1, validation_data=(x_val, y_val))`