Hi, I am trying to train an instance segmentation model with pytorch. I am using the torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=True). i have 143 classes which are not part of the categories the model was pretrained on. I created my datset class which functions properly. it returns the image, and the target dict. Below is the dataset class.
class clothDataset(torch.utils.data.Dataset):
class clothDataset(torch.utils.data.Dataset):

   

   def __init__(self, root, transforms=None):

       self.root = root

       self.transforms = transforms

       # load all image files, sorting them to

       # ensure that they are aligned

       self.imgs = list(sorted(os.listdir(os.path.join(root, "image"))))

       self.annos = list(sorted(os.listdir(os.path.join(root, "annos"))))

               

   def extract_detectors(self, file_path):

       #parse the json

       with open(file_path) as json_file:
           data = json.load(json_file)
       return [dict(data[detection_object]) for detection_object in data if type(data[detection_object]) == dict]

       

   def __getitem__(self, idx):
       annotation_path = os.path.join(self.root, 'annos')

       all_objects = self.extract_detectors( os.path.join(annotation_path, os.listdir(annotation_path)[idx]) )

       # load images ad masks

       num_objs = len(all_objects)

       

       img_path = os.path.join(self.root, "image", self.imgs[idx])

       masks = [detector['segmentation'][0] for detector in all_objects]

       boxes = [detector['bounding_box'] for detector in all_objects]

       labels = [detector['category_id'] for detector in all_objects]

       image_id = torch.tensor([idx])

       img = Image.open(img_path).convert("RGB")

       

       boxes = torch.as_tensor(boxes, dtype=torch.float32)

       area = (boxes[:, 3] - boxes[:, 1]) * (boxes[:, 2] - boxes[:, 0])

       iscrowd = torch.zeros((num_objs,), dtype=torch.int64)

       labels = torch.as_tensor(labels, dtype=torch.int64)

       if len(masks) > 1:

           max_len = max([len(x) for x in masks])

           masks = [np.pad(x, (0, max_len - len(x)), 'constant') for x in masks]

       masks = torch.as_tensor(masks, dtype=torch.uint8)

       

       target = {}

       target["boxes"] = boxes

       target["labels"] = labels

       target["masks"] = masks

       target["image_id"] = image_id

       target["area"] = area

       target["iscrowd"] = iscrowd

       

       if self.transforms is not None:

           img, target = self.transforms(img, target)

       return img, target

   

   def __len__(self):

       return len(self.imgs)

Please any help at this point will be appreciated!