huggingface / datasets

🤗 The largest hub of ready-to-use datasets for ML models with fast, easy-to-use and efficient data manipulation tools
https://huggingface.co/docs/datasets
Apache License 2.0
18.6k stars 2.55k forks source link

Example on Semantic segmentation contains bug #6865

Open ducha-aiki opened 4 weeks ago

ducha-aiki commented 4 weeks ago

Describe the bug

https://huggingface.co/docs/datasets/en/semantic_segmentation shows wrong example with torchvision transforms. Specifically, as one can see in screenshot below, the object boundaries have weird colors.

image

Original example with albumentations is correct

image

That is because torch vision.transforms.Resize interpolates with bilinear everything which is wrong when used for segmentation labels - you just cannot mix them. Overall, torchvision.transforms is designed for classification only and cannot be used to images and masks together, unless you write two separate branches of augmentations.

The correct way would be to use v2 version of transforms and convert the segmentation labels to https://pytorch.org/vision/main/generated/torchvision.tv_tensors.Mask.html#torchvision.tv_tensors.Mask object

Steps to reproduce the bug

Go to the website.

image

https://huggingface.co/docs/datasets/en/semantic_segmentation

Expected behavior

Results, similar to albumentation. Or remove the torch vision part altogether. Or use kornia instead.

Environment info

Irrelevant