• pycharm运行YOLOv5 (一)


    登录github.com,search yolov5

    查看选择各个版本:

     

    查看发布各个版本:

     

    点击下载版本:

     

    下载zip文件,解压之后导入pycharm

     

    先看这个文件requirements.txt:这是启动yolov5需要的各个库

    1. # pip install -r requirements.txt
    2. # base ----------------------------------------
    3. matplotlib>=3.2.2
    4. numpy>=1.18.5
    5. opencv-python>=4.1.2
    6. Pillow
    7. PyYAML>=5.3.1
    8. scipy>=1.4.1
    9. torch>=1.7.0
    10. torchvision>=0.8.1
    11. tqdm>=4.41.0
    12. # logging -------------------------------------
    13. tensorboard>=2.4.1
    14. # wandb
    15. # plotting ------------------------------------
    16. seaborn>=0.11.0
    17. pandas
    18. # export --------------------------------------
    19. # coremltools>=4.1
    20. # onnx>=1.8.1
    21. # scikit-learn==0.19.2 # for coreml quantization
    22. # extras --------------------------------------
    23. thop # FLOPS computation
    24. 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里面

    1. import warnings
    2. class SPPF(nn.Module):
    3. # Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher
    4. def __init__(self, c1, c2, k=5): # equivalent to SPP(k=(5, 9, 13))
    5. super().__init__()
    6. c_ = c1 // 2 # hidden channels
    7. self.cv1 = Conv(c1, c_, 1, 1)
    8. self.cv2 = Conv(c_ * 4, c2, 1, 1)
    9. self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)
    10. def forward(self, x):
    11. x = self.cv1(x)
    12. with warnings.catch_warnings():
    13. warnings.simplefilter('ignore') # suppress torch 1.9.0 max_pool2d() warning
    14. y1 = self.m(x)
    15. y2 = self.m(y1)
    16. 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就好。

  • 相关阅读:
    02Spring框架的特点以及jar包下载
    【算法】二分查找模板
    用Python中的马尔科夫链模拟文本
    SqlMap工具使用(超详细-网安(白帽黑客)人员必看!!!)
    webGL编程指南 第三章 矩阵旋转三角形rotatedTriangle_Matrix
    我们是如何解决偶发性的 502 错误的
    基于SSM实现的儿童疫苗信息管理系统设计与实现毕业设计源码311930
    Vue借助浏览器实现代码断点调试
    快速排序及其拓展应用
    计算机网络八股总结
  • 原文地址:https://blog.csdn.net/chehec2010/article/details/126649077