Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The shape of the mask [268569] at index 0 does not match the shape of the indexed tensor [0] at index 0 #17

Closed
jpainam opened this issue Sep 13, 2020 · 10 comments

Comments

@jpainam
Copy link

jpainam commented Sep 13, 2020

Problem with Instance Segmentation

Hi, I trained a maskrcnn model without your augmented data/annotation and it worked well. Using your data/annotation folder and file. I got this error

Traceback (most recent call last):
  File "tools/train_net.py", line 171, in <module>
    main()
  File "tools/train_net.py", line 164, in main
    model = train(cfg, args.local_rank, args.distributed)
  File "tools/train_net.py", line 73, in train
    arguments,
  File "/home/eldad/maskscoring_rcnn/maskrcnn_benchmark/engine/trainer.py", line 66, in do_train
    loss_dict = model(images, targets)
  File "/home/eldad/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/eldad/maskscoring_rcnn/maskrcnn_benchmark/modeling/detector/generalized_rcnn.py", line 49, in forward
    proposals, proposal_losses = self.rpn(images, features, targets)
  File "/home/eldad/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/eldad/maskscoring_rcnn/maskrcnn_benchmark/modeling/rpn/rpn.py", line 100, in forward
    return self._forward_train(anchors, objectness, rpn_box_regression, targets)
  File "/home/eldad/maskscoring_rcnn/maskrcnn_benchmark/modeling/rpn/rpn.py", line 119, in _forward_train
    anchors, objectness, rpn_box_regression, targets
  File "/home/eldad/maskscoring_rcnn/maskrcnn_benchmark/modeling/rpn/loss.py", line 91, in __call__
    labels, regression_targets = self.prepare_targets(anchors, targets)
  File "/home/eldad/maskscoring_rcnn/maskrcnn_benchmark/modeling/rpn/loss.py", line 62, in prepare_targets
    labels_per_image[~anchors_per_image.get_field("visibility")] = -1
RuntimeError: The shape of the mask [268569] at index 0 does not match the shape of the indexed tensor [0] at index 0

So i guess, the error is coming from the fact that, for a rotation, the shape of the images does not match anymore.
I used this tutorial https://colab.research.google.com/github/joheras/CLoDSA/blob/master/notebooks/CLODSA_Instance_Segmentation.ipynb

@joheras
Copy link
Owner

joheras commented Sep 14, 2020

Hi,

So, the problem is happenning with the maskrcnn library that you are using, right?

Could you indicate me which implementation of MaskRcnn are you using so I can try to reproduce the error? Could you also send me the augmentations that you applied to your dataset?

Best

@jpainam
Copy link
Author

jpainam commented Sep 14, 2020

Hi, this is the augmentations i applied to my dataset

import matplotlib.pyplot as plt
from clodsa.augmentors.augmentorFactory import createAugmentor
from clodsa.transformers.transformerFactory import transformerGenerator
from clodsa.techniques.techniqueFactory import createTechnique
import cv2

PROBLEM = "instance_segmentation"
ANNOTATION_MODE = "coco"
INPUT_PATH = "/home/eldad/data/VOCdevkit/VOC2007/JPEGImages/"
GENERATION_MODE = "linear"
OUTPUT_MODE = "coco"
OUTPUT_PATH = "/home/eldad/data/maskrcnn_train_augmented/"

augmentor = createAugmentor(PROBLEM, ANNOTATION_MODE, OUTPUT_MODE,
                            GENERATION_MODE, INPUT_PATH,
                            {"outputPath": OUTPUT_PATH}
                            )
transformer = transformerGenerator(PROBLEM)

for angle in [90, 180]:
    rotate = createTechnique("rotate", {"angle": angle})
    augmentor.addTransformer(transformer(rotate))

flip = createTechnique("flip", {"flip": 1})
augmentor.addTransformer(transformer(flip))

none = createTechnique("none", {})
augmentor.addTransformer(transformer(none))

augmentor.applyAugmentation()

I used maskscoring which is built on top of maskscrcnn. The core of maskscoring is till maskrcnn as you can see in the Traceback error. Here the repository
https://github.com/zjhuang22/maskscoring_rcnn
Thanks

@joheras
Copy link
Owner

joheras commented Sep 14, 2020 via email

@jpainam
Copy link
Author

jpainam commented Sep 15, 2020

Hi, it's a little bit difficult to provide you with a minimal example. We have generated more than 4000 images using your tool and we don't really know which image is causing this problem.
Since rotation, and flipping change the width and height of the image, i would like to know if your tool also rotates or flips the annotation values?

Thank you.
Meanwhile, we will try our best to provide you with a minimal example.

@joheras
Copy link
Owner

joheras commented Sep 15, 2020 via email

@Eldad27
Copy link

Eldad27 commented Sep 19, 2020

@joheras I've been following this.

  1. can you please provide a brief explanation of how this augmentation process (for instance segmentation) handle images in a dataset without annotations (no ground truth)? What's your advice on augmenting images without ground truth (negative samples)?

  2. Could there be a possibility that negative coordinates are generated as part of the augmentation through some faulty files during the augmentation process?

@jpainam
Copy link
Author

jpainam commented Sep 20, 2020

@joheras @Eldad27 I found out that, though I have images without annotations. (i.e, the segmentation field is [[]], these images do not appear in the new json file or the output folder. I guess CLoDSA removes them before creating the new json file.

Empty segmentation fields are also represented as [[]]. I didn't find a single one in my annotation file

@joheras
Copy link
Owner

joheras commented Sep 20, 2020 via email

@joheras
Copy link
Owner

joheras commented Sep 21, 2020 via email

@jpainam
Copy link
Author

jpainam commented Sep 21, 2020

Hi, I found the problem. It is related with maskrcnn. So, i'm going to close this issuee.
When bbox is empty, it raises this error, i fixed it by removing all images without bbox as shown in this issue
facebookresearch/maskrcnn-benchmark#31

This is what i did to make the training works

#data/datasets/coco.py
        ids_to_remove = []
        for img_id in self.ids:
            ann_ids = self.coco.getAnnIds(imgIds=img_id)
            anno = self.coco.loadAnns(ann_ids)
            if all(
                any(o <= 1 for o in obj['bbox'][2:])
                for obj in anno
                if obj['iscrowd'] == 0
            ):
                ids_to_remove.append(img_id)
        self.ids = [img_id for img_id in self.ids if img_id not in ids_to_remove]

Maybe, it is also related with the way CLoDSA deals with empty bbox . You can check that too

@jpainam jpainam closed this as completed Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants