【笔记】【YOLO学习】YOLOV5环境配置与代码运行问题

前言

本文基于该博客(目标检测—教你利用yolov5训练自己的目标检测模型)撰写,意为记录在配置yolo5运行环境运行代码时遇到的一系列问题的解决方法。



训练集、测试集、验证集的区别

训练集、测试集和验证集都是在机器学习中用于评估和调整模型的数据集,它们的主要区别在于它们在机器学习的不同阶段使用。

  • 训练集(Training set)是用于训练模型的数据集,机器学习模型会通过训练集中的数据进行学习和训练,以便对未知数据进行预测。训练集通常是数据集的大部分,通常在80%到90%之间,其余部分用于测试集和验证集。

  • 测试集(Test set)是用于评估模型性能的数据集,它用于测试模型的泛化能力,即模型在未见过的数据上的表现。测试集必须与训练集是相互独立的,这意味着测试集中的数据不应该在训练集中出现过。

  • 验证集(Validation set)是用于调整模型超参数的数据集,它用于选择最佳模型。验证集通常是从训练集中划分出来的,通常在10%到20%之间,与测试集一样必须是与训练集是相互独立的。在训练过程中,模型的超参数会被不断地调整,同时在验证集上进行评估,以找到最佳的超参数。

总之,训练集是用于训练模型的数据集,测试集是用于评估模型性能的数据集,验证集是用于调整模型超参数的数据集。在机器学习中,合理地使用这些数据集可以帮助我们获得更好的模型性能和泛化能力。



Error:module ‘numpy’ has no attribute ‘int’

原因

官方在 requirements.txt 文件中,对于 numpy 版本要求如下:

numpy>=1.18.5

但是 numpy.int 在NumPy 1.20中已弃用,在NumPy 1.24中已删除。

解决方法

降级 numpy 版本:

pip install numpy==1.85


opencv-python安装问题

安装opencv-python报错

在添加的 anaconda channels (已经换了清华源)中找不到 opencv-python 软件包,报错信息如下:

Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.


PackagesNotFoundError: The following packages are not available from current channels:

  - opencv-python[version='>=4.1.2']

Current channels:

  - https://conda.anaconda.org/pytorch/win-64
  - https://conda.anaconda.org/pytorch/noarch
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/noarch
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
  - https://repo.anaconda.com/pkgs/main/win-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/win-64
  - https://repo.anaconda.com/pkgs/r/noarch
  - https://repo.anaconda.com/pkgs/msys2/win-64
  - https://repo.anaconda.com/pkgs/msys2/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.
  • 在其他 conda channels 中可以找到能够下载 opencv-python 的 channel,但是不管是正常使用或者使用魔法速度都很慢。

解决方式

  • 激活创建的 conda 虚拟环境
conda activate 你的虚拟环境名
  • 使用 pip 安装 opencv-python
pip install opencv-python


tensorboard本地端口(http://localhost:6006/)无法打开

解决方式

  • 开启 cmd(使用管理员权限打开)
  • 激活 yolo 运行的虚拟环境
conda activate 你运行yolo的虚拟环境名
  • 进入项目路径
  1. 如果你项目所在路径和你目前所在路径不在同一个盘(例如你现在在 C 盘,但是你的项目存放在 F 盘),那么先在 cmd 键入对应的盘符(注意使用英文冒号)
F:
  1. 然后再用 cd 命令进入你项目的路径
cd 你的yolo项目路径根目录
  • 输入如下的代码,等号后改成你存放 tensorboard 数据的位置(一般就在 runs 文件夹里)
tensorboard --logdir=./runs


中文路径导致数据集不存在(Exception: Dataset not found.)

报错信息

E:\ProgramData\Anaconda3\envs\pytorch\python.exe F:/学习之路/YOLO/yolo5/yolov5-5.0/yolov5-5.0/train.py
github: skipping check (not a git repository)
YOLOv5  2021-4-12 torch 1.12.0 CUDA:0 (NVIDIA GeForce RTX 3050 Ti Laptop GPU, 4095.5MB)

Namespace(adam=False, artifact_alias='latest', batch_size=8, bbox_interval=-1, bucket='', cache_images=False, cfg='models/yolov5s_catANDdog.yaml', data='data/voc_catANDdog.yaml', device='', entity=None, epochs=300, evolve=False, exist_ok=False, global_rank=-1, hyp='data/hyp.scratch.yaml', image_weights=False, img_size=[640, 640], label_smoothing=0.0, linear_lr=False, local_rank=-1, multi_scale=False, name='exp', noautoanchor=False, nosave=False, notest=False, project='runs/train', quad=False, rect=False, resume=False, save_dir='runs\\train\\exp', save_period=-1, single_cls=False, sync_bn=False, total_batch_size=8, upload_dataset=False, weights='weights/yolov5s.pt', workers=8, world_size=1)
tensorboard: Start with 'tensorboard --logdir runs/train', view at http://localhost:6006/
hyperparameters: lr0=0.01, lrf=0.2, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0
wandb: Install Weights & Biases for YOLOv5 logging with 'pip install wandb' (recommended)

                 from  n    params  module                                  arguments                     
  0                -1  1      3520  models.common.Focus                     [3, 32, 3]                    
  1                -1  1     18560  models.common.Conv                      [32, 64, 3, 2]                
  2                -1  1     18816  models.common.C3                        [64, 64, 1]                   
  3                -1  1     73984  models.common.Conv                      [64, 128, 3, 2]               
  4                -1  1    156928  models.common.C3                        [128, 128, 3]                 
  5                -1  1    295424  models.common.Conv                      [128, 256, 3, 2]              
  6                -1  1    625152  models.common.C3                        [256, 256, 3]                 
  7                -1  1   1180672  models.common.Conv                      [256, 512, 3, 2]              
  8                -1  1    656896  models.common.SPP                       [512, 512, [5, 9, 13]]        
  9                -1  1   1182720  models.common.C3                        [512, 512, 1, False]          
 10                -1  1    131584  models.common.Conv                      [512, 256, 1, 1]              
 11                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 12           [-1, 6]  1         0  models.common.Concat                    [1]                           
 13                -1  1    361984  models.common.C3                        [512, 256, 1, False]          
 14                -1  1     33024  models.common.Conv                      [256, 128, 1, 1]              
 15                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 16           [-1, 4]  1         0  models.common.Concat                    [1]                           
 17                -1  1     90880  models.common.C3                        [256, 128, 1, False]          
 18                -1  1    147712  models.common.Conv                      [128, 128, 3, 2]              
 19          [-1, 14]  1         0  models.common.Concat                    [1]                           
 20                -1  1    296448  models.common.C3                        [256, 256, 1, False]          
 21                -1  1    590336  models.common.Conv                      [256, 256, 3, 2]              
 22          [-1, 10]  1         0  models.common.Concat                    [1]                           
 23                -1  1   1182720  models.common.C3                        [512, 512, 1, False]          
 24      [17, 20, 23]  1     18879  models.yolo.Detect                      [2, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]]
E:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\torch\functional.py:478: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  C:\cb\pytorch_1000000000000\work\aten\src\ATen\native\TensorShape.cpp:2895.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
Model Summary: 283 layers, 7066239 parameters, 7066239 gradients, 16.5 GFLOPS


WARNING: Dataset not found, nonexistent paths: ['F:\\瀛︿範涔嬭矾\\YOLO\\yolo5\\yolov5-5.0\\yolov5-5.0\\VOCdevkit\\images\\val']
Transferred 354/362 items from weights/yolov5s.pt
Traceback (most recent call last):
  File "F:/学习之路/YOLO/yolo5/yolov5-5.0/yolov5-5.0/train.py", line 572, in <module>
    train(hyp, opt, device, tb_writer)
  File "F:/学习之路/YOLO/yolo5/yolov5-5.0/yolov5-5.0/train.py", line 97, in train
    check_dataset(data_dict)  # check
  File "F:\学习之路\YOLO\yolo5\yolov5-5.0\yolov5-5.0\utils\general.py", line 173, in check_dataset
    raise Exception('Dataset not found.')
Exception: Dataset not found.

进程已结束,退出代码为 1

反复检查过数据集的路径,没有错误,怀疑是中文路径导致的问题:

解决方法

yolo使用的所有路径都不要使用含有中文的路径。



RuntimeError: result type Float can’t be cast to the desired output type __int64

解决方法

参考这篇文章
解决Yolov5的RuntimeError: result type Float can‘t be cast to the desired output type long int 问题

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

__Witheart__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值