facebookresearch / detectron2

Detectron2 is a platform for object detection, segmentation and other visual recognition tasks.
https://detectron2.readthedocs.io/en/latest/
Apache License 2.0
30.02k stars 7.41k forks source link

Size mismatch error between images and masks AFTER loading dataset #5349

Open zacklew opened 1 month ago

zacklew commented 1 month ago

Instructions To Reproduce the Issue:

Trying to train a model using panoptic_fpn

torch.cuda.empty_cache() config_file = "COCO-PanopticSegmentation/panoptic_fpn_R_50_3x.yaml" cfg = get_cfg() cfg.MODEL.DEVICE = "cuda" if torch.cuda.is_available() else "cpu" cfg.merge_from_file(model_zoo.get_config_file(config_file)) cfg.DATASETS.TRAIN = (f"{data_name}_separated",) cfg.DATASETS.TEST = () cfg.DATALOADER.NUM_WORKERS = 0 cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url(config_file)
cfg.SOLVER.IMS_PER_BATCH = 1 cfg.SOLVER.BASE_LR = 0.00025 cfg.SOLVER.MAX_ITER = 5000 cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 16 cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1 cfg.MODEL.SEM_SEG_HEAD.NUM_CLASSES = 2 cfg.MODEL.PANOPTIC_FPN.NUM_CLASSES = 1
cfg.SOLVER.AMP.ENABLED = True

MetadataCatalog.get(cfg.DATASETS.TRAIN[0]).set(thing_classes=things, stuff_classes=stuff, thing_dataset_id_to_contiguous_id={1: 0})

Example images that are causing error bad_imgs_2.zip

Expected behavior:

I've run this exact code with a different custom image set and the model ran fine. There are a few images in this image set (i.e. example images and masks below attached) that we have found to through this size error that says the masks and images are different sizes. I manually checked the dimensions of the masks and images using img properties on my PC, and it says the images and masks are the same dimensions. However, when I check the image and mask sizes after the model loads the dataset, the sizes are different. My running theory is that there is some transformation that occurs with the dataset mapper that changes the dimensions of the masks, but I'm not sure how to see if that is the case or if something else in the code is changing the dimensions of the mask and the image separately.

Any and all help trying to solve this error would be appreciated.

*Example images used in dataset in this repo: ([(https://github.com/zacklew/bad_images)])

Environment:

sys.platform linux Python 3.12.4 packaged by Anaconda, Inc. (main, Jun 18 2024, 15:12:24) [GCC 11.2.0] numpy 1.26.4 detectron2 0.6 @/home/computational/anaconda3/lib/python3.12/site-packages/detectron2 Compiler GCC 11.2 CUDA compiler CUDA 12.5 detectron2 arch flags 8.6 DETECTRON2_ENV_MODULE PyTorch 2.3.1+cu121 @/home/computational/anaconda3/lib/python3.12/site-packages/torch PyTorch debug build False torch._C._GLIBCXX_USE_CXX11_ABI False GPU available Yes GPU 0 NVIDIA RTX A2000 12GB (arch=8.6) Driver version 555.58.02 CUDA_HOME /home/computational/anaconda3 Pillow 10.3.0 torchvision 0.18.1+cu121 @/home/computational/anaconda3/lib/python3.12/site-packages/torchvision torchvision arch flags 5.0, 6.0, 7.0, 7.5, 8.0, 8.6, 9.0 fvcore 0.1.5.post20221221 iopath 0.1.9 cv2 4.10.0

PyTorch built with:

github-actions[bot] commented 1 month ago

You've chosen to report an unexpected problem or bug. Unless you already know the root cause of it, please include details about it by filling the issue template. The following information is missing: "Instructions To Reproduce the Issue and Full Logs";