Nowadays, I am in a project aimed at detect lanes and vehicles of the highway, in which SSD model is used.So This series will be updated to record our work.
In this page, I'll write down the process of how we run the example demo, including environment preparation, configuration, especially some common problem occurred and its solution .
1. clone the source code from Github. Then there may be such a error:
wangyufan@USTC-176:~$ git clone https://github.com/weiliu89/caffe.git
Cloning into 'caffe'...
remote: Counting objects: 30179, done.
remote: Compressing objects: 100% (10/10), done.
Receiving objects: 14% (4256/30179), 2.71 MiB | 0 bytes/s
error: RPC failed; curl 56 GnuTLS recv error (-54): Error in the pull function.
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Try another wifi(higher speed) then the problem can be solved.
Then, modify your Makefile.config and add it to caffe document, the Makefile is the exact file for build, which will call your own configuration file. What's more , Makefile.config.example used by the demo writer.
2. compile caffe
:make -j14
3. compile pycaffe, but before that, the python environment variable should be done.
add python path into bashrc
:vim ~/.bashrc
use 'source' to make the file go into effect,source的程序主体是bash,脚本中的$0变量的值是bash,而且由于作用于当前bash环境,脚本中set的变量将直接起效.
:source ~/.bashrc
:make pycaffe -j14
4. tar data,新建文件夹/home/data,将数据集拷贝至此
:tar -xvf 压缩的数据集文件名
(巨大突破、、、、终于在ubuntu装好了搜狗输入法!!!!终于可以敲汉字了!!!!!)
tar
-c: 建立压缩档案
-x:解压
-t:查看内容
-r:向压缩归档文件末尾追加文件
-u:更新原压缩包中的文件
这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个。下面的参数是根据需要在压缩或解压档案时可选的。
-z:有gzip属性的
-j:有bz2属性的
-Z:有compress属性的
-v:显示所有过程
-O:将文件解开到标准输出
下面的参数-f是必须的
-f: 使用档案名字,这个参数是最后一个参数,后面只能接档案名。
5. transform image format from JPG to lmdb
there may be a error :
*** Error in `/home/wangyufan/caffe/data/VOC0712/../../build/tools/get_image_size': free(): invalid pointer: 0x000000000250a2c0 ***
很可能是缺少libtcmalloc-minimal4库,首先安装
:sudo apt-get install libtcmalloc-minimal4
然后打开~/.bashrc文件在文件末尾添加如下代码:
export LD_PRELOAD=/usr/lib/libtcmalloc_minimal.so.4
6.训练模型前先观察显卡使用情况
否则内存不够时会报错:F0402 16:44:02.225286 23077 syncedmem.cpp:56] Check failed: error == cudaSuccess (2 vs. 0) out of memory
:watch -n 1 nvidia-smi
:top
shift+m
7. 把下载好的预训练模型文件放在caffe/models/VGGNet/目录下
fine tune就是用别人训练好的模型,加上我们自己的数据,来训练新的模型。fine tune相当于使用别人的模型的前几层,来提取浅层特征,然后在最后再落入我们自己的分类中。
好处在于不用完全重新训练模型,从而提高效率,因为一般新训练模型准确率都会从很低的值开始慢慢上升,但是fine tune能够让我们在比较少的迭代次数之后得到一个比较好的效果。
我们用作者训练的一个变种VGG,下载地址:http://cs.unc.edu/~wliu/projects/ParseNet/VGG_ILSVRC_16_layers_fc_reduced.caffemodel
否则下一步训练时会报错:F0402 16:41:22.895117 22477 io.cpp:63] Check failed: fd != -1 (-1 vs. -1) File not found: models/VGGNet/VGG_ILSVRC_16_layers_fc_reduced.caffemodel
8 .修改训练文件配置
微调时的基本学习速率不能太大,base_lr从0.01变成了0.001,
caffe/examples/ssd/ssd_pascal.pygpus = "0,1,2,3" # 使用哪块GPU
改为:
gpus = "1" # 只有1号GPU有足够空间
solver_para={'snapshot':5000, #每迭代5000次存储模型记录,否则出错又会从0开始训练
···}
9.训练,得到每5000次训练产生的所有模型
训练方法有两种python/shell,
方法1:
python examples/ssd/ssd_pascal.py方法2::./build/tools/caffe train -solver
resuming from models/VGGNet/VGG_ILSVRC_16_layers_fc_reduced.caffesolver
Iteration 15000(接着上次训练继续训练)
./build/tools/caffe train -weights
Finetuning from models/VGGNet/VGG_ILSVRC_16_layers_fc_reduced.caffemodel
Iteration 0(重新训练)
9. 测试
10. (next step) loss /ap/pr 曲线可视化
本文详细介绍了如何在Ubuntu环境下搭建并运行SSD模型的过程,包括从源码克隆、环境配置到模型微调等关键步骤,并针对过程中可能出现的问题提供了解决方案。
2113

被折叠的 条评论
为什么被折叠?



