Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the problem of visualization and self-made dataset metadata setting #5341

Open
lelelelelelelelelelelelele opened this issue Aug 4, 2024 · 1 comment

Comments

@lelelelelelelelelelelelele
Copy link

lelelelelelelelelelelelele commented Aug 4, 2024

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 <module>
    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 <listcomp>
    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 #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).

@github-actions github-actions bot added the needs-more-info More info is needed to complete the issue label Aug 4, 2024
Copy link

github-actions bot commented Aug 4, 2024

You've chosen to report an unexpected problem or bug. Unless you already know the root cause of it, please include details about it by filling the issue template.
The following information is missing: "Instructions To Reproduce the Issue and Full Logs";

@github-actions github-actions bot removed the needs-more-info More info is needed to complete the issue label Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant