meetps / pytorch-semseg

Semantic Segmentation Architectures Implemented in PyTorch
https://meetshah.dev/semantic-segmentation/deep-learning/pytorch/visdom/2017/06/01/semantic-segmentation-over-the-years.html
MIT License
3.38k stars 799 forks source link

ValueError: Segmentation map contained invalid class values #247

Open GutlapalliNikhil opened 3 years ago

GutlapalliNikhil commented 3 years ago

Hi guys,

I was trying to run cityscapes dataset. While doing train.py, I was getting this error like,

RUNDIR: runs/frrnB_cityscapes/26539 Found 20 train images Found 10 val images INFO:ptsemseg:Using cross_entropy with {} params INFO:ptsemseg:Using loss functools.partial(<function cross_entropy2d at 0x7fdc8ce9c158>) INFO:ptsemseg:No checkpoint found at 'frrnB_cityscapes_best_model.pkl' Traceback (most recent call last): File "train.py", line 229, in train(cfg, writer, logger) File "train.py", line 118, in train for (images, labels) in trainloader: File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 336, in next return self._process_next_batch(batch) File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 357, in _process_next_batch raise batch.exc_type(batch.exc_msg) ValueError: Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 106, in _worker_loop samples = collate_fn([dataset[i] for i in batch_indices]) File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 106, in samples = collate_fn([dataset[i] for i in batch_indices]) File "/content/pytorch-semseg/ptsemseg/loader/cityscapes_loader.py", line 166, in getitem img, lbl = self.transform(img, lbl) File "/content/pytorch-semseg/ptsemseg/loader/cityscapes_loader.py", line 197, in transform raise ValueError("Segmentation map contained invalid class values") ValueError: Segmentation map contained invalid class values

Can someone help me in this.

Thank you.

kubitz commented 3 years ago

Not exactly sure what is causing the error, but it will disappear if you turn data augmentation off

farnaznouraei commented 3 years ago

Not sure if this is a similar issue, but I was working with the Pascal dataloader and realized the .resize() functions used in the transforms are generating new (undefined) values in the segmentation map. If you change all data read/write and resize function to cv2 functions, with resizing via NEAREST NEIGHBOR (interpolation =cv2.INTER_NEAREST), it could help preserve the class integers/colors.