qubvel / segmentation_models

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

Negative dice loss #177

Open kimihailv opened 5 years ago

kimihailv commented 5 years ago

Dataset loading and preprocessing:

img = cv2.imread(path.join(self.img_dir, self.files[i] + self.img_ext))
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
mask = cv2.imread(path.join(self.mask_dir, self.files[i] + self.mask_ext), 0)
mask = to_categorical(mask, num_classes=self.num_classes)

if self.augmentation is not None:
   augumented = self.augmentation(image=img, mask=mask)
   img, mask = augumented["image"], augumented["mask"]

if self.preprocessing is not None:
    sample = self.preprocessing(image=img, mask=mask)
    img, mask = sample["image"], sample["mask"]

return img, mask

Preprocessing function:

def get_preprocessing(preprocessing_fn):
    transform = [
        A.Lambda(image=preprocessing_fn),
    ]
 return A.Compose(transform)

Where preprocessing_fn is sm.get_preprocessing(backbone). Where is my mistake? Thanks for the help.

qubvel commented 5 years ago

check that your mask is in range 0..1

kimihailv commented 5 years ago

I have already checked, values are in [0, 1]

kimihailv commented 5 years ago

check that your mask is in range 0..1

to_categorical function in my code is tf.keras.utils.to_categorical, which convert a matrix with shape (h, w) to the categorical matrix with shape (h, w, num_classes)