Hi,
Criterion ------> CrossEntropyLoss.
Input image --------->
mask image --------> 
depth image --------> 
The input image i am forwarding through my model and the mask and depth image i am taking as ground truth.
I am doing loss.backward() not on the train loss.
This is my train function
def train(self, train_acc):
        self.model.train()
        pbar = tqdm(self.train_loader)
        train_loss = 0
        length = len(self.train_loader)
        print("Length of train loader is {}".format(length))
        device = self.device
        self.model.to(self.device)
        for batch in enumerate(pbar):
            images = batch[1]['image']
            mask = batch[1]['mask']
            depth = batch[1]['depth']
            print(len(images), len(mask), len(depth))
            images = images.to(device=self.device, dtype=torch.float)
            mask_type = torch.float32 if self.model.n_classes == 1 else torch.long
            mask = mask.to(device=device, dtype=mask_type)
            depth = depth.to(device=device, dtype=mask_type)

            mask_pred = self.model(images)
           
            loss_mask = self.criterion(mask_pred, mask)
            loss_depth = self.criterion(mask_pred, depth)
            loss = loss_mask +  loss_depth 

            train_loss += loss_mask.item() + loss_depth.item()
            #writer.add_scalar('Loss/train', train_loss, global_step)

            pbar.set_postfix(**{'loss (batch)': train_loss})
            self.optimizer.zero_grad()

            # Backpropagation
            loss.backward()
            self.optimizer.step()
            self.scheduler.step()
        
            accuracy = 100*(train_loss/length)
            pbar.set_description(desc= f'Loss={train_loss} Accuracy={accuracy:0.2f}')
            train_acc.append(accuracy)

I don’t know whether it is a correct way or not to add losses for the purpose of depth and mask prediction.
My accuracy also goes to negative.
Please help.
Thanks