The image is size [3, H, W], there are a total 63 classes.
IF there are 5 objects in the image, labels are size , bounding boxes size [5,4], masks [5,H,W]. Why do I get this error message:
IndexError: The shape of the mask  at index 0 does not match the shape of the indexed tensor [14, 63, 28, 28] at index 1
Where does 14 come from? Here’s the architecture of the model, it seems correct and it worked on other problem. I don’t understand this error at all.
Isn’t 14 your batch size?
What do you mean? Theres 1 image with 5 objects/labels/bboxes/masks. I have no idea where 14 comes. 63 is the number of classes
It seems like both the mask and the indexed Tensor have a size 14 for the 0th dimension. In neural network, that usually correspond to batch.
If it does not, could you make a small code sample that we can run that reproduces the issue?
It cant be small, it’s pretty much the whole dataset + training script. The sizes of the labels are specified above. My other code for Mask rcnn doesn’t report error like this. I found a couple of masks with all 0s, that’s not what’s causing it.
To begin with i dont understand where 14 comes from, it’s not a number that pops up anywhere in my code. It’s something mask rcnn does internally, maybe fpn output? the intended output size of mask module during training is num-class×28×28.
Alright, I found it! Nothing to do with sizes at all! Turns out, formats of tensors were incorrect. I changed to:
self.lab[‘labels’] = torch.tensor(labels, dtype=
self.lab[‘boxes’] = torch.tensor(boxes, dtype = torch.float)
self.lab[‘masks’] = torch.tensor(masks, dtype = torch.uint8)
Before that they all were uint8. Damn it!
I am having the same issue when applying the loss function in this GitHub:
This file has been truncated.
import torch.nn.functional as F
from collections import defaultdict
from torch import nn
from torch.nn import CrossEntropyLoss, NLLLoss
from torch.nn import Dropout
from transformers import BertConfig, BertModel, BertForMaskedLM
from typing import Any
self.bert_model = BertForMaskedLM.from_pretrained(model_name_or_path)
outputs = self.bert_model(input_ids, masked_lm_labels=mlm_labels)
I have tried changing the types by no luck. what do you think the issue is
Screen Shot 2021-04-20 at 10.14.36 PM|690x254