Skip to content
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

Batch prediction not working with NCNN model #13010

Closed
1 of 2 tasks
BDhaese opened this issue May 22, 2024 · 3 comments
Closed
1 of 2 tasks

Batch prediction not working with NCNN model #13010

BDhaese opened this issue May 22, 2024 · 3 comments
Labels
bug Something isn't working Stale

Comments

@BDhaese
Copy link

BDhaese commented May 22, 2024

Search before asking

  • I have searched the YOLOv8 issues and found no similar bug report.

YOLOv8 Component

Predict

Bug

Using : model = YOLO('yolov8s.pt') it works fine to pass a list to model.predict()
However when using model = YOLO('yolov8s_ncnn_model') it produces the following error:

image

yolov8s_ncnn_model was made following the docs using model.export(format='ncnn')

Environment

Ultralytics YOLOv8.2.15 🚀 Python-3.10.0 torch-2.3.0+cpu CPU (Intel Core(TM) i5-8300H 2.30GHz)
Setup complete ✅ (8 CPUs, 15.9 GB RAM, 550.8/930.3 GB disk)
None

Minimal Reproducible Example

`import cv2
from ultralytics import YOLO

cap = cv2.VideoCapture(0)
i = 0
model_ncnn = YOLO('yolov8s_ncnn_model')
model_ncnn.classes = [0]

frames= []
while(i<5):

ret, frame = cap.read()
frames.append(frame)
i += 1

results = model_ncnn.predict(source=frames)
cap.release()
`

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@BDhaese BDhaese added the bug Something isn't working label May 22, 2024
Copy link

👋 Hello @BDhaese, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

@BDhaese hello! Thanks for reaching out with your issue regarding batch prediction with the NCNN model. 🌟

It seems like the NCNN model might not support batch predictions in the same way the PyTorch model does. NCNN is generally optimized for single-image inference on mobile and embedded devices, which could explain the discrepancy you're experiencing.

As a workaround, you might consider running a loop to process each frame individually, like this:

import cv2
from ultralytics import YOLO

cap = cv2.VideoCapture(0)
model_ncnn = YOLO('yolov8s_ncnn_model')
model_ncnn.classes = [0]

results = []
while True:
    ret, frame = cap.read()
    if not ret:
        break
    result = model_ncnn.predict(source=frame)
    results.append(result)

cap.release()

This approach processes each frame as it's captured, which should avoid the batch processing issue.

Let us know if this helps or if you have any more questions! 🚀

Copy link

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Jun 24, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

2 participants