登录github.com,search yolov5
查看选择各个版本:
查看发布各个版本:
点击下载版本:
下载zip文件,解压之后导入pycharm
先看这个文件requirements.txt:这是启动yolov5需要的各个库
- # pip install -r requirements.txt
-
- # base ----------------------------------------
- matplotlib>=3.2.2
- numpy>=1.18.5
- opencv-python>=4.1.2
- Pillow
- PyYAML>=5.3.1
- scipy>=1.4.1
- torch>=1.7.0
- torchvision>=0.8.1
- tqdm>=4.41.0
-
- # logging -------------------------------------
- tensorboard>=2.4.1
- # wandb
-
- # plotting ------------------------------------
- seaborn>=0.11.0
- pandas
-
- # export --------------------------------------
- # coremltools>=4.1
- # onnx>=1.8.1
- # scikit-learn==0.19.2 # for coreml quantization
-
- # extras --------------------------------------
- thop # FLOPS computation
- pycocotools>=2.0 # COCO mAP
直接在pycharm命令行下载安装:
命令行输入这个命令:
pip install -r requirements.txt
安装过程中遇到一些问题:
1、存在一个问题pycocotools无法安装成功:
参考https://blog.csdn.net/duckinBoy/article/details/123015270
https://pan.baidu.com/s/1nWQdPRtGwNnOO2DkxRuGuA 下载,提取码:i5d7
下载之后放到
2、提示:AttributeError: Can't get attribute 'SPPF' on
解决办法:把下面这段代码放到F:\yolov5-5.0\models\common.py里面
- import warnings
-
-
- class SPPF(nn.Module):
- # Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher
- def __init__(self, c1, c2, k=5): # equivalent to SPP(k=(5, 9, 13))
- super().__init__()
- c_ = c1 // 2 # hidden channels
- self.cv1 = Conv(c1, c_, 1, 1)
- self.cv2 = Conv(c_ * 4, c2, 1, 1)
- self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)
-
- def forward(self, x):
- x = self.cv1(x)
- with warnings.catch_warnings():
- warnings.simplefilter('ignore') # suppress torch 1.9.0 max_pool2d() warning
- y1 = self.m(x)
- y2 = self.m(y1)
- return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))
3、提示这个异常
raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
解决办法:
发现这个版本
torch=1.12.1
torchvision=0.13.1
降低版本
torch=1.10.1
torchvision=0.10.1
4、提示RuntimeError: The size of tensor a (60) must match the size of tensor b (56) at non-singleton dimension 3
发现yolov5s.pt没有下载成功导致的,去网站自己下载,让后放到 F:\yolov5-5.0目录下
下载地址:
https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
然后就可以成功的把yolov5跑起来了,顺便利用这个模型,预测俩张demo图片。
注意:直接运行detect.py就好。