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

Cannot load COCO dataset, when there are images without annotations #188

Closed
2 tasks done
lincoln2491 opened this issue Jul 12, 2023 · 10 comments
Closed
2 tasks done
Assignees
Labels
bug Something isn't working version: 0.12.0 Feature to be added in `0.12.0` release

Comments

@lincoln2491
Copy link

Search before asking

  • I have searched the Supervision issues and found no similar bug report.

Bug

I have a dataset (downloaded from roboflow) in COCO format. I tried to load using

dataset = sv.DetectionDataset.from_coco("dataset", "dataset/_annotations.coco.json")

but this throws an error:

/home/ks/projekty/bugs/venv/bin/python /home/ks/projekty/bugs/supervision_bug/test.py 
Traceback (most recent call last):
  File "/home/ks/projekty/bugs/supervision_bug/test.py", line 3, in <module>
    dataset = sv.DetectionDataset.from_coco("dataset", "dataset/_annotations.coco.json")
  File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/supervision/dataset/core.py", line 399, in from_coco
    classes, images, annotations = load_coco_annotations(
  File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/supervision/dataset/formats/coco.py", line 168, in load_coco_annotations
    annotation = map_detections_class_id(
  File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/supervision/dataset/utils.py", line 86, in map_detections_class_id
    detections_copy.class_id = np.vectorize(source_to_target_mapping.get)(
  File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/numpy/lib/function_base.py", line 2372, in __call__
    return self._call_as_normal(*args, **kwargs)
  File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/numpy/lib/function_base.py", line 2365, in _call_as_normal
    return self._vectorize_call(func=func, args=vargs)
  File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/numpy/lib/function_base.py", line 2450, in _vectorize_call
    ufunc, otypes = self._get_ufunc_and_otypes(func=func, args=args)
  File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/numpy/lib/function_base.py", line 2406, in _get_ufunc_and_otypes
    raise ValueError('cannot call `vectorize` on size 0 inputs '
ValueError: cannot call `vectorize` on size 0 inputs unless `otypes` is set

Process finished with exit code 1

has
I investigated what's going wrong and it turns out, that one of the images had no annotations.

This problem not occurs when datasets is in YOLO format and use from_yolo method.

I check out that changing lines from 86 to 88 in supervision.dataset.utils from

    detections_copy.class_id = np.vectorize(source_to_target_mapping.get)(
        detections_copy.class_id
    )

to

    detections_copy.class_id = np.vectorize(source_to_target_mapping.get)(
        detections_copy.class_id, otypes='int'
    )

will help with this issue.

Environment

  • OS
  • python 3.10.12
  • supervision from commit abbde887dc380b0abd8065c21ebe10cf20efb2a2
  • other packages:
    contourpy 1.1.0
    cycler 0.11.0
    fonttools 4.40.0
    kiwisolver 1.4.4
    matplotlib 3.7.2
    numpy 1.25.1
    opencv-python 4.8.0.74
    packaging 23.1
    Pillow 10.0.0
    pip 22.3.1
    pyparsing 3.0.9
    python-dateutil 2.8.2
    PyYAML 6.0
    setuptools 65.5.1
    six 1.16.0
    supervision 0.11.1
    wheel 0.38.4

Minimal Reproducible Example

supervision_bug.zip

I made an example with a toy dataset to reproduce bug. Just run test.py. There are no annotations for image 1.jpg

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@lincoln2491 lincoln2491 added the bug Something isn't working label Jul 12, 2023
@github-actions
Copy link
Contributor

Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap.

@wwzeng1
Copy link

wwzeng1 commented Jul 12, 2023

Hi! I’m one of the founders of Sweep, a github app that solves issues(like this bug) by writing pull requests.
This looks like a good issue for Sweep https://github.com/sweepai/sweep to try. We have onboarding instructions here, I’m also happy to help you onboard directly :)

@hardikdava
Copy link
Collaborator

@lincoln2491 Thanks for reporting bug. We will try to fix it.

@hardikdava
Copy link
Collaborator

@lincoln2491 I was able to reproduce the bug. But your dataset seems to have some issue. But I managed to test it with other dataset. I made a PR.

@lincoln2491
Copy link
Author

@hardikdava Thanks for help.

What do you mean by dataset have some issue?

@SkalskiP
Copy link
Collaborator

Hi @lincoln2491 👋🏻 Thanks for reporting the bug. I just took a look at @hardikdava PR, and it looks good. We will merge it to master in a few minutes. I believe it should solve your issue.

Remember that fix won't be accessible via pip install until the next release. However, you can run it with from source installation.

dataset have some issue

What @hardikdava meant is that your dataset contains images with no labels assigned.

@SkalskiP SkalskiP added the version: 0.12.0 Feature to be added in `0.12.0` release label Jul 14, 2023
@SkalskiP
Copy link
Collaborator

@wwzeng1 This issue is already solved. The app looks amazing. I'm happy to test it with another one.

@SkalskiP
Copy link
Collaborator

#192 merged! Closing the issue for now. @lincoln2491 feel free to reopen it if you will face more similar problems.

@lincoln2491
Copy link
Author

@SkalskiP @hardikdava Hi, thanks for your help guys.

@wwzeng1
Copy link

wwzeng1 commented Jul 14, 2023

@SkalskiP Gotcha, thanks for the heads up! Again, happy to help with anything :)

@SkalskiP SkalskiP added this to the version: 0.12.0 milestone Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working version: 0.12.0 Feature to be added in `0.12.0` release
Projects
Archived in project
Development

No branches or pull requests

4 participants