EXP: Object Detection(SSD) in Transportation(1)

本文详细介绍了如何在Ubuntu环境下搭建并运行SSD模型的过程,包括从源码克隆、环境配置到模型微调等关键步骤,并针对过程中可能出现的问题提供了解决方案。
部署运行你感兴趣的模型镜像

    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.py
gpus = "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 曲线可视化











您可能感兴趣的与本文相关的镜像

Llama Factory

Llama Factory

模型微调
LLama-Factory

LLaMA Factory 是一个简单易用且高效的大型语言模型(Large Language Model)训练与微调平台。通过 LLaMA Factory,可以在无需编写任何代码的前提下,在本地完成上百种预训练模型的微调

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值