Closed whiteless9 closed 3 years ago
π Hello @whiteless9, 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 Glenn Jocher at glenn.jocher@ultralytics.com.
Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:
$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt
YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.
@whiteless9 π hi, thanks for letting us know about this problem with YOLOv5 π. We've created a few short guidelines below to help users provide what we need in order to get started investigating a possible problem.
When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:
In addition to the above requirements, for Ultralytics to provide assistance your code should be:
git pull
or git clone
a new copy to ensure your problem has not already been resolved by previous commits.If you believe your problem meets all of the above criteria, please close this issue and raise a new one using the π Bug Report template and providing a minimum reproducible example to help us better understand and diagnose your problem.
Thank you! π
I meet the same error and it works well before,I don't know what happened
@Hezhexi2002 π hi, thanks for letting us know about this problem with YOLOv5 π. We've created a few short guidelines below to help users provide what we need in order to get started investigating a possible problem.
When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:
In addition to the above requirements, for Ultralytics to provide assistance your code should be:
git pull
or git clone
a new copy to ensure your problem has not already been resolved by previous commits.If you believe your problem meets all of the above criteria, please close this issue and raise a new one using the π Bug Report template and providing a minimum reproducible example to help us better understand and diagnose your problem.
Thank you! π
π 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 β!
@whiteless9 I got same error after git pool Fix - add dim before nms:
pred = torch.unsqueeze(pred, 0)
pred = non_max_suppression(pred, conf_thres, iou_thres, classes, agnostic_nms, max_det=max_det)
@Alek-dr @glenn-jocher I had the same problem using YOLOv5 v6.1 with my custom code. (I did everything that required like the original code, but for some reason it throw that error).
after adding
pred = torch.unsqueeze(pred, 0)
it solved as @Alek-dr said.
thanks!
@whiteless9 @Alek-dr @RoyCopter can you help us by supplying a reproducible example that we can use to view the error ourselves?
@glenn-jocher I'm having the same issue, also using Windows 10. Here is the minimum reproducible code:
import numpy as np
import yolov5
from yolov5.utils.general import non_max_suppression
model = yolov5.load("./yolov5s.pt")
results = model(np.zeros((3, 640, 640)))
pred = results.pred[0]
print(non_max_suppression(pred))
It throws the following error:
Traceback (most recent call last):
File "yolo_test.py", line 9, in <module>
print(non_max_suppression(pred))
File "venv\lib\site-packages\yolov5\utils\general.py", line 1055, in non_max_suppression
nc = prediction.shape[2] - nm - 5 # number of classes
IndexError: tuple index out of range
Am I perhaps using it incorrectly?
@SeifAbdElrhman π Hello! Thanks for asking about handling inference results. YOLOv5 π PyTorch Hub models allow for simple model loading and inference in a pure python environment without using detect.py
.
This example loads a pretrained YOLOv5s model from PyTorch Hub as model
and passes an image for inference. 'yolov5s'
is the YOLOv5 'small' model. For details on all available models please see the README. Custom models can also be loaded, including custom trained PyTorch models and their exported variants, i.e. ONNX, TensorRT, TensorFlow, OpenVINO YOLOv5 models.
import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # yolov5n - yolov5x6 official model
# 'custom', 'path/to/best.pt') # custom model
# Images
im = 'https://ultralytics.com/images/zidane.jpg' # or file, Path, URL, PIL, OpenCV, numpy, list
# Inference
results = model(im)
# Results
results.print() # or .show(), .save(), .crop(), .pandas(), etc.
results.xyxy[0] # im predictions (tensor)
results.pandas().xyxy[0] # im predictions (pandas)
# xmin ymin xmax ymax confidence class name
# 0 749.50 43.50 1148.0 704.5 0.874023 0 person
# 2 114.75 195.75 1095.0 708.0 0.624512 0 person
# 3 986.00 304.00 1028.0 420.0 0.286865 27 tie
results.pandas().xyxy[0].value_counts('name') # class counts (pandas)
# person 2
# tie 1
See YOLOv5 PyTorch Hub Tutorial for details.
Good luck π and let us know if you have any other questions!
Same error here. Appeared all of a sudden in the loop if inferences (same source). What may it be?
Traceback (most recent call last):
File "/home/max/yolov5-flask/camdetect.py", line 56, in <module>
results = model('http://192.168.0.6/jpg/1/image.jpg', size=2688)
File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/root/.cache/torch/hub/ultralytics_yolov5_master/models/common.py", line 689, in forward
if im.shape[0] < 5: # image in CHW
IndexError: tuple index out of range
@SuperMaximus1984 π hi, thanks for letting us know about this possible problem with YOLOv5 π. We've created a few short guidelines below to help users provide what we need in order to start investigating a possible problem.
When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:
For Ultralytics to provide assistance your code should also be:
git pull
or git clone
a new copy to ensure your problem has not already been solved in master.If you believe your problem meets all the above criteria, please close this issue and raise a new one using the π Bug Report template with a minimum reproducible example to help us better understand and diagnose your problem.
Thank you! π
I am opening this back up as this is not resolved. I classified using Yolov8, but I am using Yolov5 to detect , and getting this same error, could it be that Yolov8 generates a weight incompatible with yolov5?
It's likely that YOLOv8 weights are incompatible with YOLOv5. Please ensure you use YOLOv5-trained weights with YOLOv5 models.
βQuestion
Additional context