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.42k forks source link

Assertion called when I try to visualize the ground truth of Pascal VOC #1089

Closed SkeletonOne closed 4 years ago

SkeletonOne commented 4 years ago

If you do not know the root cause of the problem / bug, and wish someone to help you, please post according to this template:

Instructions To Reproduce the Issue:

  1. what changes you made (git diff) or what code you wrote
    
    from detectron2.data.datasets import register_coco_instances
    register_coco_instances("voc2007train", {}, "./pascal_train2007.json", "./datasets/VOC2007/JPEGImages")
    register_coco_instances("voc2007val", {}, "./pascal_val2007.json", "./datasets/VOC2007/JPEGImages")
    register_coco_instances("voc2007test", {}, "./pascal_test2007.json", "./datasets/VOC2007/JPEGImages")
    register_coco_instances("voc2012train", {}, "./pascal_train2012.json", "./datasets/VOC2012/JPEGImages")
    register_coco_instances("voc2012val", {}, "./pascal_val2012.json", "./datasets/VOC2012/JPEGImages")

from detectron2.data import DatasetCatalog, MetadataCatalog dataset_dicts = DatasetCatalog.get("voc2012val")

2. what exact command you run: dataset_dicts = DatasetCatalog.get("voc2012val")
3. what you observed (including __full logs__):

[03/23 01:51:26 d2.data.datasets.coco]: Loaded 5823 images in COCO format from ./pascal_val2012.json

AssertionError Traceback (most recent call last)

in () 1 from detectron2.data import DatasetCatalog, MetadataCatalog ----> 2 dataset_dicts = DatasetCatalog.get("voc2012val") 3 my_metadata = MetadataCatalog.get("voc2012val") 4 for d in random.sample(dataset_dicts, 3): 5 img = cv2.imread(d["file_name"]) 2 frames /content/detectron2/detectron2/data/datasets/coco.py in load_coco_json(json_file, image_root, dataset_name, extra_annotation_keys) 152 assert anno["image_id"] == image_id 153 assert anno.get("ignore", 0) == 0 --> 154 obj = {key: anno[key] for key in ann_keys if key in anno} 155 156 segm = anno.get("segmentation", None) AssertionError: ``` 4. please also simplify the steps as much as possible so they do not require additional resources to run, such as a private dataset. I am trying to finetune the coco pretrained model on pascal voc dataset, and the coco format annotations were downloaded from the coco website http://cocodataset.org/#external. So I am treating pascal voc as a coco-format custom dataset. But when I try to visualize the ground truths, assertion occurred when I call DatasetCatalog.get(). ## Expected behavior: If there are no obvious error in "what you observed" provided above, please tell us the expected behavior. If you expect the model to converge / work better, note that we do not give suggestions on how to train a new model. Only in one of the two conditions we will help with it: (1) You're unable to reproduce the results in detectron2 model zoo. (2) It indicates a detectron2 bug. ## Environment: I ran the code on Google Colab. Provide your environment information using the following command: ``` wget -nc -q https://github.com/facebookresearch/detectron2/raw/master/detectron2/utils/collect_env.py && python collect_env.py ``` If your issue looks like an installation issue / environment issue, please first try to solve it yourself with the instructions in https://github.com/facebookresearch/detectron2/blob/master/INSTALL.md#common-installation-issues
ppwwyyxx commented 4 years ago

Please include full logs as the issue template requested.

SkeletonOne commented 4 years ago

@ppwwyyxx Thanks for your reply, but I am not sure what does 'full logs' means. The block I ran in google colab is ''' from detectron2.data import DatasetCatalog, MetadataCatalog dataset_dicts = DatasetCatalog.get("voc2007train") my_metadata = MetadataCatalog.get("voc2007train") for d in random.sample(dataset_dicts, 3): img = cv2.imread(d["file_name"]) visualizer = Visualizer(img[:, :, ::-1], metadata=my_metadata, scale=0.5) vis = visualizer.draw_dataset_dict(d) cv2_imshow(vis.get_image()[:, :, ::-1]) '''

and get the output message ''' [03/23 02:07:28 d2.data.datasets.coco]: Loaded 2501 images in COCO format from ./pascal_train2007.json

AssertionError Traceback (most recent call last)

in () 1 from detectron2.data import DatasetCatalog, MetadataCatalog ----> 2 dataset_dicts = DatasetCatalog.get("voc2007train") 3 my_metadata = MetadataCatalog.get("voc2007train") 4 for d in random.sample(dataset_dicts, 3): 5 img = cv2.imread(d["file_name"]) 2 frames /content/detectron2/detectron2/data/datasets/coco.py in load_coco_json(json_file, image_root, dataset_name, extra_annotation_keys) 152 assert anno["image_id"] == image_id 153 assert anno.get("ignore", 0) == 0 --> 154 obj = {key: anno[key] for key in ann_keys if key in anno} 155 156 segm = anno.get("segmentation", None) AssertionError: ''' So what else should I provide? thanks! Besides, the install method is a local clone git clone https://github.com/facebookresearch/detectron2.git cd detectron2 && python -m pip install -e .
SkeletonOne commented 4 years ago

Environment:


sys.platform linux Python 3.6.9 (default, Nov 7 2019, 10:44:02) [GCC 8.3.0] numpy 1.18.2 detectron2 0.1.1 @/content/detectron2/detectron2 detectron2 compiler GCC 7.5 detectron2 CUDA compiler 10.0 detectron2 arch flags sm_61 DETECTRON2_ENV_MODULE PyTorch 1.4.0+cu100 @/usr/local/lib/python3.6/dist-packages/torch PyTorch debug build False CUDA available True GPU 0 Tesla P4 CUDA_HOME /usr/local/cuda NVCC Cuda compilation tools, release 10.0, V10.0.130 Pillow 7.0.0 torchvision 0.5.0+cu100 @/usr/local/lib/python3.6/dist-packages/torchvision torchvision arch flags sm_35, sm_50, sm_60, sm_70, sm_75 cv2 4.1.2


PyTorch built with:

ppwwyyxx commented 4 years ago

OK.. I'm not familiar with Colab but from what you described it sounds like the assertion happens at line 153, although the logs say 154.

In that case, your json file has annotations that are "ignored" which we do not support.

SkeletonOne commented 4 years ago

@ppwwyyxx So it means the official .json file of PASCAL VOC provided by COCO website does not meet the requirements of registering a custom dataset in coco format.... am I right?

ppwwyyxx commented 4 years ago

That's right. In fact I'm not even sure those json are converted correctly from the original dataset. There is no code that shows how they are generated.

SkeletonOne commented 4 years ago

@ppwwyyxx I just checked the json file and obviously pascal voc has a "ignore" annotation. One instance in pascal voc 2007 json file: {"segmentation":[[0,247,0,307,42,307,42,247]],"area":2520,"iscrowd":0,"image_id":1548,"bbox":[0,247,42,60],"category_id":9,"id":1159,"ignore":1} One instance in coco 2017 val file: {"segmentation": [[315.45,158.61,301.63,159.87,296.61,145.21,297.45,133.49,293.68,132.65,294.1,118.0,304.98,103.35,310.01,100.0,338.89,101.67,339.73,119.68,341.82,139.35,327.59,141.03,319.22,143.96]],"area": 2065.0249,"iscrowd": 0,"image_id": 210273,"bbox": [293.68,100.0,48.14,59.87],"category_id": 6,"id": 169222}

So I suppose by letting the code ignore the "ignore" annotation may helps.....

SkeletonOne commented 4 years ago

solved by adding anno.pop("ignore") in coco.py

ppwwyyxx commented 4 years ago

As far as I know, the original official VOC dataset does not have "ignore" annotation. I guess they may correspond to the "difficult" annotations in VOC.

So I would not recommend using these json files for serious purposes.

SkeletonOne commented 4 years ago

@ppwwyyxx Yeah thanks for your reply. You know, I searched for some other scripts of making a COCO format json file for Pascal VOC dataset, and they all just added 'ignore' for it. So since I am just trying to figure out the detection results on Pascal VOC, I will just simply remove the 'ignore' label. Anyway, the visualization of the ground truth seems good. Thanks for your excellent work of Detectron2 again!