Skip to content

Handle input sources with multi-level child subfolders#8924

Closed
DrSnowbird wants to merge 7 commits intoultralytics:masterfrom
DrSnowbird:master
Closed

Handle input sources with multi-level child subfolders#8924
DrSnowbird wants to merge 7 commits intoultralytics:masterfrom
DrSnowbird:master

Conversation

@DrSnowbird
Copy link
Copy Markdown

@DrSnowbird DrSnowbird commented Aug 10, 2022

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Enhancements to YOLOv5 output directory structure and a test script for detection.

📊 Key Changes

  • 👨‍💻 Modified the handling of output paths in detect.py, ensuring outputs are organized in images and labels subdirectories.
  • 🌲 detect.py now respects the relative directory structure of the input source when saving outputs.
  • 🏗️ Added mkdir commands to create necessary nested directories for saving images and labels.
  • 🧪 Introduced test-detect.py, a simple script to perform model inference and print the results.
  • 💾 Updated utils/dataloaders.py to properly load all files recursively when a directory is specified.

🎯 Purpose & Impact

  • 📁 The changes to directory handling in detect.py allow for better organization of outputs, especially when dealing with nested input directories, enhancing usability for users with complex datasets.
  • 🗂️ Maintaining the input's directory structure in outputs makes post-processing tasks like dataset analysis and file navigation more intuitive.
  • ✨ The new test-detect.py script offers a straightforward way for users to test model inference, improving the initial user experience and providing a quick way to validate installations and models.
  • ➕ Recursive file loading ensures that all images in nested folders are used for inference, eliminating the chance of missing data due to directory depth, which can be crucial for thorough dataset evaluation.

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Hello @DrSnowbird, thank you for submitting a YOLOv5 🚀 PR! To allow your work to be integrated as seamlessly as possible, we advise you to:

  • ✅ Verify your PR is up-to-date with upstream/master. If your PR is behind upstream/master an automatic GitHub Actions merge may be attempted by writing /rebase in a new comment, or by running the following code, replacing 'feature' with the name of your local branch:
git remote add upstream https://github.com/ultralytics/yolov5.git
git fetch upstream
# git checkout feature  # <--- replace 'feature' with local branch name
git merge upstream/master
git push -u origin -f
  • ✅ Verify all Continuous Integration (CI) checks are passing.
  • ✅ Reduce changes to the absolute minimum required 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

@glenn-jocher
Copy link
Copy Markdown
Member

glenn-jocher commented Aug 10, 2022

@DrSnowbird recursive subfolder inference is already available with glob commands, i.e.
https://stackoverflow.com/questions/2186525/how-to-use-glob-to-find-files-recursively

python detect.py --source 'path/**/*.jpg'

@glenn-jocher
Copy link
Copy Markdown
Member

@DrSnowbird I noticed the README example lacked quotes so I fixed the glob examples in #8927

@DrSnowbird
Copy link
Copy Markdown
Author

DrSnowbird commented Aug 11, 2022

Thanks for comment
The usage is for the example below so all the (including recursive children folders's) files (jpg, mp4, etc also non images will be scanned if process-able by yolov5). My users just did not like the "special requular expression setup since are are non-tech users since the burden is on them to know or setup up correctly". So, I tried to make it dumb-and-simple with whatever they provide (files, directory (plain OS dir name), or regex (if power users)) with the intelligence of processing leaving to the codes. I think we have different use casee (or design philosophy)! I though maybe yolov5 user community can benefit from my similar users' use cases. If not aligning with you guys' design principle, it's fine and I will continue to provide overwrite impelementations of you guys' upstream implementation using my forking github to shadow you guys' upstream. Thanks!

python detect.py --source './images'

@glenn-jocher
Copy link
Copy Markdown
Member

@DrSnowbird the command for recursive inference for all images and videos is very simple. The dataloader automatically ignores any non-viable files.

python detect.py --source 'path/**/*'

@DrSnowbird
Copy link
Copy Markdown
Author

@glenn-jocher - thanks for information.
I think we have two different kinds of users and design goals. As tech person, I know exactly what you said and glob ("**/.") does. But, I don't want train or require my users to specify or learn the syntax.
I will close the pull request since it is not aligning with each other goals design principles.
thanks anyway.

@DrSnowbird DrSnowbird closed this Aug 12, 2022
@glenn-jocher
Copy link
Copy Markdown
Member

Understood, @DrSnowbird! We appreciate your efforts and dedication to simplifying the user experience. The YOLOv5 community benefits greatly from diverse perspectives and contributions. If you have any further ideas or feedback, we're always open to discussion. Thank you for your understanding and support.

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.

2 participants