Skip to content

Fix FsDet category names data type

Najam Syed requested to merge fix_fsdet_cats into master

In FsDet ObjectDetectionAlgorithm.initialize, the category names for a dataset are assigned to the relevant dataset attribute of the detectron2 MetadataCatalog. If the data type of the category names is int, an exception occurs in detectron2.data.build.print_instances_class_histogram, as it calls a nested function that expects str category names. This MR updates the algorithm initialize method to ensure category names are converted to str.

The sample traceback below shows the error encountered if category names are not converted to str from int:

Traceback (most recent call last):
  File "/data/najam.syed/learn/learn/learn/protocol/learn_protocol.py", line 88, in run_protocol
    self.run_task(task)
  File "/data/najam.syed/learn/learn/learn/protocol/learn_protocol.py", line 175, in run_task
    adapt_algo.execute(toolset, "DomainAdaptTraining")
  File "/data/najam.syed/learn/learn/learn/algorithms/FsDet/objectDetectionAdapter.py", line 16, in execute
    return self.domain_adapt_training()
  File "/data/najam.syed/learn/learn/learn/algorithms/FsDet/object_detection.py", line 274, in domain_adapt_training
    os.makedirs(self.cfg.OUTPUT_DIR, exist_ok=True)
  File "/home/local/KHQ/najam.syed/miniconda3/envs/learn/lib/python3.7/site-packages/detectron2/engine/defaults.py", line 379, in __init__
    data_loader = self.build_train_loader(cfg)
  File "/home/local/KHQ/najam.syed/miniconda3/envs/learn/lib/python3.7/site-packages/detectron2/engine/defaults.py", line 539, in build_train_loader
    return build_detection_train_loader(cfg)
  File "/home/local/KHQ/najam.syed/miniconda3/envs/learn/lib/python3.7/site-packages/detectron2/config/config.py", line 192, in wrapped
    explicit_args = _get_args_from_config(from_config, *args, **kwargs)
  File "/home/local/KHQ/najam.syed/miniconda3/envs/learn/lib/python3.7/site-packages/detectron2/config/config.py", line 229, in _get_args_from_config
    ret = from_config_func(*args, **kwargs)
  File "/home/local/KHQ/najam.syed/miniconda3/envs/learn/lib/python3.7/site-packages/detectron2/data/build.py", line 317, in _train_loader_from_config
    proposal_files=cfg.DATASETS.PROPOSAL_FILES_TRAIN if cfg.MODEL.LOAD_PROPOSALS else None,
  File "/home/local/KHQ/najam.syed/miniconda3/envs/learn/lib/python3.7/site-packages/detectron2/data/build.py", line 250, in get_detection_dataset_dicts
    class_names = MetadataCatalog.get(names[0]).thing_classes
  File "/home/local/KHQ/najam.syed/miniconda3/envs/learn/lib/python3.7/site-packages/detectron2/data/build.py", line 187, in print_instances_class_histogram
    itertools.chain(*[[short_name(class_names[i]), int(v)] for i, v in enumerate(histogram)])
  File "/home/local/KHQ/najam.syed/miniconda3/envs/learn/lib/python3.7/site-packages/detectron2/data/build.py", line 187, in <listcomp>
    itertools.chain(*[[short_name(class_names[i]), int(v)] for i, v in enumerate(histogram)])
  File "/home/local/KHQ/najam.syed/miniconda3/envs/learn/lib/python3.7/site-packages/detectron2/data/build.py", line 182, in short_name
    if len(x) > 13:
TypeError: object of type 'int' has no len()

Merge request reports

Loading