仅做记录。
YOLOv5代码
报错信息显示显卡的CUDA计算能力和pytorch版本不匹配
安装适用于使用显卡的pytorch
卸载当前版本的pytorch, 重新安装匹配版本
pip uninstall torch
pip uninstall torchvision
pip install torch==1.7.0+cu110 torchvision==0.8.1+cu110 torchaudio===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple/
注意上面的内容要与自己的cuda版本匹配哈,怎么查看当前环境的cuda版本,命令如下:
查看可用cuda最大可用版本:
nvidia-smi
查看当前环境的cuda版本:
nvcc -V
(1)找到log文件的保存地址:
(2)vscode连接上服务器之后,在终端输入:
tensorboard --logdir=/databank/home/**/**/yolov5/runs/train/exp12/ #这里的地址为上述地址
这样就可以啦!!!
CUDA_VISIBLE_DEVICES=0 python train.py --img 640 --batch 16 --epochs 300 --data data/my.yaml --weights weights/yolov5s.pt
注意,原export.py中只能将“.pt”模型转为“.torchscript.pt”,不能转为“.torchscript.ptl”,所以需要稍微修改下代码,具体如下:
把蓝色框中代码注释掉,并写入红色框中代码:
f = file.with_suffix('.torchscript.ptl')
(optimize_for_mobile(ts) if optimize else ts)._save_for_lite_interpreter(str(f))
然后使用如下命令:
python export.py --weights runs/train/exp11/weights/best.pt --include torchscript
Git中提供的android-demo-app模板代码
(1)在MainActivity.java文件中改变自己的图片列表:
private String[] mTestImages = {"aicook1.jpg", "aicook2.jpg", "aicook3.jpg", "test1.png", "test2.jpg", "test3.png"};
(2)在MainActivity.java文件中改成自己的模型:
mModule = LiteModuleLoader.load(MainActivity.assetFilePath(getApplicationContext(), "best.torchscript.ptl"));
BufferedReader br = new BufferedReader(new InputStreamReader(getAssets().open("aicook.txt")));
(3)将PrePostProcessor.java中的mOutputColumn的数值改为自己模型的预测种类+5,例如,如果自己模型可以检测的目标种类为30,则值为30+5=35;
private static int mOutputColumn = 35;
(4)将ObjectDetectionActivity.java文件中的模型也给成自己的:
mModule = LiteModuleLoader.load(MainActivity.assetFilePath(getApplicationContext(), "yolov5s.torchscript.ptl"));
(5)运行demo_app