1 环境搭建
1.1 在官方仓库的给定的使用python=3.9版本,则使用conda创建对应虚拟环境。
conda create -n yolov10 python=3.9
1.2 切换到对应虚拟环境
conda activate yolov10
1.3 在指定目录下克隆yolov10官方仓库代码
git clone https://github.com/THU-MIG/yolov10.git
1.4 进入对应本地yolov10目录下安装对应依赖项
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
如果使用 pip install -r requirements.txt 命令,可能会遇到错误
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001A7EADD6CD0>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/48/f4/d0b61525a3d3db78636f1937d1bc24cbb39abc57484a545b72b6ab35c114/torch-2.0.1-cp39-cp39-win_amd64.whl
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001A7EADD6CA0>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/48/f4/d0b61525a3d3db78636f1937d1bc24cbb39abc57484a545b72b6ab35c114/torch-2.0.1-cp39-cp39-win_amd64.whl
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001A7EB200400>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/48/f4/d0b61525a3d3db78636f1937d1bc24cbb39abc57484a545b72b6ab35c114/torch-2.0.1-cp39-cp39-win_amd64.whl
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001A7EB1F1F10>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/48/f4/d0b61525a3d3db78636f1937d1bc24cbb39abc57484a545b72b6ab35c114/torch-2.0.1-cp39-cp39-win_amd64.whl
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001A7EB1F15B0>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/48/f4/d0b61525a3d3db78636f1937d1bc24cbb39abc57484a545b72b6ab35c114/torch-2.0.1-cp39-cp39-win_amd64.whl
ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/48/f4/d0b61525a3d3db78636f1937d1bc24cbb39abc57484a545b72b6ab35c114/torch-2.0.1-cp39-cp39-win_amd64.whl (Caused by ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001A7ECD869A0>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)'))
1.5 安装对应的包
pip install -e .
2 模型训练及测试效果
2.1 在Roboflow下载数据集并导出为YOLO的数据集( 或者在Roboflow制作自己的数据集并导出为YOLO的数据集)。参考Roboflow 使用详解:数据集标注、训练及下载
2.3 把data.yaml复制到C:\Users\WYX\Desktop\code\yolov10-main\ultralytics\cfg\datasets目录下,重命名为VOC_new.yaml,并修改相应的配置。
2.4 模型训练
需要修改C:\Users\WYX\Desktop\code\yolov10-main\ultralytics\models\yolov10\train.py。
训练
yolo detect train data=VOC_new.yaml model=yolov10n.yaml epochs=500 batch=32 imgsz=640 device=cpu
2.5 模型验证
yolo val model=jameslahm/yolov10n data=VOC_new.yaml batch=32
2.6 预测并导出
yolo export model=jameslahm/yolov10n format=onnx opset=13 simplify