I have created a custom dataloader to load color images but the data gets loaded on system memory instead of gpu memory.But after increasing no. of workers of Dataloader now it has loaded into gpu memory as well(besides system memory) and cpu usage is 100 % ,but the gpu utilisation is zero.Please help to improve my code.
``class SiameseNetworkDataset(Dataset):
def init(self,imageFolderDataset,transform=None,should_invert=True):
self.imageFolderDataset=imageFolderDataset
self.transform=transform
self.should_invert=should_invert
def __getitem__(self,index):
    img0_tuple=random.choice(self.imageFolderDataset.imgs)
    
    
    should_get_same_class=random.randint(0,1)  #making sure 50% images are in same classes
    if should_get_same_class:
        while True:
            #keep looping till same class image is found
            img1_tuple=random.choice(self.imageFolderDataset.imgs)
            if img0_tuple[1]==img1_tuple[1]:
                break
    else:
        img1_tuple=random.choice(self.imageFolderDataset.imgs)
        
    img0=Image.open(img0_tuple[0]).convert('RGB')
    img1=Image.open(img1_tuple[0]).convert('RGB')
    #img0=img0.convert("L")
    #img1=img1.convert("L")
    
    if self.should_invert:
        img0=PIL.ImageOps.invert(img0)
        img1=PIL.ImageOps.invert(img1)
        
    if self.transform is not None:
        img0=self.transform(img0)
        img1=self.transform(img1)
        
    #print(type(img0_tuple))
    #print(img0_tuple[1])
    #print(img1_tuple[1])
    #print()
        
    return img0,img1,torch.from_numpy(np.array([int(img1_tuple[1]!=img0_tuple[1])],dtype=np.float32))

def __len__(self):
    return len(self.imageFolderDataset.imgs)

folder_dataset=dset.ImageFolder(root=Config.training_dir)
siamese_dataset=SiameseNetworkDataset(imageFolderDataset=folder_dataset,
                                        transform=transforms.Compose([transforms.Resize((100,100)),
                                                                      transforms.ToTensor()
                                                                      ])
                                       ,should_invert=False)

train_dataloader = DataLoader(siamese_dataset,
                        shuffle=True,
                        num_workers=16,
                        batch_size=Config.train_batch_size)
#cudnn.benchmark = True
dtype = torch.cuda.FloatTensor 

net=SiameseNetwork().cuda()
criterion=ContrastiveLoss()
optimizer=optim.Adam(net.parameters(),lr=0.0005)

counter=[]
loss_history=[]
iteration_number=0

for epoch in range(0,Config.train_number_epochs):
    for i,data in enumerate(train_dataloader,0):
        img0,img1,label=data
        img0,img1,label=(Variable(img0).type(dtype)).cuda(),(Variable(img1).type(dtype)).cuda(),(Variable(label).type(dtype)).cuda()
        output1,output2=net(img0,img1)
        optimizer.zero_grad()
        loss_contrastive=criterion(output1,output2,label)
        loss_contrastive.backward()
        optimizer.step()
        if i%10 == 0:
            print("Epoch num {}\n Current loss {}\n".format(epoch,loss_contrastive.item()))
            iteration_number+=10
            counter.append(iteration_number)
            loss_history.append(loss_contrastive.item())

show_plot(counter,loss_history)