-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
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
[Classify]: Allow inference on dirs and videos #9003
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
@AyushExel this is a good idea, but the current implementation loads every image twice, which we want to avoid. I think the challenge is the input transforms are different for cls models. This might take some updating to LoadImages to accept a transform object, and to apply default transforms if T=None. |
@glenn-jocher yes the double image loading should slow down the video inference but should be negligible for single images or a dir. You want to address the transforms support in LoadImages here or take it to a separate PR? |
@AyushExel I think I can add them in this PR. Let's see. |
@AyushExel ok awesome. This passes the cls transforms to the dataloader and adds inference support for dirs, globs, URLs and videos. |
@glenn-jocher ok perfect! While you're at it, what do you think about adding support for --show-vid wherein the video inference displays each frame in cv2 windows with top 5 labels being printed at the top or bottom ? |
@AyushExel yup there's definitely more we could do on the logging/plotting results side of things with classification. I wasn't sure how to save/show classification results, but yes we could just write it directly on the image like you suggested. |
Should probably also refactor the URL-file download code into LoadImages since now it's duplicated in detect.py and classify/predict.py. |
* allow image dirs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update predict.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update dataloaders.py * Update predict.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update predict.py * Update predict.py Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher <[email protected]>
This PR allows running classification inference on dirs.

Usage:
python classify/predict.py --source data/images
🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
Enhanced the image classification inference to support various input types.
📊 Key Changes
classify/predict.py
to handle file, directory, URL, and glob patterns as input sources.cv2
) from the main inference script.LoadImages
class to theclassify/predict.py
to handle different input types.classify_transforms
function.--source
parameter.🎯 Purpose & Impact