《用于生成filelist的sh文件》
#!/usr/bin/env sh
DATA=/mnt/LinuxShare/caffe_project/data
MY=./
echo "Create test.txt..."
rm -rf $MY/test.txt
find $DATA/test/pos/ -name "*.jpg" | cut -d '/' -f 7-9 | sed "s/$/ 1/">>$MY/test.txt
find $DATA/test/neg/ -name "*.jpg" | cut -d '/' -f 7-9 | sed "s/$/ 0/">>$MY/test.txt
echo "Create train.txt..."
rm -rf $MY/train.txt
find $DATA/train/pos/images -name "*.jpg" | cut -d '/' -f 7-10 | sed "s/$/ 1/">>$MY/train.txt
find $DATA/train/neg/images -name "*.jpg" | cut -d '/' -f 7-10 | sed "s/$/ 0/">>$MY/train.txt
echo "All done"
《用于生成lmdb数据的sh文件》
#!/usr/bin/env sh
# Create the imagenet lmdb inputs
# N.B. set the path to the imagenet train + val data dirs
set -e
PRONAME=CNN_classify
DATA=/mnt/LinuxShare/caffe_project/
LMDB_DATA=/home/zac/caffe_project/
TOOLS=/mnt/LinuxShare/caffe/build/tools
TRAIN_DATA_ROOT=/mnt/LinuxShare/caffe_project/data/
VAL_DATA_ROOT=/mnt/LinuxShare/caffe_project/data/
# Set RESIZE=true to resize the images to 256x256. Leave as false if images have
# already been resized using another tool.
RESIZE=true
if $RESIZE; then
RESIZE_HEIGHT=8
RESIZE_WIDTH=32
else
RESIZE_HEIGHT=0
RESIZE_WIDTH=0
fi
if [ ! -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."
exit 1
fi
if [ ! -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."
exit 1
fi
echo "Creating train lmdb..."
echo $RESIZE_HEIGHT
echo $RESIZE_WIDTH
GLOG_logtostderr=1 $TOOLS/convert_imageset \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle=1 \
--encode_type='jpg'\
$TRAIN_DATA_ROOT \
$DATA/train.txt \
$LMDB_DATA/lane_train_lmdb
echo RESIZE_WIDTH
echo RESIZE_HEIGHT
echo "Creating val lmdb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle=1 \
--encode_type='jpg'\
$VAL_DATA_ROOT \
$DATA/test.txt \
$LMDB_DATA/lane_test_lmdb
echo "Done."
《用于生成meanfile的文件》
#!/usr/bin/env sh
# Compute the mean image from the imagenet training lmdb
# N.B. this is available in data/ilsvrc12
EXAMPLE=/home/zac/caffe_project/lane_detect
DATA=/home/zac/caffe_project/lane_detect
TOOLS=/mnt/LinuxShare/caffe/build/tools
$TOOLS/compute_image_mean $EXAMPLE/lane_train_lmdb \
$DATA/imagenet_mean.binaryproto
echo "Done."
《训练CNN网络》
#!/usr/bin/env sh
set -e
/mnt/LinuxShare/caffe/build/tools/caffe train\
--solver=/mnt/LinuxShare/caffe_project/lane_detect/solver.prototxt $@