ultralytics icon indicating copy to clipboard operation
ultralytics copied to clipboard

feat(utils): add 'label_folder_name' to 'img2label_paths' function

Open songsnim opened this issue 4 months ago β€’ 7 comments

  1. Check for Existing Contributions βœ… I have checked existing PRs and this contribution is unique.

  2. Link Related Issues N/A. This PR is a proactive improvement to enhance function reusability and does not address a specific open issue.

  3. 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...)
  1. 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. βœ…

songsnim avatar Aug 10 '25 09:08 songsnim

All Contributors have signed the CLA. βœ…
Posted by the CLA Assistant Lite bot.

github-actions[bot] avatar Aug 10 '25 09:08 github-actions[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/ultralytics main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • βœ… 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:

  1. The exact steps or code snippet to reproduce
  2. Expected vs. actual behavior
  3. Environment details (OS, Python, package versions) This helps us verify and merge your fix faster. πŸ™

UltralyticsAssistant avatar Aug 10 '25 09:08 UltralyticsAssistant

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests.

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar Aug 10 '25 09:08 codecov[bot]

I have read the CLA Document and I sign the CLA

songsnim avatar Aug 10 '25 09:08 songsnim

this would be an useful addition that a lot of people could benefit from, see also pull requests #21430, #20870 and issues #9087, #12986

roel-klein avatar Aug 13 '25 19:08 roel-klein

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.

glenn-jocher avatar Aug 14 '25 03:08 glenn-jocher

πŸ‘‹ 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 ⭐

github-actions[bot] avatar Nov 09 '25 00:11 github-actions[bot]