Hi,
I think there is problem with your conditioning that leads to NoneType in IMG1 and IMG2. Try to write python a function outside of and test that your approach is currect or not. Actually, I do not know about your data structure but I cannot understand the idea behind imgx and IMGx, mostly here.



 Mrig:

IMG1=img1.iloc[0:-1]
IMG2=img2.iloc[0:-1]



I tried to simulate your case using mnist and found no error except that IMG1 and IMG2 cannot be pandas series objects and you need to convert them to np.array.
In this simulation, each input in dataframe has 769 columns where first ones are target label and other 768 are 28x28 pixels of image.
Here is the code I used for MNIST:

class Siamese(data.Dataset):
    def __init__(self,train_df):
        self.train_df=train_df
      
    def __len__(self):
        return(len(self.train_df))
    
    def __getitem__(self,idx):
        if torch.is_tensor(idx):
            idx = idx.tolist()
        img1=self.train_df.iloc[random.randint(0,self.__len__()),:]
        img2=self.train_df.iloc[random.randint(0,self.__len__()),:]
        while(img1[0]!=img2[0]):
            img1=self.train_df.iloc[random.randint(0,self.__len__()),:]
            img2=self.train_df.iloc[random.randint(0,self.__len__()),:]
            # img1 = img1.iloc[0:-1]
            # img2 = img2.iloc[0:-1]
            return np.array(img1[0]), np.array(img2[0]), torch.from_numpy(np.array([img1[0]==img2[0]],dtype=np.float32))

train_data=pd.read_csv('sample_data/mnist_train_small.csv')
dataset_train=Siamese(train_data)
vis_dataloader = data.DataLoader(dataset_train, shuffle=True, batch_size=1)
dataiter = iter(vis_dataloader)
next(dataiter)

Bests