参考
- https://docs.ultralytics.com/zh/quickstart/#use-ultralytics-with-python
- https://pytorch.org/get-started/locally/
- https://www.zhihu.com/question/275575243
- https://github.com/onnx/onnx/issues/5773
- https://stackoverflow.com/questions/72352528/how-to-fix-winerror-206-the-filename-or-extension-is-too-long-error/76452218#76452218
环境
环境 | 版本 | 说明 |
---|---|---|
Windows | Windows 10 专业版 22H2 19045.4170 | |
VS Code | 1.88.1 | |
Git客户端 | 2.43.0.windows.1 | |
Python | 3.12 | |
pip | 3.12 | |
ultralytics | 8.1.47 | pip 包 |
torch | 2.2.2 | pip 包 |
torchaudio | 2.2.2 | pip 包 |
torchvision | 0.17.2 | pip 包 |
onnx | 1.16.0 | pip 包 |
正文
-
安装 python3
-
设置pip源:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
-
安装yolov:
pip install ultralytics
-
安装torch,https://pytorch.org/get-started/locally/
pip3 install torch torchvision torchaudio
-
设置git命令终端代理:(需要先打开梯子,并且本地端口对应,不明白梯子或者如果没有梯子就跳过这一步)
git config --global http.proxy 127.0.0.1:7890 git config --global https.proxy 127.0.0.1:7890
-
修改注册表,win+r 打开运行,输入regedit ,进入注册表找到:
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
,修改LongPathsEnabled=1
-
执行;
pip install --no-cache "onnx>=1.12.0"
。 -
尝试运行(所有本文章内的文件都会自动去下载,所以只需要下面这部分代码就可以尝试体验)
代码是演示了完整流程:创建模型/加载模型/训练模型/评估/检测/导出onnx模型from ultralytics import YOLO # Create a new YOLO model from scratch model = YOLO('yolov8n.yaml') # Load a pretrained YOLO model (recommended for training) model = YOLO('yolov8n.pt') # Train the model using the 'coco128.yaml' dataset for 3 epochs results = model.train(data='coco128.yaml', epochs=3) # Evaluate the model's performance on the validation set results = model.val() # Perform object detection on an image using the model results = model('https://ultralytics.com/images/bus.jpg') # Export the model to ONNX format success = model.export(format='onnx')