fanq15 / FewX

FewX is an open-source toolbox on top of Detectron2 for data-limited instance-level recognition tasks.
https://github.com/fanq15/FewX
MIT License
346 stars 48 forks source link

Apply model to new dataset #32

Open Chan-Sun opened 3 years ago

Chan-Sun commented 3 years ago

Hi~

I was trying to apply your fsod model to new dataset. But encounter some problems when registering dataset. I have read some documents about Detectron2, still got confused. So, would you be so kind to explain the dataset regestering procedure?

Thanks a lot.

malje16 commented 3 years ago

I have only ever registered a COCO dataset. I did it by finding the place where FewX registers its datasets, which seems to be the function: register_all_coco located in /fewx/data/datasets/builtin.py, and then adding the line: register_coco_instances('', {}, "", "")

Of course this requires your dataset to be in coco format. If you need a different format I suspect you will have to study the manual (https://detectron2.readthedocs.io/en/latest/tutorials/datasets.html), or perhaps ask the question over in the Detectron2 git.

Mas-Y commented 3 years ago

I have only ever registered a COCO dataset. I did it by finding the place where FewX registers its datasets, which seems to be the function: register_all_coco located in /fewx/data/datasets/builtin.py, and then adding the line: register_coco_instances('', {}, "", "")

Of course this requires your dataset to be in coco format. If you need a different format I suspect you will have to study the manual (https://detectron2.readthedocs.io/en/latest/tutorials/datasets.html), or perhaps ask the question over in the Detectron2 git.

Have registered full coco dataset or a subset? I am trying to register a subset of coco with only two classes. I am getting issues while training. Can you please let me know what is the procedure you followed.

malje16 commented 3 years ago

Have registered full coco dataset or a subset? I am trying to register a subset of coco with only two classes. I am getting issues while training. Can you please let me know what is the procedure you followed.

Some of the text didn't show in my original comment. I have edited it. Anyhow, in the naive method i outlined it doesn't matter for the registration if you have the full coco or a subset. All you need is a (valid) coco annotation json file and a directory with the corresponding images. But if your issues are during training I don't think it has anything to do with registration. Detectron2 will straight up tell you if you tried to load a dataset in your config that isn't registered.

Mas-Y commented 3 years ago

@Chan-Sun @malje16 Have you tried Training on new dataset? I tried to train on a subset of coco with only two classes. I am getting following error. If you have any idea around it. Can you please let me resolve the issue?

-- Process 1 terminated with the following error: Traceback (most recent call last): File "/root/anaconda3/envs/fsod_36/lib/python3.6/site-packages/torch/multiprocessing/spawn.py", line 20, in _wrap fn(i, args) File "/root/anaconda3/envs/fsod_36/lib/python3.6/site-packages/detectron2/engine/launch.py", line 94, in _distributed_worker main_func(args) File "/root/lab/MY_FSOD/FewX_copy/FewX/fsod_train_net.py", line 104, in main trainer = Trainer(cfg) File "/root/anaconda3/envs/fsod_36/lib/python3.6/site-packages/detectron2/engine/defaults.py", line 284, in init data_loader = self.build_train_loader(cfg) File "/root/lab/MY_FSOD/FewX_copy/FewX/fsod_train_net.py", line 47, in build_train_loader mapper = DatasetMapperWithSupport(cfg) File "/root/lab/MY_FSOD/FewX_copy/FewX/fewx/data/dataset_mapper.py", line 85, in init self.support_df['category_id'] = self.support_df['category_id'].map(reverse_id_mapper) File "/root/anaconda3/envs/fsod_36/lib/python3.6/site-packages/pandas/core/series.py", line 3983, in map new_values = super()._map_values(arg, na_action=na_action) File "/root/anaconda3/envs/fsod_36/lib/python3.6/site-packages/pandas/core/base.py", line 1160, in _map_values new_values = map_f(values, mapper) File "pandas/_libs/lib.pyx", line 2403, in pandas._libs.lib.map_infer File "/root/lab/MY_FSOD/FewX_copy/FewX/fewx/data/dataset_mapper.py", line 84, in reverse_id_mapper = lambda dataset_id: metadata.thing_dataset_id_to_contiguous_id[dataset_id] # noqa KeyError: 0

w39865008 commented 3 years ago

@Mas-Y I meet the same issue. Can you tell me how to solve it?

pranay-ar commented 2 years ago

@Mas-Y and @w39865008, were you both able to solve this error? I am experiencing the same error too.

tailororrr commented 2 years ago

I also meet the same issue.

lucienwang1009 commented 2 years ago

Solved by commenting out the metadata at https://github.com/fanq15/FewX/blob/cfa6033142a5315a0a0855b3b35c9d4f777a8eca/fewx/data/datasets/register_coco.py#L39-L41

      DatasetCatalog.get(name)
      MetadataCatalog.get(name).set(
          json_file=json_file, image_root=image_root, evaluator_type="coco",  # **metadata
      )

The added DatasetCatalog.get(name) kicks off load_coco_json to generate a MetadataCatalog for the custom dataset.

Hope it will be helpful :-). My env: detectron2 0.6 cudatoolkit 11.3.1 pytorch 1.11.0