roboflow-python
roboflow-python copied to clipboard
fix: support case-insensitive images/labels folders in YOLO datasets
Description
Fix case-sensitive matching issue in YOLO dataset folder parsing. The current implementation only supports lowercase images and labels folders, causing annotation matching to fail when using capitalized folder names like Images and Labels.
Changes
- Modified
_describe_file()inroboflow/util/folderparser.pyto use case-insensitive regex replacement instead of hardcoded lowercase string matching - Now supports any case variation:
images,Images,IMAGES,labels,Labels,LABELS, etc.
Problem
When uploading YOLO format datasets with capitalized folder names (e.g., Train/Images and Train/Labels), the annotation files were not being matched to their corresponding images. This is because the fullkey2 generation used case-sensitive string replacement:
# Before (case-sensitive)
fullkey2 = fullkey.replace("/labels", "").replace("/images", "")
For a path like /Train/Images/image.jpg, the replacement would not match, causing fullkey2 to remain as /train/images/image instead of the expected /train/image.
Solution
Use re.sub() with re.IGNORECASE flag:
# After (case-insensitive)
fullkey2 = re.sub(r"/labels", "", fullkey, flags=re.IGNORECASE)
fullkey2 = re.sub(r"/images", "", fullkey2, flags=re.IGNORECASE)
Testing
Verified that:
- Images with annotations in capitalized folders (
Images/Labels) are now correctly matched - Existing lowercase folder structures continue to work as before
- Upload process shows
annotations = OKfor all images
Related Issues
Fixes the issue where YOLO datasets with non-lowercase folder names fail to upload annotations.