Pytorch-UNet icon indicating copy to clipboard operation
Pytorch-UNet copied to clipboard

Either no mask or multiple masks found for the ID

Open SkevyHoo opened this issue 3 years ago • 6 comments

I used my own dataset to train U-Net,and it took a error: Either no mask or multiple masks found for the ID So how to solve it?

SkevyHoo avatar Nov 05 '21 08:11 SkevyHoo

I'm using the Carvana dataset (which is what this code is supposed to download but I kept getting unauthorized error) and I'm getting the same thing. Any idea on how to fix that?

I'm going to take a quick look at the files and see if anything stands out.

ihamdi avatar Nov 29 '21 08:11 ihamdi

I used my own dataset to train U-Net,and it took a error: Either no mask or multiple masks found for the ID So how to solve it?

Somehow, running it on my home PC (i9 RTX 3090 Ubuntu) doesn't give me that error anymore. I never had an issue before running code on the laptop (i7 RTX 2060 Ubuntu). Absolutely have no idea why that would happen on one machine but not another.

I'll let you know if it happens again.

ihamdi avatar Nov 29 '21 15:11 ihamdi

I used my own dataset to train U-Net,and it took a error: Either no mask or multiple masks found for the ID So how to solve it?

Go to utils folder then data_loading.py and add: if len(mask_file)!=1: print(name) in getitem just after img_file = list(self.images_dir.glob(name + '.*'))

This will show you which file is the problem. In my case, I had an empty folder inside the /data/imgs and /data/masks folder that was causing the issue. I checked the other machine and I didn't have that so it makes sense that its the issue.

ihamdi avatar Nov 30 '21 05:11 ihamdi

@milesial changing the listdir(images_dir) to glob would be an easy fix to avoid this problem. Or just mention that we need to make sure imgs and masks folders in the data/ should contain nothing other than the actual masks and images.

ihamdi avatar Nov 30 '21 05:11 ihamdi

The directory of your mask in data_loading file is wrong. The data_loading file includes the code to read the image and mask. But the author set a mask_suffix in the code. Please check your mask directory.

wujiayi avatar Jan 05 '22 09:01 wujiayi

Traceback (most recent call last): File "train.py", line 188, in train_net(net=net, File "train.py", line 79, in train_net for batch in train_loader: File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 578, in next data = self._next_data() File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1273, in _next_data return self._process_data(data) File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1299, in _process_data data.reraise() File "/opt/conda/lib/python3.8/site-packages/torch/_utils.py", line 461, in reraise raise exception AssertionError: Caught AssertionError in DataLoader worker process 0. Original Traceback (most recent call last): File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 300, in _worker_loop data = fetcher.fetch(index) File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/dataset.py", line 290, in getitem return self.dataset[self.indices[idx]] File "/workspace/unet/utils/data_loading.py", line 62, in getitem assert len(mask_file) == 1, f'Either no mask or multiple masks found for the ID {name}: {mask_file}' AssertionError: Either no mask or multiple masks found for the ID 0de66245f268_09: []

All folders are created correctly.

data/imgs/ data/masks/

When i check mask. It is found.

root@8a72d2424c09:/workspace/unet# ls data/masks/ | grep 0de66245f268_09 0de66245f268_09.png

Looks like i fixed it by setting utils/data_loading.py last line super().init(images_dir, masks_dir, scale, mask_suffix='')

It was expecting '_mask' suffix, have no idea why.

silakanveli avatar Nov 09 '22 20:11 silakanveli