LMDB是Cafffe中应用的一种数据库,我们常常需要对LMDB进行读写操作,本文介绍如何采用bash脚本进行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/tyd/下载/face_detect # 数据集存放的路经
DATA=/home/tyd/下载/face_detect
TOOLS=/home/tyd/caffe/build/tools # caffe安装的路经
TRAIN_DATA_ROOT=/home/tyd/下载/face_detect/train/ # 训练数据集存放路经
VAL_DATA_ROOT=/home/tyd/下载/face_detect/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
根据上面的脚本示例,按照脚本中的中文注释的地方修改自己实际的路经位置.然后运行脚本:sh **.sh 文件即可.
python 生成LMDB
网络上也有用python制作LMDB数据源的,可以参考:https://zhuanlan.zhihu.com/p/23485774