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

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

Closed
1 task done
zinuok opened this issue Dec 2, 2022 · 4 comments
Closed
1 task done

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

zinuok opened this issue Dec 2, 2022 · 4 comments
Labels
question Further information is requested Stale

Comments

@zinuok
Copy link

zinuok commented Dec 2, 2022

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

@zinuok zinuok added the question Further information is requested label Dec 2, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2022

👋 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
Copy link
Member

glenn-jocher commented Dec 2, 2022

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

@glenn-jocher
Copy link
Member

glenn-jocher commented Dec 2, 2022

👋 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:

  • 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!

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2023

👋 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 ⭐!

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

2 participants