Dear Valentyn,
thanks for your reply and suggestions. I am creating the dataset by passing a numpy array containing all the images with type uint8 already. So the type of the Dataset is inferred and is '|u8'. I have tried also to pass it as float64 and convert it afterward when I index the specific image from the Dataset. To have more clear the context, I share some lines of code:
path = self.images_paths[idx]
image2 = Image.open(path)
img_arr2 = np.asarray(image2)
img_arr = self.dataset[idx, ...]
np.array_equal(img_arr, img_arr2) # returns False many times
img_arr = self.dataset[idx, ...]
np.array_equal(img_arr, img_arr2) # returns True (rarely False)
image = Image.fromarray(img_arr)
As you can see I open the image directly with PIL first and convert it to an array (uint8). Then, I read the same image from the Dataset and, before converting it to an Image, I compare the two. The problem is not the type but small divergences between the values. Roughly, there is 50-150px average difference between pixel value per Image ( in case they are not equal ).
I actually found the problem just today. It is related to multiprocessing when loading of the data by setting pytorch.Dataloader num_workers>0. When this feature is disabled, with num_workers=0, there is no problem. Do you have any idea how to fix this?