Thanks for the information.
I found it like that somewhere…
I changed the dataloader loop and printed the size of the tensors inside it.
At least this now seems to be ok.
The image-tensors have the size torch.Size([1, 3, 1000, 1000]) and the masks have torch.Size([1, 1, 1000, 1000]).
This is the current training loop:
num_epochs = 1
for e in range(num_epochs):
    # Training:
    model.train() 
    for img, mask in dataloader_train:
        img, mask = img.cuda(), mask.cuda()
        
        #img = torch.squeeze(img, 0)
        #mask = torch.squeeze(mask, 0)
        
        # For debug only:
        #print(img.shape)
        #print(mask.shape)
        #print(torch.squeeze(img, 0).shape)
        #break
        
        img = img.to(device)
        mask = mask.to(device)
        output = model(img)
        loss = criterion(output, mask)
        print(loss.cpu())
        
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()

Now I get another error in the line output = model(img):

…python3.8/site-packages/torch/nn/functional.py", line 1666, in batch_norm
raise ValueError(‘Expected more than 1 value per channel when training, got input size {}’.format(size))
ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 256, 1, 1])

I am wondering why the tensors have four dimensions instead of three.
Because of that I used         img = torch.squeeze(img, 0),         mask = torch.squeeze(mask, 0) but with that I get the error:

…python3.8/site-packages/torch/nn/modules/conv.py", line 341, in conv2d_forward
return F.conv2d(input, weight, self.bias, self.stride,
RuntimeError: Expected 4-dimensional input for 4-dimensional weight 64 3 7 7, but got 3-dimensional input of size [1, 1000, 1000] instead

Do I have to squeeze or not and where comes the corresponding error from?
Thank you very much