环境配置见yolov5/yolov3 pytorch环境配置gpu+windows11+anaconda+pycharm+RTX3050 笔记
正确的训练步骤见(windows)yolov5/yolov3训练自己的数据集,win11 gpu,pycharm,RTX3050笔记
数据集文件分布
建议将JPEGImages改为images,否则见报错三及解决方法
![](https://i-blog.csdnimg.cn/blog_migrate/33575936740e2a461d36235c397093c4.png)
HITUAVyolo.yaml数据集配置
![](https://i-blog.csdnimg.cn/blog_migrate/6428a2c5b469a6ed8edc2be8f8365a21.png)
修改train.py
搜索--data 将coco.yaml改为你自己配置文件的文件名
![](https://i-blog.csdnimg.cn/blog_migrate/a9cd61eefbdf2b52d4d4ee55b97dd584.png)
报错1
Traceback (mostrecent call last):
File"D:\anaconda3\envs\yolov5\lib\site-packages\git\__init__.py", line89, in <module>
refresh()
File"D:\anaconda3\envs\yolov5\lib\site-packages\git\__init__.py", line76, in refresh
if not Git.refresh(path=path):
File"D:\anaconda3\envs\yolov5\lib\site-packages\git\cmd.py", line 392, inrefresh
raise ImportError(err)
ImportError:Bad git executable.
The gitexecutable must be specified in one of the following ways:
- be included in your $PATH
- be set via $GIT_PYTHON_GIT_EXECUTABLE
- explicitly set via git.refresh()
All gitcommands will error until this is rectified.
This initialwarning can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESHenvironment variable. Use one of the following values:
- quiet|q|silence|s|none|n|0: for nowarning or exception
- warn|w|warning|1: for a printed warning
-error|e|raise|r|2: for a raised exception
![](https://i-blog.csdnimg.cn/blog_migrate/a180e93f85aed5a1ac24532cfe56cb7b.png)
解决方法
import git 或 from git import xxx前面加一行
os.environ["GIT_PYTHON_REFRESH"]= "quiet"
参考入门Anaconda cuda yolov5 安装排坑_anaconda yolov5_Theory D的博客-CSDN博客
报错2(可能是因为打开了todesk)
![](https://i-blog.csdnimg.cn/blog_migrate/8e7c8ceaf0ead94966ac2f1ba4a47b23.png)
解决方法
关闭todesk,修改model/yolov5s.yaml的种类为自己数据集的class数目 nc
![](https://i-blog.csdnimg.cn/blog_migrate/cf6afe54180545188ccf31fe7fb49746.png)
报错3
AssertionError:train: No labels found in D:\code\datasets\HIT-UAV\train.cache, can not starttraining. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
问题解决
这是因为【datasets.py】中的图片路径设置的不对
解决方案如下:
1.打开在utils/dataloaders.py
2.打开之后,按【Ctrl】+【F】打开搜索功能,输入【Define label 】找到下面的一行内容:
sa, sb =f'{os.sep}images{os.sep}',f'{os.sep}labels{os.sep}' # /images/,/labels/ substrings
3.由于我数据集图片放在了JPEGImages文件夹内:需要把【JPEGImages】替换掉images
![](https://i-blog.csdnimg.cn/blog_migrate/704de9385fe6191b7770d64c6b82011f.png)
再次运行【trian.py】
python train.py --img 640 --batch 16 --epochs 100 --data data/HIT-UAVyolo.yaml--weights yolov5s.pt --device 0
成功
关于Linux上yolov3/v5环境配置及训练过程,可以参考:
(linux)yolov5/v3-pytorch目标检测1:环境配置gpu+anaconda+pycham+ RTX2080ti 笔记_chao_xy的博客-CSDN博客
(linux)yolov5/v3-pytorch目标检测2:训练自己的数据集,gpu,pycharm, RTX2080ti,单/多显卡训练,笔记_chao_xy的博客-CSDN博客