ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.48k stars 16.29k forks source link

RuntimeError: "slow_conv2d_cpu" not implemented for 'Half' #10379

Closed zinuok closed 1 year ago

zinuok commented 1 year ago

Search before asking

Question

Hello, I'm trying to use YOLOv5n with CPU.

I wanted to speed up model inference even more, so I applied the --half flag. As a result, the following error occurred. Is half-precision not supported in CPU mode?

Fusing layers... 
YOLOv5n summary: 213 layers, 1867405 parameters, 0 gradients
Traceback (most recent call last):
  File "/home/zinuok/ros/cps_new_ws/src/yolov5_ros/scripts/ros_yolo.py", line 261, in <module>
    run(**vars(opt))
  File "/home/zinuok/anaconda3/envs/yolo5/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/home/zinuok/ros/cps_new_ws/src/yolov5_ros/scripts/ros_yolo.py", line 140, in run
    pred = model(im, augment=augment, visualize=False)
  File "/home/zinuok/anaconda3/envs/yolo5/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/zinuok/ros/cps_new_ws/src/yolov5_ros/scripts/models/common.py", line 515, in forward
    y = self.model(im, augment=augment, visualize=visualize) if augment or visualize else self.model(im)
  File "/home/zinuok/anaconda3/envs/yolo5/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/zinuok/ros/cps_new_ws/src/yolov5_ros/scripts/models/yolo.py", line 209, in forward
    return self._forward_once(x, profile, visualize)  # single-scale inference, train
  File "/home/zinuok/ros/cps_new_ws/src/yolov5_ros/scripts/models/yolo.py", line 121, in _forward_once
    x = m(x)  # run
  File "/home/zinuok/anaconda3/envs/yolo5/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/zinuok/ros/cps_new_ws/src/yolov5_ros/scripts/models/common.py", line 60, in forward_fuse
    return self.act(self.conv(x))
  File "/home/zinuok/anaconda3/envs/yolo5/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/zinuok/anaconda3/envs/yolo5/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 447, in forward
    return self._conv_forward(input, self.weight, self.bias)
  File "/home/zinuok/anaconda3/envs/yolo5/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 444, in _conv_forward
    self.padding, self.dilation, self.groups)
RuntimeError: "slow_conv2d_cpu" not implemented for 'Half'

Additional

No response

github-actions[bot] commented 1 year ago

πŸ‘‹ Hello @zinuok, 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 commented 1 year ago

@zinuok torch ops do not run on CPU at FP16. This has nothing to do with YOLOv5.

glenn-jocher commented 1 year ago

πŸ‘‹ Hello! Thanks for asking about inference speed issues. 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:

Good luck πŸ€ and let us know if you have any other questions!

github-actions[bot] commented 1 year ago

πŸ‘‹ 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 ⭐!