版权声明:原创博客未经允许请勿转载!https://mp.csdn.net/postedit/83615211
(一)系统版本:
# nvidia-smi
Thu Nov 1 01:29:23 2018
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.87 Driver Version: 390.87 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 TITAN Xp Off | 00000000:06:00.0 On | N/A |
| 36% 59C P2 161W / 250W | 4726MiB / 12195MiB | 51% Default |
+-------------------------------+----------------------+----------------------+
| 1 TITAN Xp Off | 00000000:84:00.0 Off | N/A |
| 23% 23C P8 16W / 250W | 12MiB / 12196MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
+-----------------------------------------------------------------------------+
2.cuda与cudnn版本:
# cat /usr/local/cuda/version.txt
CUDA Version 8.0.44
# cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 5
#define CUDNN_MINOR 1
#define CUDNN_PATCHLEVEL 10
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#include "driver_types.h"
3.系统版本
#cat /proc/version
Linux version 3.10.0-693.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Tue Aug 22 21:09:27 UTC 2017
(二)安装SSD,源代码:https://github.com/weiliu89/caffe/tree/ssd
(三)复现SSD论文实验后面填坑。
(四)安装DSOD
Create a subfolder dsod under example/, add files DSOD300_pascal.py, DSOD300_pascal++.py, DSOD300_coco.py, score_DSOD300_pascal.py and DSOD300_detection_demo.py to the folder example/dsod/.
Create a subfolder grp_dsod under example/, add files GRP_DSOD320_pascal.py and score_GRP_DSOD320_pascal.py to the folder example/grp_dsod/.
Replace the file model_libs.py in the folder python/caffe/ with ours.
2.具体代码详见:https://github.com/szq0214/DSOD
3.训练
Train a DSOD model on VOC 07+12:
python examples/dsod/DSOD300_pascal.py
Train a DSOD model on VOC 07++12:
python examples/dsod/DSOD300_pascal++.py
Train a DSOD model on COCO trainval:
python examples/dsod/DSOD300_coco.py
4.问题
Check failed: mdb_status == 0 (2 vs. 0) No such file or directory
因为显卡内存小,有说可能是因为batch_size设置的过大的原因
源码:batch_size = 32
accum_batch_size = 128
/home/caffe-ssd/examples/dsod +273
修改为:batch_size =4# 32
accum_batch_size =16# 128
Check failed: error == cudaSuccess (10 vs. 0) invalid device ordinal
这是由于GPU数量不匹配造成的,需要将solver.prototxt文件中的device_id项改为自己的GPU块数,一块就是0,两块就是1,以此类推。
example/dsod/DSOD300_pascal.py +278 gpus = "0,1,2,3,4,5,6,7" 改为gpus = "0”
(五)训练行人检测数据
# mkdir dsod_train
# cp -rf /home/caffe-ssd/data/VOC0712/* /home/caffe-ssd/data/dsod_train/
3. 在data下新建文件sample,在sample下新建dsod_train与mydatasets。
4. 准备数据,行人数据是标准的VOC数据格式,传输数据到mydatasets中,有以下几个方法:
安装FileZilla软件,它是免费开源的FTP软件,网上教程很多。
安装方法:
#apt-get install lrzsz
从服务端发送文件到客户端:sz后回车弹出选择的文件。
#sftp:/home/caffe-ssd/data/sample/mydatasets> put Z:\深度学习\Annotations /home/caffe-ssd/data/sample/mydatasets/
5. 准备好了数据,解压后开始转成LMDB的格式。首先修改data/dsod/creat_list.sh,代码如下:
#!/bin/bash
#root_dir=/home/caffe-ssd/data/VOCdevkit/
root_dir=/home/caffe-ssd/data/sample/
sub_dir=ImageSets/Main
bash_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
for dataset in trainval test
do
dst_file=$bash_dir/$dataset.txt
if [ -f $dst_file ]
then
rm -f $dst_file
fi
#for name in VOC2007 VOC2012
for name in mydatasets
do
# if [[ $dataset == "test" && $name == "VOC2012" ]]
# then
# continue
# fi
echo "Create list for $name $dataset..."
dataset_file=$root_dir/$name/$sub_dir/$dataset.txt
img_file=$bash_dir/$dataset"_img.txt"
cp $dataset_file $img_file
sed -i "s/^/$name\/JPEGImages\//g" $img_file
sed -i "s/$/.jpg/g" $img_file
label_file=$bash_dir/$dataset"_label.txt"
cp $dataset_file $label_file
sed -i "s/^/$name\/Annotations\//g" $label_file
sed -i "s/$/.xml/g" $label_file
paste -d' ' $img_file $label_file >> $dst_file
rm -f $label_file
rm -f $img_file
done
# Generate image name and size infomation.
if [ $dataset == "test" ]
then
$bash_dir/../../build/tools/get_image_size $root_dir $dst_file $bash_dir/$dataset"_name_size.txt"
fi
# Shuffle trainval file.
if [ $dataset == "trainval" ]
then
rand_file=$dst_file.random
cat $dst_file | perl -MList::Util=shuffle -e 'print shuffle();' > $rand_file
mv $rand_file $dst_file
fi
done
~
~
~
运行./create_list.sh
/home/caffe-ssd/data/dsod_train
Create list for mydatasets trainval...
Create list for mydatasets test...
I1101 11:48:46.939064 3113 get_image_size.cpp:61] A total of 2171 images.
I1101 11:48:51.158903 3113 get_image_size.cpp:100] Processed 1000 files.
I1101 11:48:55.381808 3113 get_image_size.cpp:100] Processed 2000 files.
I1101 11:48:56.103267 3113 get_image_size.cpp:105] Processed 2171 files.
在data/dsod_train里面会重新生成三个文件(以前的不用删,运行程序会直接覆盖以前的)
-rw-r--r--. 1 root root 140915 Nov 1 04:01 test.txt
-rw-r--r--. 1 root root 38978 Nov 1 04:02 test_name_size.txt
-rw-r--r--. 1 root root 563089 Nov 1 04:01 trainval.txt
root@8606b1e08332:/home/caffe-ssd/data/train_sample# vim test.txt
sample/JPEGImages/03_245525.jpg sample/Annotations/03_245525.xml
sample/JPEGImages/01_77660.jpg sample/Annotations/01_77660.xml
sample/JPEGImages/02_211004.jpg sample/Annotations/02_211004.xml
sample/JPEGImages/02_468307.jpg sample/Annotations/02_468307.xml
sample/JPEGImages/03_831804.jpg sample/Annotations/03_831804.xml
sample/JPEGImages/04_796466.jpg sample/Annotations/04_796466.xml
sample/JPEGImages/03_2584905.jpg sample/Annotations/03_2584905.xml
sample/JPEGImages/03_260282.jpg sample/Annotations/03_260282.xml
sample/JPEGImages/03_2277306.jpg sample/Annotations/03_2277306.xml
root@8606b1e08332:/home/caffe-ssd/data/train_sample# vim trainval.txt
sample/JPEGImages/03_1164425.jpg sample/Annotations/03_1164425.xml
sample/JPEGImages/04_41943.jpg sample/Annotations/04_41943.xml
sample/JPEGImages/01_277407.jpg sample/Annotations/01_277407.xml
sample/JPEGImages/01_223079.jpg sample/Annotations/01_223079.xml
sample/JPEGImages/01_69969.jpg sample/Annotations/01_69969.xml
sample/JPEGImages/01_371695.jpg sample/Annotations/01_371695.xml
sample/JPEGImages/03_123987.jpg sample/Annotations/03_123987.xml
sample/JPEGImages/02_185663.jpg sample/Annotations/02_185663.xml
sample/JPEGImages/04_31490.jpg sample/Annotations/04_31490.xml
sample/JPEGImages/01_208821.jpg sample/Annotations/01_208821.xml
root@8606b1e08332:/home/caffe-ssd/data/train_sample# vim test_name_size.txt
03_245525 480 640
01_77660 480 640
02_211004 480 640
02_468307 480 640
03_831804 480 640
04_796466 480 640
03_2584905 480 640
03_260282 480 640
修改caffe-ssd/data/train_sample/labelmap_voc.prototxt 除了background之外改成自己的类别,我的是两类。
# vim labelmap_voc.prototxt
item {
name: "none_of_the_above"
label: 0
display_name: "background"
}
item {
name: "headshoulder"
label: 1
display_name: "headshoulder"
}
item {
name: "ignore"
label: 2
display_name: "ignore"
}
6. 修改data/dsod_train/creat_data.sh
ur_dir=$(cd $( dirname ${BASH_SOURCE[0]} ) && pwd )
root_dir=$cur_dir/../..
cd $root_dir
redo=1
data_root_dir="/home/caffe-ssd/data/sample"
dataset_name="dsod_train"
mapfile="$root_dir/data/$dataset_name/labelmap_voc.prototxt"
anno_type="detection"
db="lmdb"
min_dim=0
max_dim=0
width=0
height=0
extra_cmd="--encode-type=jpg --encoded"
if [ $redo ]
then
extra_cmd="$extra_cmd --redo"
fi
for subset in test trainval
do
python $root_dir/scripts/create_annoset.py --anno-type=$anno_type --label-map-file=$mapfile --min-dim=$min_dim --max-dim=$max_dim --resize-width=$width --resize-height=$height --check-label $extra_cmd $data_root_dir $root_dir/data/$dataset_name/$subset.txt $data_root_dir/$dataset_name/$db/$dataset_name"_"$subset"_"$db examples/$dataset_name
done
修改完后运行./creat_data.sh 。在example/train_sample中生成两个lmdb链接;在/data/sample/dsod_train/lmdb会生成转化好的lmdb文件。
7. 修改example/dsod_train/DSOD300_pascal.py文件
8. 训练 python ./example/dsod_train/DSOD300_pascal.py
明天记录结果和测试效果。