ucbdrive / few-shot-object-detection

Implementations of few-shot object detection benchmarks
Apache License 2.0
1.1k stars 223 forks source link

Update model_zoo.py #97

Closed scott-vsi closed 2 years ago

scott-vsi commented 3 years ago

As suggested in MODEL_ZOO.md, I tried running

from fsdet import model_zoo
model = model_zoo.get(
   "COCO-detection/faster_rcnn_R_101_FPN_ft_all_1shot.yaml", trained=True)

However, that resulted in this error:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/src/few-shot-object-detection/fsdet/model_zoo/model_zoo.py", line 176, in get
    cfg.merge_from_file(cfg_file)
  File "/venv/lib/python3.7/site-packages/detectron2/config/config.py", line 54, in merge_from_file
    self.merge_from_other_cfg(loaded_cfg)
  File "/venv/lib/python3.7/site-packages/fvcore/common/config.py", line 123, in merge_from_other_cfg
    return super().merge_from_other_cfg(cfg_other)
  File "/venv/lib/python3.7/site-packages/yacs/config.py", line 217, in merge_from_other_cfg
    _merge_a_into_b(cfg_other, self, self, [])
  File "/venv/lib/python3.7/site-packages/yacs/config.py", line 478, in _merge_a_into_b
    _merge_a_into_b(v, b[k], root, key_list + [k])
  File "/venv/lib/python3.7/site-packages/yacs/config.py", line 478, in _merge_a_into_b
    _merge_a_into_b(v, b[k], root, key_list + [k])
  File "/venv/lib/python3.7/site-packages/yacs/config.py", line 491, in _merge_a_into_b
    raise KeyError("Non-existent config key: {}".format(full_key))
KeyError: 'Non-existent config key: MODEL.BACKBONE.FREEZE'

In 884c17f ("remove detectron2 dependencies") fsdet/config/config.py was removed and this was changed from fsdet.config to detectron2.config. However, fsdet/config/config.py was then added back in 3cab324 ("more updates") and this file was never updated to match. fsdet/config/config.py imports fsdet/config/default.py, which defines MODEL.BACKBONE.FREEZE, which resolves this problem.

scott-vsi commented 3 years ago

It turns out, I also had to change the path computed by model_zoo/model_zoo.py:get_config_file before I could get the model to download. Even then, I still cannot run the demo using an fsdet:// path.

scott-vsi commented 3 years ago

However, if I switch to the model_zoo branch and apply these changes then I can get the model and run the demo.

EDIT However, I cannot run training.

scott-vsi commented 3 years ago

The path change in model_zoo/model_zoo.py:get_config_file (model_zoo.py is based on the same file in detectron2) is necessary because fsdet does not symlink the configs into the model_zoo directory on install like detectron2 does. (It doesn't have a setup.py script at all). Consequently, the path is correct in the case of detectron2.

https://github.com/facebookresearch/detectron2/blob/v0.3/setup.py#L141-L142

scott-vsi commented 3 years ago

Just to close the loop, it appears that in fsdet v0.1, there was a setup.py file (like detectron2) that copied the configs directory into the model_zoo.

scott-vsi commented 3 years ago

By using an older version of fvcore (along with this patch), I am now able to get a model, run the demo and run training on the master branch (6b0769b).

detectron2 v0.2.1 depends on fvcore>=0.1.1. However, fsdet expects fvcore:fvcore/common/checkpoint.py to import PathManager from fvcore.common.file_io, not iopath.common.file_io because fsdet registers a path handler (in fsdet/checkpoint/catalog.py:PathManager.register_handler) on fvcore.common.file_io.PathManager (as does the detectron2 package). However, this changed in 813a225. As such, we must use an fvcore release prior to 813a225 (there are no releases on github, but pypi has a ton. I used fvcore==0.1.2.post20201213)

EDIT Once the model_zoo branch gets merged in, the latest fvcore (0.1.3.post20210317) will work; however, the detectron2 dependency will need to be changed from 0.2.1 to >v0.4

thomasehuang commented 2 years ago

Thanks for the detailed fix! I double checked the issue you mentioned and indeed you are right. Will merge your changes and make further fixes based on that.