huyquoctrinh / MetaPolyp-CBMS2023

Meta-Polyp: a baseline for efficient Polyp segmentation (CBMS 2023)
MIT License
68 stars 9 forks source link

ValueError: Unknown loss function: 'dice' #7

Closed qqc222111 closed 6 months ago

qqc222111 commented 6 months ago

Hello, I set my virtual environment according to your requirement, python3.9, tensorflow2.11, but I met the error ValueError: Unknown loss function: 'dice'. Please ensure you are using a keras.utils.custom_object_scope and that this object is included in the scope.

huyquoctrinh commented 6 months ago

Hi dear,

For the custom_object "dice", you can ignore it by compile = False during load model. During the load model, follow this:

model = tf.keras.models.load_model("your model name", compile = False)

You can solve that problem!

Thank you so much for raising this issue

qqc222111 commented 6 months ago

Thanks for your answering. But I met the error when I use train.py, I can't find the code you refered in train.py and it occurs in the code below. Whether it may be caused by the version of tensorflow? his = model.fit(train_dataset, epochs=epochs, verbose=1, callbacks=callbacks, steps_per_epoch=steps_per_epoch, validation_data=valid_dataset, ) image image

huyquoctrinh commented 6 months ago

Hi, thanks for your response. To solve this problem, we can add directly the loss function to the compile attribute of the model via this code:

model.compile(optimizer = opts,
            loss= dice_loss,
            metrics=[dice_coeff,bce_dice_loss, IoU, zero_IoU])

Let me know if you can fix it :>

qqc222111 commented 6 months ago

Thank you very much for solving my problem!

huyquoctrinh commented 6 months ago

It's my pleasure. I will close this issue, thanks for raising it :>