SysCV / shift-detection-tta

This repository implements continuous test-time adaptation algorithms for object detection on the SHIFT dataset.
MIT License
18 stars 3 forks source link

KeyError: 'categories' #2

Closed YuyangSunshine closed 1 year ago

YuyangSunshine commented 1 year ago

Some errors happened during validatting the source model on the validation set of the continuous target domain.

I tried to modify the attribute ('category' -> 'categories') in the _det_2dcocoformat.json (there is no corresponding file in the provided datasets.), but it still didn't work.

  1. May I know the true annotaion file for val data?
  2. Do you know how to fix this problem?

Traceback (most recent call last): File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 122, in build_from_cfg obj = obj_cls(args) # type: ignore File "/data/users/yliu/workspace/TTA/shift-detection-tta/shift_tta/datasets/shift_dataset.py", line 31, in init super().init(*args, *kwargs) File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmtrack/datasets/base_video_dataset.py", line 54, in init super().init(args, kwargs) File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmengine/dataset/base_dataset.py", line 245, in init self.full_init() File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmtrack/datasets/base_video_dataset.py", line 78, in full_init self.data_list, self.valid_data_indices = self.load_data_list() File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmtrack/datasets/base_video_dataset.py", line 98, in load_data_list data_list, valid_data_indices = self._load_video_data_list() File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmtrack/datasets/base_video_dataset.py", line 117, in _load_video_data_list self.cat_ids = coco.get_cat_ids(cat_names=self.metainfo['CLASSES']) File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmdet/datasets/api_wrappers/coco_api.py", line 33, in get_cat_ids return self.getCatIds(cat_names, sup_names, cat_ids) File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/pycocotools/coco.py", line 170, in getCatIds cats = self.dataset['categories'] KeyError: 'categories'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 122, in build_from_cfg obj = obj_cls(*args) # type: ignore File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmengine/runner/loops.py", line 410, in init super().init(runner, dataloader) File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmengine/runner/base_loop.py", line 26, in init self.dataloader = runner.build_dataloader( File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmengine/runner/runner.py", line 1346, in build_dataloader dataset = DATASETS.build(dataset_cfg) File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmengine/registry/registry.py", line 548, in build return self.build_func(cfg, args, **kwargs, registry=self) File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 144, in build_from_cfg raise type(e)( KeyError: "class SHIFTDataset in shift_tta/datasets/shift_dataset.py: 'categories'"

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/data/users/yliu/workspace/TTA/shift-detection-tta/tools/test.py", line 88, in main() File "/data/users/yliu/workspace/TTA/shift-detection-tta/tools/test.py", line 84, in main runner.test() File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmengine/runner/runner.py", line 1760, in test self._test_loop = self.build_test_loop(self._test_loop) # type: ignore File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmengine/runner/runner.py", line 1563, in build_test_loop loop = LOOPS.build( File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmengine/registry/registry.py", line 548, in build return self.build_func(cfg, *args, **kwargs, registry=self) File "/data/users/yliu/soft/anaconda3/envs/shift-tta/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 144, in build_from_cfg raise type(e)( KeyError: 'class TestLoop in mmengine/runner/loops.py: "class SHIFTDataset in shift_tta/datasets/shift_dataset.py: \'categories\'"'

mattiasegu commented 1 year ago

Hi @YuyangSunshine, it seems that you are using the original annotation files and not processing them to convert them to coco format.

Please refer to dataset_prepare.md for instructions on how to download and prepare the SHIFT dataset.

Hope this helps!

YuyangSunshine commented 1 year ago

Thanks a lot! I will try to fix it by your suggestion.

mattiasegu commented 1 year ago

No problem, please let me know if it works!

YuyangSunshine commented 1 year ago

After fixing the docker image, I met a new problem when I run docker run -v ../data/shift/continuous/videos/1x/val/front/img.tar -e MODE=hdf5 shift_dataset_decompress

Traceback (most recent call last): File "/usr/local/lib/python3.8/runpy.py", line 185, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/usr/local/lib/python3.8/runpy.py", line 111, in _get_module_details import(pkg_name) File "/usr/src/app/shift_dev/init.py", line 1, in from .dataloader.shift_dataset import SHIFTDataset File "/usr/src/app/shift_dev/dataloader/shift_dataset.py", line 14, in from scalabel.label.io import parse File "/usr/local/lib/python3.8/site-packages/scalabel/init.py", line 3, in from . import bot, label, tools File "/usr/local/lib/python3.8/site-packages/scalabel/label/init.py", line 3, in from . import coco_typing, from_coco, io, to_coco, typing File "/usr/local/lib/python3.8/site-packages/scalabel/label/from_coco.py", line 9, in from ..common.io import open_read_text File "/usr/local/lib/python3.8/site-packages/scalabel/common/io.py", line 10, in from .typing import DictStrAny File "/usr/local/lib/python3.8/site-packages/scalabel/common/typing.py", line 10, in NDArrayF64 = npt.NDArray[np.float64] AttributeError: module 'numpy.typing' has no attribute 'NDArray'

mattiasegu commented 1 year ago

That seems like a problem with the numpy version and scalabel version.

Did you build the docker with the following command?

docker build -t shift_dataset_decompress .

Also, please change the mode to .tar:

# run the container (the mode is set to "tar")
docker run -v <path/to/data>:/data -e MODE=tar shift_dataset_decompress
YuyangSunshine commented 1 year ago

Yes, I used the corresponding command to build the docker.

I have chenge the mode as .tar, but it still have the same problem.

mattiasegu commented 1 year ago

Okay, thanks for the reply. We are working on it, scalabel recently applied their requirements and created some incompatibility with the shift-dev repo.

I'll update this issue as soon as it's solved.

YuyangSunshine commented 1 year ago

Okay, thanks for the reply. We are working on it, scalabel recently applied their requirements and created some incompatibility with the shift-dev repo.

I'll update this issue as soon as it's solved.

Thank you! If you solve this problem, please let me know.

mattiasegu commented 1 year ago

https://github.com/SysCV/shift-dev/pull/61

Please have a look at the following PR, which should address your problem. Let me know if it works.

YuyangSunshine commented 1 year ago

Following your suggestion, I successfully address the docker problem.

But when I run:

docker run -v /data/**/*.tar -e MODE=tar shift_dataset_decompress It will occuer this problem:

[07/03/2023 10:56:36] SHIFT DevKit - INFO - Files to convert: 1
[07/03/2023 10:56:36] SHIFT DevKit - INFO - Starting conversion to tar
[07/03/2023 10:56:36] SHIFT DevKit - INFO - Note: You can also run this code using multi-processing by setting `-j` option.
[07/03/2023 10:56:36] SHIFT DevKit - INFO - Processing /data/**/*.tar
 Traceback (most recent call last):
   File "/usr/src/app/shift_dev/io/decompress_videos.py", line 70, in convert_to_archive
     tar_file = TarArchiveReader(tar_filepath)
   File "/usr/src/app/shift_dev/utils/storage.py", line 76, in __init__
     self.file = tarfile.TarFile(filename, "r")
   File "/usr/local/lib/python3.8/tarfile.py", line 1639, in __init__
    fileobj = bltn_open(name, self._mode)
 IsADirectoryError: [Errno 21] Is a directory: '/data/**/*.tar'

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "/usr/local/lib/python3.8/runpy.py", line 194, in _run_module_as_main
     return _run_code(code, main_globals, None,
   File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
   File "/usr/src/app/shift_dev/io/decompress_videos.py", line 224, in <module>
     main()
   File "/usr/src/app/shift_dev/io/decompress_videos.py", line 219, in main
     convert(f, args.tmp_dir, show_progress_bar=True)
  File "/usr/src/app/shift_dev/io/decompress_videos.py", line 72, in convert_to_archive
    logger.error("Cannot open {}. ".format(tar_filepath) + e)
TypeError: can only concatenate str (not "IsADirectoryError") to str

Or I run:

docker`` run -v "../data" -e MODE=tarshift_dataset_decompress` or

docker`` run -v ../data -e MODE=tarshift_dataset_decompress`

It will output:


[07/03/2023 10:47:03] SHIFT DevKit - INFO - Files to convert: 0
[07/03/2023 10:47:03] SHIFT DevKit - INFO - Starting conversion to tar
[07/03/2023 10:47:03] SHIFT DevKit - INFO - Note: You can also run this code using multi-processing by setting `-j` option.
mattiasegu commented 1 year ago

According to the documentation, this is the command that you should run:

docker run -v <path/to/data>:/data -e MODE=tar shift_dataset_decompress

If your data directory is at ../data, this means that you should run the following command:

docker run -v ../data/**/*.tar:/data -e MODE=tar shift_dataset_decompress

Please let me know if this solves your issue!

YuyangSunshine commented 1 year ago

Okay, I solved this error now. Thanks. :^~^: