目录

1、pip install -r requirements.txt问题

 2、错误:pycharm终端提示"无法加载文件 C:\xxxx\profile.ps1,因为在此系统上禁止运行脚本......"

3、错误:RuntimeError: result type Float can‘t be cast to the desired output type __int64

 4、错误:RuntimeError:CUDA out of memory

 5、错误:OSError:[WinError 1455]页面文件太小,无法完成操作。

6、错误:YOLO UserWarning: torch.meshgrid: in an upcoming release,return _VF.meshgrid(tensors, **kwargs) #type: ignore[attr-defined]......

7、pycharm找不到conda可执行文件怎么办

 8、YOLOv5连接摄像头失败


1、pip install -r requirements.txt问题

目标检测常用相机 目标检测常用的模型_YOLO

 解决方法:修改镜像源为国内,eg:清华/阿里云/豆瓣,以清华镜像为例, 临时修改:加参数-i和镜像地址

pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/

 相关资料:

1、requirements.txt文件

     python项目中必须包含一个 requirements.txt 文件,用于记录所有依赖包及其精确的版本号。以便新环境部署。requirements.txt可以通过pip命令自动生成和安装。

2、生成requirements.txt文件

     PyCharm的Terminal端生成requirements.txt文件

pip freeze > requirements.txt

3、安装requirements.txt文件中的依赖包

     PyCharm的Terminal安装requirements.txt依赖包:

pip install -r requirements.txt

 2、错误:pycharm终端提示"无法加载文件 C:\xxxx\profile.ps1,因为在此系统上禁止运行脚本......"

目标检测常用相机 目标检测常用的模型_YOLO_02

 解决方法:使用管理远打开 windows powershell,运行以下内容

Set-ExecutionPolicy -ExecutionPolicy

RemoteSigned -Scope CurrentUser

 采用此方案后,可能会对本地某些脚本放行,存在安全问题,所以,运行此内容后,日常使用电脑浏览网页时需更加谨慎

3、错误:RuntimeError: result type Float can‘t be cast to the desired output type __int64

目标检测常用相机 目标检测常用的模型_目标检测_03

 在使用YOLOv5训练自己的数据集时,运行train.py时出现上述问题

 解决方法:因为新版本的torch无法自动执行此转换,故:

将loss.py中

gain = torch.ones(7, device=targets.device)

 更改为

gain = torch.ones(7, device=targets.device).long()

 4、错误:RuntimeError:CUDA out of memory

目标检测常用相机 目标检测常用的模型_YOLO_04

 由于每个人的电脑性能不同,所以输入图片的数量和工作的核心数也会不同,需要根据自身设备的实际情况进行配置,否则就会出现GPU显存溢出的报错如上图所示

 解决方法:修改train.py中的参数

parser.add_argument('--batch-size', type=int, default=8, help='total batch size for all GPUs')

parser.add_argument('--workers', type=int, default=8, help='maximum number of dataloader workers')

 5、错误:OSError:[WinError 1455]页面文件太小,无法完成操作。

 解决方法:可以根据如下的操作来修改,在utils路径下找到datasets.py这个文件,将里面的第81行里面的参数nw改完0就可以了

目标检测常用相机 目标检测常用的模型_目标检测_05

 

目标检测常用相机 目标检测常用的模型_目标检测_06

6、错误:YOLO UserWarning: torch.meshgrid: in an upcoming release,return _VF.meshgrid(tensors, **kwargs) #type: ignore[attr-defined]......

 解决方法:找到pyCharm所用的虚拟环境下的functional.py文件

根据具体错误情况找到functional的504行

return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]

 然后修改此代码为:

return _VF.meshgrid(tensors, **kwargs, indexing = 'ij') # type: ignore[attr-defined]

7、pycharm找不到conda可执行文件怎么办

 解决方法:找到conda/bin文件下面的conda.bt文件,把路径复制下来,粘贴到Conda可执行文件,点击加载环境,如下图所示:

目标检测常用相机 目标检测常用的模型_深度学习_07

 8、YOLOv5连接摄像头失败

目标检测常用相机 目标检测常用的模型_深度学习_08

 default值为0表示启用摄像头

parser.add_argument('--source', type=str, default='0', help='source')  # file/folder, 0 for webcam

 解决方法:修改代码

源代码:

if 'youtube.com/' in url or 'youtu.be/' in url:  # if source is YouTube video

修改后:

if 'youtube.com/' in str(url) or 'youtu.be/' in str(url):  # if source is YouTube video

【纯小白】本文为本人搭建YOLOv5目标检测模型中所遇到的一系列问题及最终的解决方法的学习记录总结