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

Allow "tiff" and more extensions in DetectionDataset.from_yolo function #1636

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

patel-zeel
Copy link
Contributor

@patel-zeel patel-zeel commented Oct 31, 2024

Description

Addresses #1554 as discussed with @LinasKo.

Highlights

  • Allows any image extension in DetectionDataset.from_yolo.
    Tested extensions (listed on Ultralytics predict page):
    • bmp
    • jpg
    • mpo
    • png
    • tif
    • webp
    • pfm - Pillow could not read pfm images, cv2 is able to read them. I saw here that even Ultralytics uses Pillow to read images. In that case, I am not sure if Ultralytics can "really" support pfm format, as their documentation suggests.
    • dng
  • Image must be of "RGB" type, raise ValueError otherwise.

List any dependencies that are required for this change.

  • Pillow

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How has this change been tested, please provide a testcase or example of how you tested the change?

The changes are tested with this colab notebook.

Test Case

100 images of each extension were generated along with their corresponding dummy labels and dummy data.yml. Test run checks if the function works for a particular extension and computes time taken to load the dataset.

Time taken (in seconds) to run the test case

  • Columns 0,1,2,3,4 are seed numbers.
  • -1.11 value indicates that supervision doesn't support that extension yet.

Result for supervision version 0.24.0, which uses cv2 to check the shape of images.

0 1 2 3 4 Mean Std
bmp -1.11 -1.11 -1.11 -1.11 -1.11 -1.11 0.00
jpg 0.98 1.16 0.85 0.76 0.77 0.90 0.15
mpo -1.11 -1.11 -1.11 -1.11 -1.11 -1.11 0.00
png 0.58 0.56 0.42 0.4 0.41 0.48 0.08
tif -1.11 -1.11 -1.11 -1.11 -1.11 -1.11 0.00
webp -1.11 -1.11 -1.11 -1.11 -1.11 -1.11 0.00
dng -1.11 -1.11 -1.11 -1.11 -1.11 -1.11 0.00

Result for this PR, which uses Pillow to check the shape and type (RGB or not) of images.

0 1 2 3 4 Mean Std
bmp 0.04 0.02 0.02 0.02 0.03 0.03 0.01
jpg 0.03 0.02 0.03 0.02 0.02 0.03 0.00
mpo 0.04 0.04 0.06 0.04 0.04 0.04 0.01
png 0.02 0.02 0.04 0.02 0.02 0.02 0.01
tif 0.05 0.06 0.08 0.05 0.05 0.06 0.01
webp 0.10 0.11 0.11 0.09 0.11 0.10 0.00
dng 0.06 0.06 0.05 0.06 0.06 0.06 0.00

Docs

  • Docs updated? What were the changes: Not changed, please suggest if we need changes in the docs

@LinasKo
Copy link
Contributor

LinasKo commented Oct 31, 2024

You never cease to surprise, @patel-zeel; such a thorough analysis! ⭐

Adding this to the back of my review backlog, but I already know it will be a delight.

@LinasKo LinasKo added the hacktoberfest-accepted Contribute to the notion of open-source this October! label Oct 31, 2024
@patel-zeel
Copy link
Contributor Author

Thank you for your kind words, @LinasKo. It's a pleasure to help improve a widely used library. Looking forward to your feedback!

@patel-zeel
Copy link
Contributor Author

patel-zeel commented Dec 31, 2024

@LinasKo a small correction. I recently found that Ultralytics uses this function to read pfm and other image files during yolo predict call. It uses cv2 and not Pillow. So, I was able to process pfm images with Ultralytics. However, the fact remains that Pillow does not support colored pfm images. This PR added greyscale pfm support in Pillow and it points to this issue for not supporting colored pfm images. The issue is pinned on Pillow since May 2016 and thus, looks like it is not going to be resolved in the near future. However, unless pfm format dominates some domains, we are not bottlenecked by it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Contribute to the notion of open-source this October!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants