I have been trying to use MaskRCNN with a Resnet backbone on the DeepFashion2 Dataset for instance segmentation. The custom configurations are as follows:

class ClothDataset(utils.Dataset):

    # load_dataset function is used to load the train and test dataset
    def load_dataset(self, dataset_dir):
        print("Inside Load Dataset")
        categories = ["short sleeve top", "long sleeve top", "short sleeve outwear", "long sleeve outwear", "vest", "sling", 
                      "shorts", "trousers", "skirt", "short sleeve dress", "long sleeve dress", "vest dress", "sling dress"]
        for index, category in enumerate(categories):
            self.add_class("fashion", index+1, category.lower())

        images_dir = dataset_dir + '/image/'
        annotations_dir = dataset_dir + '/annos/'

        for filename in listdir(images_dir):

            image_id = filename[:-4]
            # img_path and ann_path variables are defined
            img_path = images_dir + filename
            ann_path = annotations_dir + image_id + '.json'
            # using add_image function we pass image_id, image_path and ann_path so that the current
            # image is added to the dataset for training
            self.add_image('fashion', image_id=image_id, path=img_path, annotation=ann_path)

    # function used to extract bouding boxes from annotated files
    def extract_boxes(self, filename):
        print("Inside Extract Boxes")
        boxes = list()
        # Implementation for JSON annotations
        annotation_file = json.load(open(filename))
        for item in annotation_file.keys():
            if item != "source" and item != "pair_id":
                name = annotation_file[item]['category_name'].lower()
                coors = annotation_file[item]['bounding_box']
        # Extracting width and height of the image
        image_path = filename.replace("annos", "image").replace("json", "jpg")
        image = skimage.io.imread(image_path)
        height, width = image.shape[:2]
        return boxes, width, height

    # returns a boolean mask with following dimensions width * height * instances        
    def load_mask(self, image_id):
        print("Inside Load Mask")
        info = self.image_info[image_id]
        path = info['annotation']
        boxes, w, h = self.extract_boxes(path)
        masks = np.zeros([h, w, len(boxes)], dtype='uint8')
        class_ids = list()
        for i in range(len(boxes)):
            box = boxes[i]
            masks[box[1]:box[3], box[0]:box[2], i] = self.class_names.index(box[4])
        return masks, np.asarray(class_ids, dtype='int32')
    # this functions takes the image_id and returns the path of the image
    def image_reference(self, image_id):
        info = self.image_info[image_id]
        return info['path']

class ClothConfig(Config):
    # name of the configuration
    NAME = "fashion_config"
    GPU_COUNT = 1
    # Number of Classes
    NUM_CLASSES = 1 + 13

    # Image Dimensions
    IMAGE_RESIZE_MODE = 'square'
    BACKBONE = 'resnet50'
    TRAIN_BN = True
    # Learning Rate
    LEARNING_RATE = 0.004
    WEIGHT_DECAY = 0.0
    LR_SCHEDULE = True
    # Dataloader Queue Size (was set to 100 but resulted in OOM error)
    # Cache Items
    CACHE = True
    # Debug mode will disable model checkpoints
    DEBUG = False
    # Do not use multithreading as this slows down the dataloader!
    WORKERS = 0
    # Losses
        'rpn_class_loss': 1.0,    # is the class of the bbox correct? / RPN anchor classifier loss (Forground/Background)
        'rpn_bbox_loss': 1.0,     # is the size of the bbox correct? / RPN bounding box loss graph (bbox of generic object)
        'mrcnn_class_loss': 1.0,  # loss for the classifier head of Mask R-CNN (Background / specific class)
        'mrcnn_bbox_loss': 1.0,   # is the size of the bounding box correct or not? / loss for Mask R-CNN bounding box refinement
        'mrcnn_mask_loss': 1.0,   # is the class correct? is the pixel correctly assign to the class? / mask binary cross-entropy loss for the masks head
    # Training Structure
    RPN_ANCHOR_SCALES = (32, 64, 128, 256, 512)

However, I get a 'list index out of range' error on calling model.train(..) and from the error stack I can't seem to figure out where exactly the issue is. Attaching the error logs below,

enter image description here enter image description here

Any help is much appreciated. Thank you!


1 Answer 1



I've narrowed down the issue to a possible Tensorflow version incompatibility. Though I don't have all the specifics, it seems the problem might be related to this.

To provide more context, I was working with Kaggle kernels to run the model. Initially, I was modifying an existing notebook in an attempt to reuse the original environment. That's when I encountered the error logs mentioned earlier. As an alternative, I tried using another notebook with a different, more up-to-date pinned environment, and interestingly, the same model worked(snapshot attached).

MaskRCNN Running

  • $\begingroup$ As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. $\endgroup$
    – Community Bot
    Aug 15, 2023 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.