facebookresearch / facebookresearch/detectron2
the problem of visualization and self-made dataset metadata setting
- Dominant language
- Python
- Stars
- 34.7k
- Forks
- 7.9k
- PR merge metrics
- No merged PRs in 30d
Description
## Instructions To Reproduce the 🐛 Bug:
### description:
I wanna split the origin dataset (coco json format) to train and test parts.
Therefore, I compared 2 methods by `register_coco_instance` and `load_coco_json`, and get the dicts respectively.
```
register_coco_instances("my_dataset", {}, "./dataset/annotations/train_test2017.json", "./dataset/JPEGImages")
a = DatasetCatalog.get("my_dataset")
# or
metadata = MetadataCatalog.get("my_dataset").set(
thing_classes = ["ship"],
thing_dataset_id_to_contiguous_id = {1: 0},
json_file=json_path,
image_root=img_path,
evaluator_type='coco',
)
a = load_coco_json(json_path, img_path)
DatasetCatalog.register("my_dataset", lambda: a)
```
both of which follow the tutorials.
**however**, it faced issue when implementing visualization code:
`visualizer = Visualizer(img[:, :, ::-1], metadata=metadata, scale=0.5, instance_mode=ColorMode.IMAGE_BW)`
`out = visualizer.draw_dataset_dict(d)`
### problem / log
what is weird is that method 1 went smoothly yet method 2 went wrong and shows
```
File "h:\github\training\self_dataload.py", line 56, in
out = visualizer.draw_dataset_dict(d)
File "h:\github\detectron2\detectron2\utils\visualizer.py", line 589, in draw_dataset_dict
labels = _create_text_labels(
File "h:\github\detectron2\detectron2\utils\visualizer.py", line 244, in _create_text_labels
labels = [class_names[i] for i in classes]
File "h:\github\detectron2\detectron2\utils\visualizer.py", line 244, in
labels = [class_names[i] for i in classes]
IndexError: list index out of range
```
## Environment:
common windows environment
python 3.10
## solution:
I faced the same question with https://github.com/facebookresearch/detectron2/issues/546
I check the source code and debug it. It turned out that the IDs of my categories started at 1 and not as expected at 0.
The problem should be solved by setting an internal parameter `thing_dataset_id_to_contiguous_id` in the metadata of the dataset. However, during my debugging, no matter how I set the parameter by `metadata = MetadataCatalog.get("my_dataset").set()`, the visualizer cant solve the mapping. I also try to register by `a = load_coco_json(json_path, img_path, "my_dataset_1")`(very similar to method 2 but register automatically and i cant filter or change the dataset manually), in that case, even i dont set the metadata, The visualizer can understand the mapping and shows the image.
Above all, I deduce that self-setting metadata in coco format cant be understood by function *visualizer.draw_dataset_dict(d)*, or even worse by the trainer( i haven't check but since the `register_coco_instance` works well, I doubt if the self-setting metadata works at all).
Contributor guide
Assessment
This issue has not been assessed yet.