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

Fix GIF Image Handling in Dataset Loader #171

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bibisbar
Copy link

@bibisbar bibisbar commented Feb 2, 2025

Fix GIF Image Handling in Dataset Loader

📝 Description

This PR improves the dataset image loading pipeline by adding support for GIF images and handling cases where the image file extension might be different than expected.

🔧 Changes

  • Added automatic fallback to check for alternative image formats (.jpg, .jpeg, .png, .bmp, .webp, .gif) if the expected file is missing.
  • Implemented proper handling for .gif images by converting the first frame to RGB mode to ensure compatibility.
  • Wrapped the image loading process with a with Image.open(...) statement for better resource management.

🐞 Problem

Previously, the dataset loader assumed all images were in a fixed format (e.g., .jpg), leading to FileNotFoundError when images were stored with different extensions. Additionally, GIF files were not handled correctly, causing unexpected errors.

✅ Solution

  • If the expected image file is missing, the code now iterates through possible extensions to locate the correct file.
  • When loading a GIF file, it automatically converts the first frame to RGB, preventing format-related issues.

📌 Related Issues

  • Fixes FileNotFoundError caused by missing or mismatched file extensions.
  • Resolves compatibility issues with .gif images.

🔬 Testing

  • Verified that images with different formats are correctly loaded.
  • Confirmed that GIF images no longer cause errors and are properly converted.

Let me know if any further improvements are needed! 🚀

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

Successfully merging this pull request may close these issues.

1 participant