Visualising masks in Cityscapes testset

Hi, I am working on Segmentation task in Cityscapes. To do that I downloaded the dataset and when I visualise trainset and valset I can see the images and masks correctly. But for images in test set it returns only a black mask. For masks I use _leftImg8bit.png' in dataset. I mean I am using 3-channel masks.

Here is a short script of how I visualise masks:


img_root = os.path.join(root_path,'test')

mask_root = os.path.join(root_path,'test_labels')

img_city_list = os.listdir(img_root)

mask_city_list = os.listdir(mask_root)

assert img_city_list==mask_city_list

cities = img_city_list

cities

berlin_img_list= sorted(os.listdir(os.path.join(img_root,'berlin'))) 

berlin_mask_list= sorted(os.listdir(os.path.join(mask_root,'berlin')))

img_sample = berlin_img_list[10]

img_sample:```



```berlin_000010_000019_leftImg8bit.png```

Here I visualise images:

```image = Image.open(os.path.join(img_root,'berlin',img_sample))
plt.imshow(image)```

now we have the following files in label folder:

```mask_lists = ['berlin_000010_000019_gtFine_color.png',
 'berlin_000010_000019_gtFine_instanceIds.png',
 'berlin_000010_000019_gtFine_labelIds.png',
 'berlin_000010_000019_gtFine_polygons.json']```

And when I visualise it using the following code:

```mask1 = Image.open(os.path.join(mask_root,'berlin',mask_lists[0])).convert('RGB')

mask2 = Image.open(os.path.join(mask_root,'berlin',mask_lists[2])).convert('L')```

```plt.imshow(mask1)```

```plt.imshow(mask2)```

I would just get a black mask. I would appreciate any help.

Are you able to open these images in any picture viewer and are you seeing a valid output?
If so, it would point towards a failure in opening or deciding the images.
Are you visualizing the training and validation masks using the same or similar code?

Regarding the first question, I did not try to open the images in any viewer. Except opening them using PIL library and visualising them using plt.imshow.

Regarding the second question, yes, I am visualising images and masks in training and validation sets exactly with the similar code.
Can you help me? I really need to visualise these masks in my work. I even tried the implementation of pytorch:

dataset = Cityscapes('./data/cityscapes', split='test', mode='fine',
                     target_type= 'color')

img, col = dataset[0]

But I couldn’t visualise the masks.

Could you try to visualize these images using an image viewer and verify, that they are indeed not empty images?

I just tried that.

training and validation masks are not empty but the test masks are empty.

In that case it seems that PIL is correctly loading the test images and you would have to check, why these images are empty. Maybe they are corrupt or never contained any valid data.

How can I check that then?

I can visualise the test images but not test masks. I mean the masks in test set are empty.

Is that the reason that when I evaluate my model on test set I got large value for loss?

I think you downloaded dummy test label.

In the cityscapes site, they provide only train and validation dataset labels.

Plz check your test dataset labels are correct.

1 Like