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

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

Closed agp-ka32 closed 4 years ago

agp-ka32 commented 4 years ago

❓ 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.

ppwwyyxx commented 4 years ago

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

agp-ka32 commented 4 years ago

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.

agp-ka32 commented 4 years ago

@ppwwyyxx Could you help with this issue? Thanks.

ppwwyyxx commented 4 years ago

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

agp-ka32 commented 4 years ago

Thank you!

zsc1220 commented 4 years ago

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

ppwwyyxx commented 4 years ago

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.

zsc1220 commented 4 years ago

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 !

ppwwyyxx commented 4 years ago

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

zsc1220 commented 4 years ago

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

sameer00123 commented 4 years ago

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,

Adblu commented 4 years ago

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

ppwwyyxx commented 4 years ago

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.

AderonHuang commented 4 years ago

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

AderonHuang commented 4 years ago

@ppwwyyxx

ppwwyyxx commented 4 years ago

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

zhanghang1989 commented 3 years ago

I also encountered this issue. I found that the main reason is Metadata doesn't allow reassigning existing attrs to different values.

https://github.com/facebookresearch/detectron2/blob/master/detectron2/data/catalog.py#L146-L153

This can be resolved using monkey patch to overwrite this method.

d12306 commented 3 years ago

@zhanghang1989 , could you please show us a line of code to do this monkey patch?

Thanks,

zhanghang1989 commented 3 years ago

@zhanghang1989 , could you please show us a line of code to do this monkey patch?

Thanks,

You may create a new function as a monkey patch and then call that function. something like:

def hardsetpatch(self, key, val):
    super().__setattr__(key, val)

Metadata.hardset = hardsetpatch
Metadata.hardset(key, val)
john2020-210 commented 3 years ago

@akshaygadipatil I met the same problem,how could you sovle it?

john2020-210 commented 3 years ago

@12306,could you solve the problem?

PoloZuohui commented 3 years ago

@zhanghang1989 , could you please show us a line of code to do this monkey patch? Thanks,

You may create a new function as a monkey patch and then call that function. something like:

def hardsetpatch(self, key, val):
    super().__setattr__(key, val)

Metadata.hardset = hardsetpatch
Metadata.hardset(key, val)

where to put these lines? in the catalog.py? please show us specifically, thanks a lot. did you solve the problem? @zhanghang1989 and how? I met the same problem.

PoloZuohui commented 3 years ago

@d12306

zhanghang1989 commented 3 years ago

@zhanghang1989 , could you please show us a line of code to do this monkey patch? Thanks,

You may create a new function as a monkey patch and then call that function. something like:

def hardsetpatch(self, key, val):
    super().__setattr__(key, val)

Metadata.hardset = hardsetpatch
Metadata.hardset(key, val)

where to put these lines? in the catalog.py? please show us specifically, thanks a lot. did you solve the problem? @zhanghang1989 and how? I met the same problem.

Put it where you would like to reset some attributes.