Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative dice loss #177

Open
kimihailv opened this issue Aug 17, 2019 · 3 comments
Open

Negative dice loss #177

kimihailv opened this issue Aug 17, 2019 · 3 comments

Comments

@kimihailv
Copy link

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
Copy link
Owner

qubvel commented Aug 17, 2019

check that your mask is in range 0..1

@kimihailv
Copy link
Author

kimihailv commented Aug 17, 2019

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

@kimihailv
Copy link
Author

kimihailv commented Aug 17, 2019

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants