Before using Caffe, we need to prepare data (mainly pictures)to feed the model.
Execute environment:
All the scripts has been put in the folder ~/caffe/caffe/data/myself
The current path is : ~/caffe/caffe/data/myself$
1. Resize(This has been integrated into the step3 in our new version).
We first resize our pictures to 256x256 by using
resizeImage.sh
for name in /path/to/imagenet/val/*.JPEG; do
convert -resize 256x256\! $name $name
done
2. Convert to lmdbFirstly, We can use the script as follows to create the file list.
File Name: creatFilelist.sh
Code:#!/usr/bin/env sh
# creat the file list
DATA=.
echo "Create train.txt..."
rm -i $DATA/train.txt
find $DATA/cats/ -name '*.jpg' | cut -d '/' -f3 | sed "s/$/ 1/">>$DATA/train.txt
find $DATA/birds/ -name '*.jpg' | cut -d '/' -f3 | sed "s/$/ 2/">>$DATA/tmp.txt
cat $DATA/tmp.txt>>$DATA/train.txt
rm -i $DATA/tmp.txt
echo "Done.."
whereas the folder containing pictures are in current path, the folder 'cats' contains pictures of cats and the folder 'birds' contains pictures of birds.
Secondly, we can use the following script to convert the images to lmdb
File Name: convertImages.sh
Code:#!/usr/bin/env sh
# conver pictures to the lmdb file
DATA=.
rm -ri $DATA/img_train_lmdb
../../build/tools/convert_imageset --shuffle \
--resize_height=256 --resize_width=256 \
/home/liu/caffe/caffe/data/myself/ $DATA/train.txt $DATA/img_train_lmdb
3. Calculate the mean value
By calculating the mean value we can get higher speed and accuracy
File Name:make_myself_mean
Code:#!/usr/bin/env sh
# Compute the mean image from the imagenet training lmdb
# N.B. this is available in data/ilsvrc12
EXAMPLE=.
DATA=.
TOOLS=../../build/tools
$TOOLS/compute_image_mean $EXAMPLE/img_train_lmdb \
$DATA/img_mean.binaryproto
echo "Done."
reference:
1. Caffe学习系列(12):训练和测试自己的图片 - denny402 - 博客园 http://www.cnblogs.com/denny402/p/5083300.html