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

DetectionDataset merge fails when class name contains capital letter #1641

Closed
2 tasks done
Suhas-G opened this issue Nov 1, 2024 · 5 comments · Fixed by #1643
Closed
2 tasks done

DetectionDataset merge fails when class name contains capital letter #1641

Suhas-G opened this issue Nov 1, 2024 · 5 comments · Fixed by #1643
Labels
bug Something isn't working

Comments

@Suhas-G
Copy link

Suhas-G commented Nov 1, 2024

Search before asking

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

Bug

Hello, thanks for this great library! I'm facing an issue while trying to merge 2 datasets when any of the class names contain a capital letter.

Error:

ValueError: Class Animal not found in target classes. source_classes must be a subset of target_classes.

The issue stems from the merge_class_lists function at

def merge_class_lists(class_lists: List[List[str]]) -> List[str]:

where the class names are converted to lower-case, but build_class_index_mapping keeps the class names as it is. For my use case, I was able to get around by removing the lower-case conversion.

Environment

  • Supervision 0.24.0
  • OS: Windows 10
  • Python 3.10.14

Minimal Reproducible Example

Example: I downloaded 2 roboflow datasets - https://universe.roboflow.com/cvlab-6un5p/cv-lab-kpdek and https://universe.roboflow.com/padidala-indhu-e1dhl/animals-gzsxr and tried to merge them

import supervision as sv


def main():
    ds1 = sv.DetectionDataset.from_coco("data/CV-LAB.v1i.coco/train", "data/CV-LAB.v1i.coco/train/_annotations.coco.json")
    ds2 = sv.DetectionDataset.from_coco("data/Animals.v1i.coco/train", "data/Animals.v1i.coco/train/_annotations.coco.json")

    sv.DetectionDataset.merge([ds1, ds2])


if __name__ == '__main__':
    main()

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@Suhas-G Suhas-G added the bug Something isn't working label Nov 1, 2024
@LinasKo
Copy link
Contributor

LinasKo commented Nov 1, 2024

Hi @Suhas-G 👋

We'd like to treat classes with different capitalization as different classes. That is, "Animal" and "animal" are different.

Right now I expect people to rename these manually inside Detections. However, adding a Detections.rename_class(from: str, to: str) and DetectionsDataset.rename_class(from: str, to: str) would be very useful!

@Suhas-G
Copy link
Author

Suhas-G commented Nov 1, 2024

Hi @LinasKo, to treat classes with different capitalization as different classes, isn't it better to not call .lower() in the merge function? That way the merged list will have "Animal" as a different class. Note that in this example, there is no "animal" class but only "Animal" which is converted to lower case in merged list, and so "Animal" is not found while building the index mapping.

@LinasKo
Copy link
Contributor

LinasKo commented Nov 1, 2024

Are we calling that? If so, I believe we can remove it.

@LinasKo
Copy link
Contributor

LinasKo commented Nov 1, 2024

Thanks @onuralpszr!

@Suhas-G, would you mind testing out whether it works this time? You can install the develop version of supervision like so:

pip install git+https://github.com/roboflow/supervision.git@develop

@Suhas-G
Copy link
Author

Suhas-G commented Nov 2, 2024

Yes, it's working fine. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants