LMDB是Cafffe中應(yīng)用的一種數(shù)據(jù)庫创肥,我們常常需要對LMDB進(jìn)行讀寫操作,本文介紹如何采用bash腳本進(jìn)行LMDB的數(shù)據(jù)源制作操作镐躲。
腳本例子
#!/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 # 數(shù)據(jù)集存放的路經(jīng)
DATA=/home/tyd/下載/face_detect
TOOLS=/home/tyd/caffe/build/tools # caffe安裝的路經(jīng)
TRAIN_DATA_ROOT=/home/tyd/下載/face_detect/train/ # 訓(xùn)練數(shù)據(jù)集存放路經(jīng)
VAL_DATA_ROOT=/home/tyd/下載/face_detect/val/ # 測試集存放的路經(jīng)
# 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 # 對數(shù)據(jù)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 \ # 訓(xùn)練集的txt文件, 存放圖片目錄和圖片類別
$EXAMPLE/face_train_lmdb # 訓(xùn)練集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 \ # 驗(yàn)證集的txt文件, 存放圖片目錄和圖片類別
$EXAMPLE/face_val_lmdb # 驗(yàn)證集lmdb存放位置
echo "Done."
Status API Training Shop Blog About
根據(jù)上面的腳本示例,按照腳本中的中文注釋的地方修改自己實(shí)際的路經(jīng)位置.然后運(yùn)行腳本:sh **.sh 文件即可.
python 生成LMDB
網(wǎng)絡(luò)上也有用python制作LMDB數(shù)據(jù)源的,可以參考:https://zhuanlan.zhihu.com/p/23485774