UnidentifiedImageError during Data Augmenatition

I am facing this UnidentifiedImageError when I try to display the augmented images. Kindly help in resolving this error:
the code is as follows:

class ImageDataset2(torch.utils.data.Dataset):
def init(self, csv_file, transform = transform):
# Input will be a csv file (self.reference) and optional transform
self.reference = pd.read_csv(csv_file, header=None)
# Will allow transforms to be defined in main, default is off (False)
#self.transform = transform
self.transform = transform
def len(self):
# Finds size of data set for initializing training and validation
return len(self.reference)
def getitem(self, idx):
# Load image from csv using imread function from imageio (renamed to io here)
#image = torch.tensor(io.imread(self.reference[0][idx])).permute(2, 1, 0)
#label = torch.tensor(self.reference[1][idx])-1
label = self.reference[1][idx]
label = torch.tensor(label)-1
# Output image and label pair (Convert to torch friendly inputs)
image = plt.imread(self.reference[0][idx])

    image = Image.fromarray(image).convert('RGB')        
    image = np.asarray(image).astype(np.uint8)

    image = self.transforms(image)
    #image=torch.tensor(image).permute(2, 1, 0)
    #out = {
        #'image': image.type(torch.FloatTensor),
        #'label': label.type(torch.long)
    #}
    return torch.tensor(image, dtype=torch.float)

batchsize = 2
trainset = ImageDataset2(csv_file=‘trainingSet.csv’, transform = True)
trainLoader = torch.utils.data.DataLoader(dataset=trainset, shuffle=False, batch_size=batchsize)
valset = ImageDataset2(csv_file=‘validationSet.csv’, transform = True)
validLoader = torch.utils.data.DataLoader(dataset=valset, shuffle=False, batch_size=1)
testset = ImageDataset2(csv_file=‘testingSet.csv’, transform=False)
testLoader = torch.utils.data.DataLoader(dataset=testset, shuffle=False, batch_size=1)

#display images
f = plt.figure(figsize=(15,15))
n = range(1,11)
i=0
for batch in trainLoader:
images = batch[‘image’]
image = images[0]
npimage = image.numpy()
trans = transforms.ToPILImage()
f.add_subplot(2,5,n[i])
#plt.imshow(trans(image))
plt.imshow(np.transpose(npimg,(1,2,0)))
plt.show()
f.subplots_adjust(bottom=0.55)
i=i+1
if(i>len(n)-1):
break

UnidentifiedImageError Traceback (most recent call last) in 2 n = range**(** 1 , 11 ) 3 i**=** 0 ----> 4 for batch in trainLoader**:** 5 images = batch**[** ‘image’ ] 6 image = images**[** 0 ] ~\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\utils\data\dataloader.py in next(self) 515 if self**.** _sampler_iter is None : 516 self**.** _reset**(** ) → 517 data = self**.** _next_data**(** ) 518 self**.** _num_yielded += 1 519 if self**.** _dataset_kind == _DatasetKind**.** Iterable and \ ~\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\utils\data\dataloader.py in _next_data**(self)** 555 def _next_data**(** self**)** : 556 index = self**.** _next_index**(** ) # may raise StopIteration → 557 data = self**.** _dataset_fetcher**.** fetch**(** index**)** # may raise StopIteration 558 if self**.** _pin_memory**:** 559 data = _utils**.** pin_memory**.** pin_memory**(** data**)** ~\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\utils\data_utils\fetch.py in fetch**(self, possibly_batched_index)** 42 def fetch**(** self**,** possibly_batched_index**)** : 43 if self**.** auto_collation**:** —> 44 data = [ self**.** dataset**[** idx**]** for idx in possibly_batched_index**]** 45 else : 46 data = self**.** dataset**[** possibly_batched_index**]** ~\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\utils\data_utils\fetch.py in (.0) 42 def fetch**(** self**,** possibly_batched_index**)** : 43 if self**.** auto_collation**:** —> 44 data = [ self**.** dataset**[** idx**]** for idx in possibly_batched_index**]** 45 else : 46 data = self**.** dataset**[** possibly_batched_index**]** in getitem(self, idx) 22 label = torch**.** tensor**(** label**)** - 1 23 # Output image and label pair (Convert to torch friendly inputs) —> 24 image = plt**.** imread**(** self**.** reference**[** 0 ] [ idx**]** ) 25 26 image = Image**.** fromarray**(** image**)** . convert**(** ‘RGB’ ) ~\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\pyplot.py in imread**(fname, format)** 2059 @ docstring**.** copy**(** matplotlib**.** image**.** imread**)** 2060 def imread**(** fname**,** format**=** None ) : → 2061 return matplotlib**.** image**.** imread**(** fname**,** format**)** 2062 2063 ~\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\image.py in imread**(fname, format)** 1462 raise ValueError('Only know how to handle PNG; with Pillow ’ 1463 ‘installed, Matplotlib can handle more images’) → 1464 with Image**.** open**(** fname**)** as image**:** 1465 return pil_to_array**(** image**)** 1466 from matplotlib import _png ~\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\Image.py in open**(fp, mode)** 2929 warnings**.** warn**(** message**)** 2930 raise UnidentifiedImageError( → 2931 "cannot identify image file %r" % ( filename if filename else fp**)** 2932 ) 2933 UnidentifiedImageError : cannot identify image file ‘C:\Users\DELL\Documents\RGB Image Slices\Day 3\2303\WoundEdgeStack-002\Slice90.tiff’

The error is raised by PIL/Pillow, which cannot create an image given the provided array. You can check supported formats here and make sure to transform the image into a listed format. Additionally, you could check, if e.g. matplotlib would allow to display the currently provided array.

I am getting the same when I change the format. I think that there is something wrong in the class ‘imagedataset2’ because the error is in the line

----> 4 for batch in trainLoader:

but I can’t spot that out. I am actually a beginner in pytorch. Please let me know your thoughts here.