Hi! This is how my code for trying to show sample prediction:
def test(model):
  model.eval
  correct = 0
  total = 0

  with torch.no_grad():
      for i in tqdm(range(len(img_test))):

          
          real_class = mask_test[i]
          net_out = model(img_test[i].view(-1, 3, 224, 224))[0]
          _, predicted_class = torch.max(net_out, 0)
          prediction = predicted_class.eq(mask_test[i])
        

          
          plt.figure(figsize=(22,8))

          
          plt.subplot(1, 3, 1)
          plt.imshow(img_test[i].view(-1, 224, 224, 3).detach().cpu().squeeze())
          plt.title('original image')

          plt.subplot(1, 3, 2)
          plt.imshow(real_class.cpu().squeeze())
          plt.title('ground truth')

          plt.subplot(1, 3, 3)
          plt.imshow(predicted_class.cpu().squeeze())
          plt.title('predicted mask')
          
          break

      
test(model)

I have already tried using weighted cross entropy but the result was the same my model predicts everything as a background
image715×227 27.3 KB