yes, I know!! But what I sent is not working, and I would like to understand why!
I get this error: pic should be PIL Image or ndarray. Got <class ‘str’>
batch_size = 1
learning_rate = 0.001
threads=1
train_loader = torch.utils.data.DataLoader(train_dataset, num_workers=threads, batch_size=batch_size, shuffle=True)
val_loader = torch.utils.data.DataLoader(val_dataset, num_workers=threads, batch_size=batch_size, shuffle=False)

class CNN(nn.Module): 
    def __init__(self):
        super(CNN, self).__init__()
        self.conv1 = nn.Conv2d(in_channels=3, out_channels=10, kernel_size=3)
        self.conv2 = nn.Conv2d(10, 20, kernel_size=3)
        self.conv2_drop = nn.Dropout2d()
        self.fc1 = nn.Linear(720, 1024)
        self.fc2 = nn.Linear(1024, 2)

    def forward(self, x):
        x = F.relu(F.max_pool2d(self.conv1(x), 2))
        x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2))
        x = x.view(x.shape[0],-1)
        x = F.relu(self.fc1(x))
        x = F.dropout(x, training=self.training)
        x = self.fc2(x)
        return x

model = CNN()

cuda = torch.cuda.is_available()
print(cuda)
if cuda:
   model = model.cuda()
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(),lr = learning_rate)

starting_epoch=0
epochs=50
best_dice=0
loss_accum = []

for epoch in range(starting_epoch, epochs):  
    print ('Running epoch ',epoch)
    train_loss=0
    val_loss=0
    val_dice=[]

    for phase in ['train','val']:

      if phase=='train':
        loader=train_loader
        model.train()
      else:  
        loader=val_loader
        model.eval()

      for batch in loader:
        if cuda:
          image = batch['image'].cuda()
          target = batch['target'].cuda()
 
        
        #print(image)
        image=Variable(image)
        target=Variable(target) 


        optimizer.zero_grad()
        with torch.set_grad_enabled(phase == 'train'):
          output = model.forward(image)
          output=(output.squeeze(0))
                    
          loss = criterion(output, target) 
         
          if phase=='train':
            loss.backward()
            loss=loss.item()
            optimizer.step()
            train_loss=train_loss+loss*image.size(0)      
          else:
            loss=loss.item()
            val_loss=val_loss+loss*image.size(0)         
            dice=Dice(target.detach().cpu().numpy(),output.detach().cpu().numpy())
            print('Dice score: ',dice)
            val_dice.append(dice)  
          
          print('Loss: ',loss*image.size(0))