Hi,
I am trying to create a dataset for a siamese CNN and essentially the dataset is a modified version of the MNIST dataset wherein in a list i have 3 images(the first two images are of the same digit and the last image is of another digit),i create 5000 samples of the same kind and save all these samples in a list and so the size of my list is essentially 5000x3.
Now when i pass this to the DataLoader for getting me batches of size 2 the DataLoader should essentially return to me a list which is of the size 2x3 but the DataLoader returns to me a list of images of size 3x2 which is totally wrong.
I have tried to print values inside the getitem fuunction to see how the sampling is happening and it is happening correctly but after this sampling the DataLoader is somehow changing the dimensions of my dataset.
The ‘traindata’ and ‘testdata’ is essentially the downloaded MNIST dataset from pytorch
dont know why this is happening or if i am misunderstanding something.
some help would be much appreciated.
Thanks!
The code is below–
class siameseMNIST(Dataset):
    def __init__(self,images,labels):
        self.x=images
        #print(self.x[0])
        self.y=labels
    def __getitem__(self,index):
        print(index,self.x[index])
        return (self.x[index],self.y[index])
    def __len__(self):
        return len(self.x)

def generateTrainSet(trainData):
    newtrainset=list()
    newtrainlabels=list()
    for i in range(10):
        for j in range(500):
            index=np.argwhere(trainData[1]==i)
            index1=np.argwhere(trainData[1]!=i)
            newtrainset.append([trainData[0][index[0][0]],trainData[0][index[0][random.randint(0,index.shape[1]-1)]],trainData[0][index1[0][random.randint(0,index1.shape[1]-1)]]])
            newtrainlabels.append([1,0])
    return newtrainset,newtrainlabels
def generateTestSet(testData):
    newtestset=list()
    newtestlabels=list()
    for i in range(10):
        for j in range(500):
            index=np.argwhere(trainData[1]==i)
            index1=np.argwhere(trainData[1]!=i)
            newtestset.append([trainData[0][index[0][0]],trainData[0][index[0][random.randint(0,index.shape[1]-1)]],trainData[0][index1[0][random.randint(0,index1.shape[1]-1)]]])
            newtestlabels.append([1,0])
    return newtestset,newtestlabels
newtrainset,newtrainlabels=generateTrainSet(trainData)
newtestset,newtestlabels=generateTestSet(testData)
newtrainlabels=torch.tensor(newtrainlabels).float()
newtestlabels=torch.tensor(newtestlabels).float()
train=siameseMNIST(newtrainset,newtrainlabels)
test=siameseMNIST(newtestset,newtestlabels)
trainLoader=DataLoader(dataset=train,batch_size=2,shuffle=True)
testLoader=DataLoader(dataset=test,batch_size=2,shuffle=False)
#print(newtrainset[0])
example=iter(trainLoader)
features,labels=example.next()
print(len(features))
print(len(features[0]))


and the output is–
3
2

and i need the output to be
2
3