caffe 制作lmdb数据集

时间:2021-04-17 03:59:49
1生成lmdb文件
caffe中通过图像生成lmdb格式文件的程序为examples/imagenet/create_imagenet.sh。该文件调用
build/tools/convert_imageset(对应的源码为tools/convert_imageset.cpp)。

为了不改变原来的程序,在examples内新建自己的工程文件夹my_experiment。


复制create_imagenet.sh,并修改:

1 #!/usr/bin/env sh
2 # Create the imagenet lmdb inputs
3 # N.B. set the path to the imagenet train + val data dirsset e
4
5 EXAMPLE=examples/testCreateLmDB
6 DATA=/home/xxx/database/CASIA
7 TOOLS=build/tools
8
9 TRAIN_DATA_ROOT=/home/xxx/database/CASIA/
10 VAL_DATA_ROOT=/home/xxx/database/CASIA/
11
12 # Set RESIZE=true to resize the images to 256x256. Leave as false
if images have
13 # already been resized using another tool.
14 RESIZE=true
15 if $RESIZE; then
16 RESIZE_HEIGHT=128
17 RESIZE_WIDTH=128
18 else
19 RESIZE_HEIGHT=0
20 RESIZE_WIDTH=0
21 fi
22
23 if [ ! d
"$TRAIN_DATA_ROOT" ]; then
24 echo "Error: TRAIN_DATA_ROOT is not a path to a directory:
$TRAIN_DATA_ROOT"
25 echo "Set the TRAIN_DATA_ROOT variable in create_imagenet.sh to
the path" \
26 "where the ImageNet training data is stored."
27 exit 1
28 fi
2223 if [ ! d"$TRAIN_DATA_ROOT" ]; then24 echo "Error: TRAIN_DATA_ROOT is not a path to a directory:$TRAIN_DATA_ROOT"25 echo "Set the TRAIN_DATA_ROOT variable in create_imagenet.sh tothe path" \26 "where the ImageNet training data is stored."27 exit 1
28 if
29
30 if [ ! d
"$VAL_DATA_ROOT" ]; then
31 echo "Error: VAL_DATA_ROOT is not a path to a directory:
$VAL_DATA_ROOT"
32 echo "Set the VAL_DATA_ROOT variable in create_imagenet.sh to the
path" \
33 "where the ImageNet validation data is stored."
34 exit 1
35 fi
36
37 echo "Creating train lmdb..."
38
39 GLOG_logtostderr=1 $TOOLS/convert_imageset \
40 resize_
height=$RESIZE_HEIGHT \
41 resize_
width=$RESIZE_WIDTH \
42 shuffle
\
43 $TRAIN_DATA_ROOT \
44 $DATA/train_all.txt \
45 $EXAMPLE/face_train_lmdb
46
47 echo "Creating val lmdb..."
48
49 #GLOG_logtostderr=1 $TOOLS/convert_imageset \
50 # resize_
height=$RESIZE_HEIGHT \
51 # resize_
width=$RESIZE_WIDTH \
52 # shuffle
\
53 # $VAL_DATA_ROOT \
54 # $DATA/val.txt \
55 # $EXAMPLE/face_val_lmdb
56
57 echo "Done."


之后,在caffe根目录打开终端,并输入shexamples/testCreateLmDB/create_imagenet.sh

注意自己的路径是否正确,标签问题是否齐全;

如果正确的话就会出现整整的文件处理:

2 生成mean.binaryproto文件

之后就是制作其平均数据集

为了不更改源文件,在自己文件夹内复制粘贴make_imagenet_mean.sh,并更改:

1 #!/usr/bin/env sh
2 # Compute the mean image from the imagenet training lmdb
3 # N.B. this is available in data/ilsvrc12
4
5 EXAMPLE=examples/testCreateLmDB
6 DATA=examples/testCreateLmDB
7 TOOLS=build/tools
8
9 $TOOLS/compute_image_mean $EXAMPLE/ train_lmdb \
10 $DATA/train_mean.binaryproto
11
12 echo "Done."
说明:
1) 程序第3行EXAMPLE为当前程序所在目录(实际上为lmdb库文件所
在目录。见第9行)。
2) 程序第4行DATA为需要生成的face_train_mean.binaryproto所在目录(见程序
第10行)。
3) 生成的train_mean.binaryproto文件大小为192KB。

注意:先对整个文件夹赋予一定的可操作权限,chmod 775 filename;

 之后在linux系统中,.sh文件的运行命令是先跳转到包含该命令的文件中,之后在终端输入 sh make_imagenet_mean.sh即可


参考:http://www.cnblogs.com/darkknightzh/p/5909121.html