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

Yolo V5 Inferencing on CPU Machine #10268

Closed
1 task done
rahul1728jha opened this issue Nov 23, 2022 · 10 comments
Closed
1 task done

Yolo V5 Inferencing on CPU Machine #10268

rahul1728jha opened this issue Nov 23, 2022 · 10 comments
Labels
question Further information is requested Stale

Comments

@rahul1728jha
Copy link

Search before asking

Question

Hi All,

I am trying to inference using yolo v5. Below is the setup being used:

System Configuration :
Operating system : Windows
Processor Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz 1.80 GHz
Installed RAM 8.00 GB (7.86 GB usable)
System type 64-bit operating system, x64-based processor

Setup:
Input source : Real time RTSP stream from IP camera
Output : Annotated frames

Code:
sample code is like

model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True, )
results = detection_model(frame)
labels, confidence, _ = results.xyxyn[0][:, -1], results.xyxyn[0][:, -2], results.xyxyn[0][:, :-1]
detections = results.pred[0]
dets_prod = detections.to("cpu")

Current metrics
Able to process 30 frames in 6 seconds i.e. getting a output @ 5FPS

Question :
My Constraint is I have to run it on a CPU.

  • My input stream is at 30FPS. With Yolo v5 running on CPU, can i achieve the rate of 30FPS?
  • Is it possible to achieve 30FPS on a more powerful machine in terms of RAM and process(No GPU)

Additional

No response

@rahul1728jha rahul1728jha added the question Further information is requested label Nov 23, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 23, 2022

👋 Hello @rahul1728jha, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

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

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

glenn-jocher commented Nov 24, 2022

@rahul1728jha 👋 Hello! Thanks for asking about inference speed issues. I would recommend ONNX or OpenVINO for CPU inference. See https://docs.ultralytics.com/yolov5/tutorials/model_export to ONNX or OpenVINO for up to 3x CPU speedup (#6613)

PyTorch Hub speeds will vary by hardware, software, model, inference settings, etc. Our default example in Colab with a V100 looks like this:

Screen Shot 2022-05-03 at 10 20 39 AM

YOLOv5 🚀 can be run on CPU (i.e. --device cpu, slow) or GPU if available (i.e. --device 0, faster). You can determine your inference device by viewing the YOLOv5 console output:

detect.py inference

python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source data/images/

Screen Shot 2022-05-03 at 2 48 42 PM

YOLOv5 PyTorch Hub inference

import torch

# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')

# Images
dir = 'https://ultralytics.com/images/'
imgs = [dir + f for f in ('zidane.jpg', 'bus.jpg')]  # batch of images

# Inference
results = model(imgs)
results.print()  # or .show(), .save()
# Speed: 631.5ms pre-process, 19.2ms inference, 1.6ms NMS per image at shape (2, 3, 640, 640)

Increase Speeds

If you would like to increase your inference speed some options are:

  • Use batched inference with YOLOv5 PyTorch Hub
  • Reduce --img-size, i.e. 1280 -> 640 -> 320
  • Reduce model size, i.e. YOLOv5x -> YOLOv5l -> YOLOv5m -> YOLOv5s -> YOLOv5n
  • Use half precision FP16 inference with python detect.py --half and python val.py --half
  • Use a faster GPUs, i.e.: P100 -> V100 -> A100
  • Export to ONNX or OpenVINO for up to 3x CPU speedup (CPU Benchmarks)
  • Export to TensorRT for up to 5x GPU speedup (GPU Benchmarks)
  • Use a free GPU backends with up to 16GB of CUDA memory: Open In Colab Open In Kaggle

Good luck 🍀 and let us know if you have any other questions!

@Denizzje
Copy link

Denizzje commented Nov 24, 2022

I am actually surprised you even got 5fps out of my old laptop CPU lol. I dont think it is possible to run a YoloV5s model with 30fps on your CPU no.

But you can perhaps squeeze out a few more FPS with the provided tools here: https://docs.ultralytics.com/yolov5/tutorials/model_export

For reference, this is mine on a Ryzen 7 5800X running the benchmark:

`benchmarks: weights=yolov5s.pt, imgsz=640, batch_size=1, data=/home/denizz/yolov5/data/coco128.yaml, device=cpu, half=False, test=False, pt_only=False, hard_fail=False
Checking setup...
YOLOv5 🚀 v7.0-4-g7398d2d Python-3.10.4 torch-1.12.0+cu102 CPU
Setup complete ✅ (16 CPUs, 31.3 GB RAM, 77.3/251.0 GB disk)

Benchmarks complete (283.14s)
                   Format  Size (MB)  mAP50-95  Inference time (ms)
0                 PyTorch       14.1    0.4716                59.95
1             TorchScript       28.1    0.4716                58.43
2                    ONNX       28.0    0.4716                43.25
3                OpenVINO        NaN       NaN                  NaN
4                TensorRT        NaN       NaN                  NaN
5                  CoreML        NaN       NaN                  NaN
6   TensorFlow SavedModel       27.8    0.4716                57.90
7     TensorFlow GraphDef       27.8    0.4716                57.96
8         TensorFlow Lite       13.9    0.4714               339.99
9     TensorFlow Edge TPU        NaN       NaN                  NaN
10          TensorFlow.js        NaN       NaN                  NaN
11           PaddlePaddle       56.1    0.4716               526.35`

Standard (PyTorch) I get 59.95ms inference time but you can see ONNX is quite a bit faster. I believe it is 17 fps vs 24 fps. OpenVINO fails for me I believe because I have an AMD CPU but it should work on your CPU. Maybe it is faster too. The OPENCV DNN should be the fastest but I couldnt get it to run now because of wrong OpenCV version to compare.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 25, 2022

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

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 YOLOv5 🚀 and Vision AI ⭐!

@github-actions github-actions bot added the Stale label Dec 25, 2022
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 5, 2023
@lucvt001
Copy link

lucvt001 commented Aug 3, 2023

Hi @glenn-jocher I understand that GPU is blazingly faster than CPU at inferencing on a batch. However, in real applications of inferencing on a live video, does the gpu still have the advantage? Since now we r processing frame by frame? For example, should I get a powerful intel NUC or a Jetson device for my robotic application if I want to do object detection and tracking in real time?

@glenn-jocher
Copy link
Member

@lucvt001 in real-time applications where inferencing is done on live video frames, GPUs still have a significant advantage over CPUs. While it's true that processing is done frame by frame, the parallel processing capabilities of GPUs allow for faster and more efficient object detection and tracking.

If you're looking for real-time object detection and tracking in a robotic application, it is recommended to use a powerful GPU such as the one found in an Intel NUC or a Jetson device. These devices are specifically designed for high-performance computing tasks like computer vision and can provide the necessary processing power to achieve real-time performance.

@lucvt001
Copy link

lucvt001 commented Aug 3, 2023

@glenn-jocher thank you for your advice!

@glenn-jocher
Copy link
Member

Hi @lucvt001 👋

When it comes to real-time video inferencing for object detection and tracking, GPUs still offer a significant advantage over CPUs. This is due to their parallel processing capabilities, which allow for faster and more efficient computation.

If you're looking to perform real-time object detection and tracking in a robotic application, it is recommended to use a powerful GPU such as those found in Intel NUC or Jetson devices. These devices are specifically designed for high-performance computing tasks like computer vision and can provide the necessary processing power to achieve real-time performance.

I hope this helps! Let me know if you have any more questions.

@shanmugamani1023
Copy link

thank you

@glenn-jocher
Copy link
Member

@shanmugamani1023 you're welcome! If you have any more questions in the future, feel free to ask. Good luck with your robotic application! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

5 participants