1、簡述
caffe使用工具 convert_imageset 将标注資料轉換成lmdb或leveldb格式,convert_imageset 使用方法可以參考腳本examples/imagenet/create_imagenet.sh。
convert_imageset 在./build/tools/中。
2、convert_imageset指令行參數
./build/tools/convert_imageset
convert_imageset: 将一組圖像轉換為leveldb/lmdb格式用為Caffe輸入的格式。
用法:
convert_imageset [參數] 儲存圖檔的路徑或圖檔清單 生成檔案的名字
Flags from tools/convert_imageset.cpp:
-backend 選擇生成的資料格式(lmdb, leveldb),預設是: "lmdb"
-check_size 檢查圖檔大小是否一緻,預設不檢查: false
-encode_type 編碼圖檔格式(jpg、png)
-encoded 啟用此選項後,已編碼的圖像将儲存在資料中,預設是: false
-gray 将圖檔視為灰階圖檔,預設是: false
-resize_height 調整圖檔高度,預設是0,不調整
-resize_width 調整圖檔寬度,預設是0,不調整
-shuffle 随機打亂圖檔和标簽的順序,預設是: false
3、create_imagenet.sh腳本說明
#!/usr/bin/env sh
# Create the imagenet lmdb inputs
# N.B. set the path to the imagenet train + val data dirs
set -e
EXAMPLE=examples/imagenet # 儲存生成lmdb的路徑
DATA=data/ilsvrc12 # 标注檔案路徑
TOOLS=build/tools # convert_imageset工具路徑
TRAIN_DATA_ROOT=examples/imagenet/train_data # 訓練圖檔集路徑
VAL_DATA_ROOT=examples/imagenet/val_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=256
RESIZE_WIDTH=256
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..."
# GLOG_logtostderr=1,設定環境變量GLOG_logtostderr,參考glog的使用方法
GLOG_logtostderr=1 $TOOLS/convert_imageset \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle \
$TRAIN_DATA_ROOT \
$DATA/train.txt \
$EXAMPLE/ilsvrc12_train_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 \
$EXAMPLE/ilsvrc12_val_lmdb
echo "Done."