Thank you for your response.
I am certain every pixel is labeled but I switched to torch.zeros to be sure.
How do you recommend I check the mask for each class?
Nonetheless, here is my updated code:
    def __getitem__(self, index):
        img_path = os.path.join(self.image_dir, self.images[index])
        mask_path = os.path.join(self.mask_dir, self.images[index].replace(".jpg", "_mask.png"))
        image = np.array(Image.open(img_path).convert("RGB"))
        mask = np.array(Image.open(mask_path).convert("RGB"))
        target = torch.from_numpy(mask)
        h,w = target.shape[0], target.shape[1]
        mask = torch.zeros(h, w, dtype = torch.long)
        colors = torch.unique(target.view(-1, target.size(2)), dim=0).numpy()
        target = target.permute(2, 0, 1).contiguous()
        mapping = {tuple(c): t for c, t in zip(colors.tolist(), range(len(colors)))}
        print(f"target shape: {target.shape}\n")

        for k in mapping:
            # Get all indices for current class
            idx = (target==torch.tensor(k, dtype=torch.uint8).unsqueeze(1).unsqueeze(2))
            validx = (idx.sum(0) == 3)  # Check that all channels match
            mask[validx] = torch.tensor(mapping[k], dtype=torch.long)
            print(f"idx shape: {idx.shape}\n")
            print(f"validx shape: {validx.shape}\n")
            
        image = transforms.ToTensor()(image)   
        print(f"image shape: {image.shape}\n")
        print(f"mask shape: {mask.shape}\n")
        torchvision.utils.save_image(image, "data/inside_data_loader/" + self.images[index])
        torchvision.utils.save_image(mask.float(), "data/inside_data_loader/" + self.images[index].replace(".jpg", "_mask.png"))
        return image, mask

Here is the output:
target shape: torch.Size([3, 1000, 1000])

idx shape: torch.Size([3, 1000, 1000])

validx shape: torch.Size([1000, 1000])

image shape: torch.Size([3, 1000, 1000])

mask shape: torch.Size([1000, 1000])

@ptrblck This procedure is based off of some solutions that you gave in order to create a mask for multi-class segmentation. If you have the time, would you mind taking a look at this? The problem is that my mask does not seem to be read in correctly to the model (loss of color and loss of class data) which thereby affects my model performance. Thank you very much!