使用caffe框架制作LMDB数据源代码如下:
#!/usr/bin/env sh
# Create the face_48 lmdb inputs
# N.B. set the path to the face_48 train + val data dirs
EXAMPLE=/home/badoo/PycharmProjects/test/dataset #工作目录
DATA=/home/badoo/PycharmProjects/test/dataset #生成train.txt和test.txt文件的路径
TOOLS=/home/badoo/caffe-ssd/build/tools #指定caffe安装的路径
TRAIN_DATA_ROOT=/home/badoo/PycharmProjects/test/dataset/train/ #训练集数据的路径
VAL_DATA_ROOT=/home/badoo/PycharmProjects/test/dataset/val/ #测试集数据的路径
# Set RESIZE=true to resize the images to 60 x 60. Leave as false if images have
# already been resized using another tool.
RESIZE=true
if $RESIZE; then #对数据进行resize操作
RESIZE_HEIGHT=227
RESIZE_WIDTH=227
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_face_48.sh to the path" \
"where the face_48 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_face_48.sh to the path" \
"where the face_48 validation data is stored."
exit 1
fi
echo "Creating train lmdb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle \
$TRAIN_DATA_ROOT \
$DATA/train.txt \ #训练集的txt文件,存放图片目录和图片类别
$EXAMPLE/face_train_lmdb #训练集lmdb存放位置
echo "Creating val lmdb..."
GLOG_logtostderr=1 $TOOLS/convert_imageset \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle \
$VAL_DATA_ROOT \
$DATA/val.txt \ #验证集的txt文件,存放图片目录和图片类别
$EXAMPLE/face_val_lmdb #验证集lmdb存放位置
echo "Done."
Status API Training Shop Blog About
运行以上脚本就可以了。