Hello everyone,
I am working on a multilabel classification in which I want to predict several scores/labels for each image.
I am using a pretrained ResNet as model and the training returns very good results.
But I am having some trouble to plot the images and the predicted labels to visualize the results.
My training function looks like this:

        # Each epoch has a training and validation phase
        for phase in ['train', 'val']:
            if phase == 'train':
                model.train()  # Set model to training mode
            else:
                model.eval()   # Set model to evaluate mode

            running_loss = 0.0
            running_corrects = 0
            average_precis = 0.001
            loss_values = []
            gr_truth_val = np.array([]) #convet to int dtype
            preds_val = np.array([])
            gr_truth_val = gr_truth_val.astype(int)
            preds_val = preds_val.astype(int) 
            av_precision_overall = np.array([]).astype(float)

            # Iterate over data.
            #for inputs in dataloaders[phase]:
            print('Iterating over data:')
            
            for batch_idx, (inputs, labels) in enumerate(dataloaders[phase]):
                inputs = inputs.to(device)
                labels = labels.to(device).float()
                gt_data = labels
                gt_data = gt_data.to(device)
                gt_data = gt_data.cpu().data.numpy()
                # zero the parameter gradients
                optimizer.zero_grad()
                # forward
                # track history if only in train
                #pdb.set_trace()
                if phase == 'train':
                  with torch.set_grad_enabled(phase == 'train'):
                      outputs = model(inputs)
                      outputs = outputs.cpu()#.data.numpy()
                      preds = outputs.cpu().data.numpy()
                      preds = np.round(preds) #set a condition for binary
                      gt_data = np.round(gt_data)
                      gt_data = torch.from_numpy(gt_data)
                      loss = criterion(outputs, gt_data)
                    # backward + optimize only if in training phase
                      if phase == 'train':
                          loss.backward()
                          optimizer.step()
                # statistics
                  running_loss += loss.item() * inputs.size(0)
                  running_corrects += f1_score(gt_data, preds, average='samples')
                #pdb.set_trace()
                else:
                  #pdb.set_trace()
                  with torch.no_grad():
                      val_outputs = model(inputs)
                      val_outputs = val_outputs.cpu()#.data.numpy()
                      val_preds = val_outputs.cpu().data.numpy()
                      val_preds = np.round(val_preds) #set a condition for binary
                      val_preds = val_preds.astype(int)
                      #pdb.set_trace()
                      val_gtdata_np = np.round(gt_data)
                      val_gtdata_int = val_gtdata_np.astype(int)
                      val_gtdata = torch.from_numpy(val_gtdata_np)
                      loss = criterion(val_outputs, val_gtdata)
                      gr_truth_val = np.append(gr_truth_val, val_gtdata_int)
                      preds_val = np.append(preds_val ,val_preds)
                  # statistics
                  running_loss += loss.item() * inputs.size(0)
                  running_corrects += f1_score(val_gtdata, val_preds, average='samples')
                   
                
            if phase == 'train':
                scheduler.step()    
            epoch_loss = running_loss / len(dataloaders[phase].dataset)
            epoch_acc = running_corrects / len(dataloaders[phase].dataset) 
            epoch_acc = np.round(epoch_acc, decimals=4)
            if phase == 'val':
              scheduler.step()
              epoch_loss = running_loss / len(dataloaders[phase].dataset)
              epoch_acc = running_corrects / len(dataloaders[phase].dataset) #running_corrects.float()
              epoch_acc = np.round(epoch_acc, decimals=4)
              average_precis += average_precision_score(gr_truth_val, preds_val, average="macro")
              av_precision_overall = np.append(av_precision_overall ,average_precis)
              #precision = average_precis
              precision = average_precis / len(dataloaders[phase].dataset)


            print('{} Loss: {:.4f}'.format(phase, epoch_loss))
            print("Acc:", epoch_acc)
            print("Average precision:", average_precis)
        
        
        print()
            
  

And I don’t know how I can plot the “outputs” of the model in RGB (my predictions and labels are in binary) in order to have something like that:
[image] #show image here
0.9465 [‘dirty’] 0.6558 [‘storm’] 1.0 [‘snow’] 1.0 [‘cold’] 1.0 [‘winter’] 0.9045 [‘dull’] 0.9171 [‘moist’] 0.9255 [‘ice’] 0.7018 [‘cluttered’] 0.8918 [‘boring’] #labels here