The personal Practice code is as follows:
#!/usr/bin/env sh# Create the imagenet lmdb inputs# n.b.SetThe path to the Imagenet train +Val Data dirsSet-Eexample=/home/wp/caffe/caffe-master/myself/00bDATA=/home/wp/caffe/caffe-master/myself/00bTOOLS=build/Toolstrain_data_root=/home/wp/caffe/caffe-master/myself/00b/train/Val_data_root=/home/wp/caffe/caffe-master/myself/00b/val/# Set RESIZE=trueTo resize the images to 256x256. Leave as false ifimages have# already been resizedusinganother tool. RESIZE=trueif$RESIZE; then resize_height.=101Resize_width=101ElseResize_height=0Resize_width=0fiif[!-D"$TRAIN _data_root" ]; Then Echo"Error:train_data_root is not a path to a directory: $TRAIN _data_root"Echo"Set the train_data_root variable in create_imagenet.sh to the path" "where the ImageNet training data is stored."Exit1fiif[!-D"$VAL _data_root" ]; Then Echo"Error:val_data_root is not a path to a directory: $VAL _data_root"Echo"Set the val_data_root variable in create_imagenet.sh to the path" "where the ImageNet validation data is stored."Exit1Fiecho"Creating train Lmdb ..."Glog_logtostderr=1$TOOLS/Convert_imageset--resize_height=$RESIZE _height--resize_width=$RESIZE _width--Shuffle $TRAIN _data_root $DATA/train.txt $EXAMPLE/00b_train_lmdbecho"Creating val Lmdb ..."Glog_logtostderr=1$TOOLS/Convert_imageset--resize_height=$RESIZE _height--resize_width=$RESIZE _width--Shuffle $VAL _data_root $DATA/val.txt $EXAMPLE/00b_val_lmdbecho"Done ."# CD CAFFE/caffe-master# Sh./myself/00b/create_lmdb.sh
Results two files were generated: 00b_train_lmdb.sh; 00b_val_lmdb.sh
Reference one:
Because of the more parameters, we can write a sh script to execute the command:
First, create the sh script file:
# sudo VI examples/images/create_lmdb.sh
Edit, enter the following code and save
[CPP]
#!/usr/bin/en shdata=examples/imagesrm-rf $DATA/img_train_lmdbbuild/tools/convert_imageset--shuffle--resize_ height=256--resize_width=256/home/xxx/caffe/examples/images/$DATA/train.txt $DATA/img_train_lmdb
Note:/convert_imageset--shuffle \//Use Shuffle
- --resize_height=--resize_width=256 \//The size of the picture will call OpenCV to get a fixed size
- Absolute storage path for/opt/modules/caffe-master/examples/images/\//Picture
- List information for/opt/modules/caffe-master/examples/images/train.txt \//Files
- /opt/modules/caffe-master/examples/images/img_train_lmdb \//The path of the resulting database save
Set the parameter-shuffle to disturb the picture order. Set parameters-resize_height and-resize_width to change all picture sizes to 256*256.
/home/xxx/caffe/examples/images/the absolute path saved for the picture.
Finally, run the script file
[CPP]
# sudo sh examples/images/create_lmdb.sh
A folder named Img_train_lmdb is generated in the examples/images/directory, and the file is the db file we need .
The image data is converted to a db (Leveldb/lmdb) file.
Reference two:
Create_filelist.sh then write a script file create_lmdb.sh, calling the Convert_imageset command to convert the data format.
# sudo vi examples/myfile/create_lmdb.sh
Insert:
#!/usr/bin/env shmy=examples/Myfileecho"Create train Lmdb."RM-RF $MY/img_train_lmdbbuild/tools/Convert_imageset--Shuffle--resize_height=256--resize_width=256/home/xxx/caffe/data/re/ $MY/ train.txt $MY/img_train_lmdbecho "create test Lmdb. "img_test_ Lmdbbuild/tools/convert_imageset--shuffle--resize_ Width=256--resize_height=256/home/xxx/caffe/data/ Re/ $MY/test.txt $MY/ Img_test_lmdbecho "all done.
Because the picture size is different, I convert it to 256*256 size uniformly. After successful operation, two folders Img_train_lmdb and Img_test_lmdb are generated under Examples/myfile, respectively, to save the image converted Lmdb file.
7.caffe data preprocessing converted into Lmdb format create_lmdb.sh