NielsRogge / Transformers-Tutorials

This repository contains demos I made with the Transformers library by HuggingFace.
MIT License
8.51k stars 1.34k forks source link

Error with Mask2Former Custom Dataset Training on no-object images #257

Closed steveyu323 closed 1 year ago

steveyu323 commented 1 year ago

Dear Team, I'm currently trying to fine-tune the current model, since I don't have semantic labels, I used only one class label

id2label = {0:"true object"}
print(id2label)
processor = AutoImageProcessor.from_pretrained("facebook/mask2former-swin-base-coco-instance")
model = Mask2FormerForUniversalSegmentation.from_pretrained("facebook/mask2former-swin-base-coco-instance",
                                                           id2label=id2label,
                                                          ignore_mismatched_sizes=True)

I build a data loader following the MaskFormer tutorial and it worked well on training the MaskFormer, when I switch to Mask2Former, however, I encountered the following error

grid_sampler(): expected 4D or 5D input and grid with same number of dimensions, but got input with sizes [0, 1] and grid with sizes [0, 12544, 1, 2]

The error only pops with images where class label is with the shape torch.Size([0]), ie no object in the frame. Is there a way to fix this? Thank you so much.