Thanks a lot, @Youyoun, your solution resolved the IndexError.
However, I now get a different error when trying to train the model:
epochs = 20
min_valid_loss = np.inf
loss_values_train = []
loss_values_val = []

acc_values_train = []
acc_values_val = []
for e in range(epochs):
    y_pred_train = []
    y_true_train = []

    train_loss = 0.0
    model.train()     # Optional when not using Model Specific layer
    for data, labels in train_loader:
        if torch.cuda.is_available():
            data, labels = data.cuda(), labels.cuda()
        
        optimizer.zero_grad()
        target = model(data)
        print(target)
        loss = criterion(target,labels)
        loss.backward()
        optimizer.step()
        train_loss += loss.item() * data.size(0) 
        
        _, preds = torch.max(target, 1)
        y_pred_train.append(preds.tolist())
        y_true_train.append(labels.tolist())

    y_pred_train = [item for sublist in y_pred_train for item in sublist]
    y_true_train = [item for sublist in y_true_train for item in sublist]
    train_acc = accuracy_score(y_true_train, y_pred_train)
    acc_values_train.append(train_acc)
    loss_values_train.append(train_loss / len(train_loader))
    
    y_pred_val = []
    y_true_val = []
    
    valid_loss = 0.0
    model.eval()     # Optional when not using Model Specific layer
    for data, labels in val_loader:
        if torch.cuda.is_available():
            data, labels = data.cuda(), labels.cuda()
        
        target = model(data)
        loss = criterion(target,labels)
        valid_loss += loss.item() * data.size(0)
        
        _, preds = torch.max(target, 1)
        y_pred_val.append(preds.tolist())
        y_true_val.append(labels.tolist())
        
    y_pred_val = [item for sublist in y_pred_val for item in sublist]
    y_true_val = [item for sublist in y_true_val for item in sublist]
    val_acc = accuracy_score(y_true_val, y_pred_val)
    acc_values_val.append(val_acc)
    loss_values_val.append(valid_loss / len(val_loader))
    
    print(f'Epoch {e+1}: \n Training Loss: {train_loss/len(train_loader)} \t Training Acc: {train_acc} \n Validation Loss: {valid_loss/len(val_loader)} \t Validation Acc: {val_acc}')
    if min_valid_loss > valid_loss:
        min_valid_loss = valid_loss
        # Saving State Dict
        torch.save(model.state_dict(), 'resnet_model.pth')

---------------------------------------------------------------------------

tensor([[ 0.1182,  0.1314,  0.0728, -0.0236],
        [ 0.1169,  0.1362,  0.0707, -0.0107],
        [ 0.1232,  0.1335,  0.0721, -0.0102],
        [ 0.1210,  0.1218,  0.0656, -0.0114],
        [ 0.1180,  0.1376,  0.0793, -0.0139],
        [ 0.1136,  0.1300,  0.0782, -0.0301],
        [ 0.1139,  0.1294,  0.0726, -0.0256],
        [ 0.1209,  0.1298,  0.0703, -0.0201],
        [ 0.1202,  0.1272,  0.0728, -0.0251],
        [ 0.1221,  0.1278,  0.0727, -0.0245],
        [ 0.1231,  0.1286,  0.0757, -0.0226],
        [ 0.1216,  0.1305,  0.0756, -0.0254],
        [ 0.1219,  0.1298,  0.0752, -0.0226],
        [ 0.1213,  0.1308,  0.0761, -0.0256],
        [ 0.1234,  0.1294,  0.0742, -0.0261],
        [ 0.1210,  0.1275,  0.0736, -0.0225],
        [ 0.1211,  0.1280,  0.0748, -0.0246],
        [ 0.1237,  0.1290,  0.0737, -0.0197],
        [ 0.1225,  0.1302,  0.0763, -0.0223],
        [ 0.1222,  0.1330,  0.0765, -0.0226],
        [ 0.1231,  0.1316,  0.0746, -0.0217],
        [ 0.1209,  0.1325,  0.0772, -0.0254],
        [ 0.1235,  0.1270,  0.0750, -0.0191],
        [ 0.1219,  0.1286,  0.0753, -0.0236],
        [ 0.1199,  0.1309,  0.0744, -0.0239],
        [ 0.1213,  0.1314,  0.0740, -0.0223],
        [ 0.1215,  0.1310,  0.0742, -0.0223],
        [ 0.1214,  0.1317,  0.0738, -0.0223],
        [ 0.1224,  0.1317,  0.0734, -0.0223],
        [ 0.1211,  0.1314,  0.0740, -0.0222],
        [ 0.1206,  0.1305,  0.0748, -0.0225],
        [ 0.1213,  0.1313,  0.0745, -0.0228]], device='cuda:0',
       grad_fn=<AddmmBackward>)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-f023976bdd04> in <module>
     19         target = model(data)
     20         print(target)
---> 21         loss = criterion(target,labels)
     22         loss.backward()
     23         optimizer.step()

~\miniconda3\envs\glaucoma\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
   1049         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1050                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1051             return forward_call(*input, **kwargs)
   1052         # Do not call functions when jit is used
   1053         full_backward_hooks, non_full_backward_hooks = [], []

~\miniconda3\envs\glaucoma\lib\site-packages\torch\nn\modules\loss.py in forward(self, input, target)
   1119     def forward(self, input: Tensor, target: Tensor) -> Tensor:
   1120         return F.cross_entropy(input, target, weight=self.weight,
-> 1121                                ignore_index=self.ignore_index, reduction=self.reduction)
   1122 
   1123 

~\miniconda3\envs\glaucoma\lib\site-packages\torch\nn\functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction)
   2822     if size_average is not None or reduce is not None:
   2823         reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 2824     return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
   2825 
   2826 

ValueError: Expected input batch_size (32) to match target batch_size (8).

When printing out the shape of the tensor after the flatten operation, I get the following:
x = torch.flatten(y, start_dim=1)
print(x.shape)

---------------------------------------------------------------------------

torch.Size([8, 40000])

Seems to me, as if there still is an issue with dimensionality of my tensor.