一、环境配置 1.安装NVIDIA显卡驱动+cuda+cudnn配置深度学习环境 2.安装OPENCV libopencv-dev 通过apt安装,是opencv 2的dev集合,支持C++头文件 sudo apt install python3-opencv libopencv-dev 二、模型训练 可主要参考 yolo-fastest,次要参考 darknet
git clone https://github.com/dog-qiuqiu/Yolo-Fastest.git cd Yolo-Fastest vim MakeFile
GPU=1 to build with CUDA to accelerate by using GPU (CUDA should be in /usr/local/cuda) 没有 GPU 设置为 0,有GPU且设置好 CUDA,设置为1 CUDNN=1 to build with cuDNN v5-v7 to accelerate training by using GPU (cuDNN should be in /usr/local/cudnn) cudnn 和cuda 一般一起安装,上面为0,则这个也为0 CUDNN_HALF=1 to build for Tensor Cores (on Titan V / Tesla V100 / DGX-2 and later) speedup Detection 3x, Training 2x OPENCV=1 to build with OpenCV 4.x/3.x/2.4.x - allows to detect on video files and video streams from network cameras or web-cams 已安装 opencv 则设置 为 1,否则为 0 Set the other options in the Makefile according to your need. 编译工程 make -j2 1.2 生成 COCO 预训练模型./darknet partial ./ModelZoo/yolo-fastest-1.0_coco/yolo-fastest.cfg ./ModelZoo/yolo-fastest-1.0_coco/yolo-fastest.weights yolo-fastest.conv.109 109 1.3 训练配置文件修改mkdir pupildata cp ./ModelZoo/yolo-fastest-1.0_coco/yolo-fastest.cfg ./pupildata/pupil.cfg
1.6进行训练./darknet detector train ./pupildata/pupil.data ./pupildata/pupil.cfg yolo-fastest.conv.109 视情况而定是否需要添加 -dont_show 如果出現內存溢出的报错:CUDA Error: out of memory 将pupil.cfg配置文件里的batch=128改小即可。 运行如下指令,根据自己的路径进行修改,即可推理测试 ./darknet detector test ./pupildata/pupil.data ./pupildata/pupil.cfg ./backup/pupil_last.weights data/dog.jpg -i 0 -thresh 0.25 三、模型转换(多方尝试失败) 由于想部署到移动端,想darknet模型转caffe模型,再用MNN工具转换,部署。 参考:https://github.com/dog-qiuqiu/MobileNet-Yolo#darknet2caffe-tutorial conda install -c defaults caffe 或者 conda install -c defaults caffe-gpu pip3 install torch 原代码python2跟pyhton3不兼容的问题 prototxt.py里直接执行import caffe.proto.caffe_pb2 as caffe_pb2不用try block.has_key('name') 替换成'name' in block 寻路无果,还是换了方向,用tensorflow的方式训练模型,还直接些,首先git个新项目 git clone https://github.com/yss9701/Ultra96-Yolov4-tiny-and-Yolo-Fastest.git 里面有两个项目yolov4跟yolo-fastest,我们只跑yolo-fasttest,将项目根目录中 整个modle_data文件夹复制到/yolo_fastest_tensorflow2/ nets文件夹里的ious.py和loss.py复制到./yolo_fastest_tensorflow2/nets/目录中 如上图根据自己的情况,把文件路径准备好,进入到./yolo_fastest_tensorflow2/目录,运行脚本python train.py,缺啥moudle补啥, 开始训练>>>>>>>>> 五、再次模型转换keras转tensorflow 我怎么说再呢,多么痛的领悟,我还是绕远路了 n n 用主目录的脚本keras_to_tensorflow.py进行h5转pb模型,还在./yolo_fastest_tensorflow2/目录下,运行如下命令 python ../keras_to_tensorflow.py --input_model="./logs_7/ep100-loss0.221-val_loss0.216.h5" --input_model_json="./logs_7/model_config.json" --output_model="./yolo_fastest.pb" 还是有报错:module 'tensorflow_core.keras.backend' has no attribute 'get_session' 在这又折腾很久,知道版本问题,可是就不知道用那个版本行,多次尝试,才发现gitbub的文档有说明,要用tensorflow=1.15.2版本,不过pip已经没有该版本,将tensorflow的版本更改为tensorflow=1.15.0也是可以,我重新conda建个环境 conda create -n tensorflow1 tensorflow=1.15.0 会根据tensorflow的要求配置相应环境,python都会默默装上 再次运行脚本,还算是出现报错: original_keras_version = f.attrs['keras_version'].decode('utf8') 解决办法: pip install h5py==2.10 -i https://pypi.tuna./simple/ 终于得到pb模型,这次成功啦,VVVV ————————————————————— 附:相关值得参考连接 https://zhuanlan.zhihu.com/p/291215818# https://hideousmon./2020/10/02/Yolo-Fastest-%E8%AE%AD%E7%BB%83%E6%8E%92%E5%9D%91%E8%AE%B0%E5%BD%95/ 训练自己的数据: https://blog.csdn.net/hesongzefairy/article/details/107183162 |
|