1. 程式人生 > >caffe 製作lmdb資料集

caffe 製作lmdb資料集

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