feat(utils): add 'label_folder_name' to 'img2label_paths' function
-
Check for Existing Contributions β I have checked existing PRs and this contribution is unique.
-
Link Related Issues N/A. This PR is a proactive improvement to enhance function reusability and does not address a specific open issue.
-
Purpose of Change
- The existing img2label_paths function was not flexible because the label folder name was hardcoded as 'labels'. This made it difficult to reuse the function for datasets with different directory structures (e.g., annotations, yolo_txts).
- This change is very useful when you experiment with training a single set of images against several different sets of labels. (labels_with_A_scheme, labels_with_B_scheme, etc...)
- Description of Change
- Added a new parameter, label_folder_name, to the img2label_paths function.
- Specifying label_folder_name in the .yaml file sets the training label directory to be that folder, located alongside the images directory
- Set the default value to 'labels' to ensure backward compatibility, meaning existing code that uses this function will not break.
Modified the path string generation to use this new parameter dynamically.
π οΈ PR Summary
Made with β€οΈ by Ultralytics Actions
π Summary
Adds flexibility to map image paths to label paths by allowing custom label folder names instead of only "labels". ποΈβ¨
π Key Changes
- Updated img2label_paths to:
- Accept any iterable of image paths (type hint relaxed).
- Support a configurable label folder name via a new parameter label_folder_name (default: "labels").
- Preserve existing behavior while enabling alternative directory structures.
π― Purpose & Impact
- Enables datasets that use non-standard label folder names (e.g., "ann", "annotations") without extra preprocessing. π§
- Improves compatibility with diverse dataset layouts, making data integration smoother. π€
- Maintains backward compatibility for existing users and pipelines. β
All Contributors have signed the CLA. β
Posted by the CLA Assistant Lite bot.
π Hello @songsnim, thank you for submitting an ultralytics/ultralytics π PR! This is an automated response to help speed things up, and an Ultralytics engineer will also assist you soon. To ensure a seamless integration of your work, please review the following checklist:
- β Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues(https://github.com/ultralytics/ultralytics/issues). Ensure your commit messages are clear, concise, and adhere to the project's conventions.
- β
Synchronize with Source: Confirm your PR is synchronized with the
ultralytics/ultralyticsmainbranch. If it's behind, update it by clicking the 'Update branch' button or by runninggit pullandgit merge mainlocally. - β Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI)(https://docs.ultralytics.com/help/CI/) checks are passing. If any checks fail, please address the issues.
- β Update Documentation: Update the relevant documentation(https://docs.ultralytics.com/) for any new or modified features.
- β Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
- β Sign the CLA: Please ensure you have signed our Contributor License Agreement(https://docs.ultralytics.com/help/CLA/) if this is your first Ultralytics PR by writing "I have read the CLA Document and I sign the CLA" in a new message.
- β Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." β Bruce Lee
For more guidance, please refer to our Contributing Guide(https://docs.ultralytics.com/help/contributing/). Donβt hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! π
Notes on your PR:
- Nice enhancement to img2label_paths with the new label_folder_name parameter while keeping default behavior for backward compatibility. π
- If this feature affects dataset YAML usage or examples, please consider adding a brief note or example in the docs and tests to validate alternate label directory names. π§ͺπ
If your PR addresses a bug, please also include a Minimum Reproducible Example (MRE) detailing:
- The exact steps or code snippet to reproduce
- Expected vs. actual behavior
- Environment details (OS, Python, package versions) This helps us verify and merge your fix faster. π
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:loudspeaker: Thoughts on this report? Let us know!
I have read the CLA Document and I sign the CLA
this would be an useful addition that a lot of people could benefit from, see also pull requests #21430, #20870 and issues #9087, #12986
Thanks, agreedβthis is useful; weβll review alongside #21430, #20870 and the related issues to consolidate behavior, and pending a small unit test plus threading the YAML key through YOLODataset so img2label_paths actually receives label_folder_name, weβll move it forward.
π Hello there! We wanted to let you know that we've decided to close this pull request due to inactivity. We appreciate the effort you put into contributing to our project, but unfortunately, not all contributions are suitable or aligned with our product roadmap.
We hope you understand our decision, and please don't let it discourage you from contributing to open source projects in the future. We value all of our community members and their contributions, and we encourage you to keep exploring new projects and ways to get involved.
For additional resources and information, please see the links below:
- Docs: https://docs.ultralytics.com
- HUB: https://hub.ultralytics.com
- Community: https://community.ultralytics.com
Thank you for your contributions to YOLO π and Vision AI β