[Classify]: Allow inference on dirs and videos#9003
[Classify]: Allow inference on dirs and videos#9003glenn-jocher merged 9 commits intoultralytics:masterfrom
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 <glenn.jocher@ultralytics.com>
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.pyto handle file, directory, URL, and glob patterns as input sources.cv2) from the main inference script.LoadImagesclass to theclassify/predict.pyto handle different input types.classify_transformsfunction.--sourceparameter.🎯 Purpose & Impact