I tried to calculate the loss after adding a mask to the output, but the problem is that MSE loss does not drop during the iteration process, the following is a code snippet of my program.
with torch.autograd.set_detect_anomaly(True):
            prediction = net(x, train_pers)
           
            mask_info = scio.loadmat(mask_path)
            pos_x = mask_info['maskVerticesXCoordinates']
            pos_y = mask_info['maskVerticesYCoordinates']
            pos = np.concatenate((pos_x, pos_y), 1).astype(np.int32)  # 8 * 2
            mask_tg = np.zeros((576, 720))
            cv2.fillPoly(mask_tg, [pos], 1)  # fill 1 in the mask
            mask_tg = mask_tg[np.newaxis, np.newaxis, :, :]
            mask = torch.from_numpy(mask_tg)
            mask = functional.interpolate(mask, scale_factor=0.125, mode='nearest')

            prediction = torch.mul(prediction.double(), mask2.to(setting.device))
            prediction = Variable(prediction,requires_grad=True)

            loss = criterion(prediction, y)

            optimizer.zero_grad()
            loss.backward()