Count all different pixel values given a set of images
In order to sanity check masks for the semantic segmentation task, I would like to know how I can find all different pixel values, given a set of images.
I tried:
l = []
for img in glob.glob('/content/Maschere/*png'):
  im = Image.open(img)
  data = torch.from_numpy(np.asarray(im))
  v = torch.unique(data)
  l.append(v)

print(set(l))

The aforementioned code displays the unique pixel values per image, instead, I want get the unique for the whole set of images
NOTE:
I get this output format:
{tensor([  2, 255], dtype=torch.uint8), tensor([  2, 255], dtype=torch.uint8), tensor([  2, 255], dtype=torch.uint8), tensor([  2, 255], dtype=torch.uint8), tensor([  3, 255], dtype=torch.uint8), tensor([  9, 255], dtype=torch.uint8)

I would get this kind of result instead :
tensor([  2, 3, 9 255], dtype=torch.uint8)


I didnt' test it, but something along the lines of:
l = set()
for img in glob.glob('/content/Maschere/*png'):
  im = Image.open(img)
  data = torch.from_numpy(np.asarray(im))
  v = set(torch.unique(data))
  l.update(v)

print(l)

It maintains a single set which you update with any new values you encounter.
