Thank you very much for your reply.
Yes that’s the case, I’m sending everything to cuda(), but nvidia-smi gives almost 0% GPU utilisation.
I’m struggling with this since two weeks, I can’t figure out what’s wrong.
Here is my DataLoader Class: (I’m loading data from S3 Bucket into memory via this Class)
class myDataset(Dataset):
    def __init__(self, csv_file, root_dir, target, length, transform=None):
        self.annotations = pd.read_csv(fs.open(csv_file)).iloc[:length,:]
        self.root_dir = root_dir
        self.transform = transform
        self.target = target
        self.length = length

    def __len__(self):
        return len(self.annotations)

    def __getitem__(self, index):
        img_path = fs.open(os.path.join(self.root_dir, self.annotations.loc[index, 'image_id']))
        image = Image.open(img_path)
        image = np.array(image)

        if self.transform:
            image = self.transform(image=image)["image"]

        image = np.transpose(image, (2, 0, 1)).astype(np.float32)
        image = torch.Tensor(image)
        y_label = torch.tensor(int(self.annotations.loc[index, str(self.target)]))
        return image, y_label

And my training loop:
def train_model(model, criterion, optimizer, loader, test_loader, num_epoch):

    for epoch in tqdm(range(num_epoch)):
        #print(f'Epoch -- {epoch}')
        train_one_epoch(model, loader, optimizer, criterion)

def train_one_epoch(model, loader, optimizer, criterion):
    losses = []
    longueur_data = 0
    for batch_idx, (x, y) in enumerate(tqdm(loader)):
        
        x = x.to('cuda')
        y = y.to(torch.float32).unsqueeze(1).to('cuda')
        
        optimizer.zero_grad()
        
        scores= model(x)
        
        loss = criterion(scores, y)
        loss.backward()
        optimizer.step()
        
        losses.append(loss.item())
        longueur_data += x.size(0)

    Loss = sum(losses) / longueur_data
    print(f'Loss Epoch : {Loss}')


Here is the call to my Dataset Class, and my data loading (I’m using albumentations for data augmentation):
aug = al.Compose([
    al.RandomResizedCrop(H, W, p=0.2),
    al.Resize(H, W),
    al.Transpose(p=0.2),
    al.HorizontalFlip(p=0.5),
    al.VerticalFlip(p=0.2),
    al.augmentations.transforms.Normalize(mean=[0.485, 0.456, 0.406], 
                                          std=[0.229, 0.224, 0.225], 
                                          max_pixel_value=255.0, 
                                          always_apply=True, 
                                          p=1.0)
])


dataset = myDataset(csv_file=LABEL_PATH,
                    root_dir=IMAGE_PATH,
                    target='gender',
                    length=LENGTH,
                    transform=aug)

train_set, test_set = torch.utils.data.random_split(dataset,[int(LENGTH*0.8), LENGTH - int(LENGTH*0.8)])


train_loader = DataLoader(dataset=train_set, batch_size=batch_size, shuffle=True)
test_loader = DataLoader(dataset=test_set, batch_size=batch_size, shuffle=True)

I cannot figure out where is the issue.
Thank you very much,