Detectron2: AssertionError: Attribute 'thing_classes' in the metadata of 'coco_2017_train' cannot be set to a different value!

Created on 26 Oct 2019  ·  16Comments  ·  Source: facebookresearch/detectron2

❓ Questions and Help

Hi,
I am trying to train on my dataset with just 4 classes.
When I run it, I get an error as below:
image
The scripts are interlinked a lot and therefore a bit difficult to debug.
How to resolve this?

Thanks.

All 16 comments

Please include details about the problem following the issue template. It looks like you're setting datasets to "coco" instead of your own dataset.

Sure. Here are the details according to the [issue template]:(https://github.com/facebookresearch/detectron2/issues/new?template=unexpected-problems-bugs.md)


image

Reproduce:

1) I did not change any line of code.
2) I just created a folder named "coco" inside the "./datasets" directory and added the annotations and image files as required by detectron2. To be specific, the "annotations" subfolder contains instance_train2014 and instance_val2014 json files. And the "train2014" and "val2014" subfolders contain the respective image file names included in the json files.
3) The full log is as below:
image

Environment:

image

I do not know how to set the datasets to something else other than "coco".
Is it because of not changing the dataset name? If yes, how do I make this modification?

Please let me know if the above details are sufficient enough for my error to be understood. If not, let me know what other details are needed.

Thanks.

@ppwwyyxx Could you help with this issue? Thanks.

I just created a folder named "coco" inside the "./datasets" directory and added the annotations and image files as required by detectron2. To be specific, the "annotations" subfolder contains instance_train2014 and instance_val2014 json files. And the "train2014" and "val2014" subfolders contain the respective image file names included in the json files.

You are not allowed to do this. COCO is COCO. Please do not call other datasets "COCO" or put other datasets under the directory "COCO".

Please call register_coco_instances (https://detectron2.readthedocs.io/modules/data.html#detectron2.data.datasets.register_coco_instances) for other datasets that are in coco format. See more at https://detectron2.readthedocs.io/tutorials/datasets.html

Thank you!

HI @ppwwyyxx
Could you please tell me in which file to add the extra line of register_cooc_instances ? Thank you very much!!!

You can add it in any place (e.g., in your own train_net.py) as long as it will be executed before you create the data loader.

Hi @ppwwyyxx
Thank you so much ! I add the line in train_net.py , but it makes another error !!

:~/pythoncode/detectron2$ python tools/train_net.py --config-file configs/COCO-Detection/faster_rcnn_R_101_FPN_3x.yaml SOLVER.IMS_PER_BATCH 2 SOLVER.BASE_LR 0.0025
Traceback (most recent call last):
File "tools/train_net.py", line 155, in
register_coco_instances("coco_2014_train", {}, " datasets/coco/annotations/instances_train2014.json", "/home/xxx/data/datasets1/coco/train2014")
File "/home/xxx/pythoncode/detectron2/detectron2/data/datasets/register_coco.py", line 37, in register_coco_instances
json_file=json_file, image_root=image_root, evaluator_type="coco", **metadata
File "/home/xxx/pythoncode/detectron2/detectron2/data/catalog.py", line 154, in set
setattr(self, k, v)
File "/home/xxx/pythoncode/detectron2/detectron2/data/catalog.py", line 137, in __setattr__
"to a different value!n{} != {}".format(key, self.name, oldval, val)
AssertionError: Attribute 'json_file' in the metadata of 'coco_2014_train' cannot be set to a different value!
datasets/coco/annotations/instances_train2014.json != datasets/coco/annotations/instances_train2014.json

I really don't know how to modify it , Could you please take a look at it for me? Thank you so much !

You can not call your dataset "coco_2014_train" since it's used for coco.

Yes , it is works ! thank you a lot ! @ppwwyyxx

I did exactly the same as mentioned here but still getting the following issue:
AssertionError: Attribute 'thing_classes' in the metadata of 'coco_2017_train' cannot be set to a different value!
image

I have not changed anything in the code, just followed the same procedure mentioned here: create dataset - coco/annotations and coco/image-folders, registered the dataset by calling register_coco_instances into tools/train_net.py and used the same training command as used by @zsc1220.

One thing that I have noted is when I merely print the Json_file supplied to register_coco.py like this:
image

I see the output as:
image

Looks like it registers all the COCO datasets even when I just want my custom dataset to be registered.

Can somebody please point me to a solution to this?

Thanks,

I have the same problem. I have registered my own dataset:

 register_coco_instances("class_x", {}, "/home/user/a/datasets/coco/annotations/instances_train2017.json",
                                "/home/user/car/datasets/coco/train2017/")

and still Im getting:

AssertionError: Attribute 'thing_classes' in the metadata of 'coco_2017_train' cannot be set to a different value!
['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] != ['class_x']

Did somebody managed to solve it ? @sameer00123 @ppwwyyxx @zsc1220 @akshaygadipatil

Please do not call other datasets 'COCO' if they are not COCO.

If you need help to solve an unexpected issue you observed, please include details following the "Unexpected behaviors" issue template.

image
I alse met this problem,above methods did not work for me ,can you help me ?

@ppwwyyxx

If you need help to solve an unexpected issue you observed, please include details following the "Unexpected behaviors" issue template.

Was this page helpful?
0 / 5 - 0 ratings