Caffe应用篇----文件格式转换
1 訓(xùn)練前準(zhǔn)備
caffe常使用的數(shù)據(jù)是db格式(leveldb/lmdb),我們手中有的圖片數(shù)據(jù),jpg、bmp格式等,必須轉(zhuǎn)換;此操作caffe已經(jīng)提供工具。它的路徑是/home/your/caffe-master/build/tools/convert_imageset.bin;不過,使用它之前,需要先生成一個(gè)依賴文本文件。
convert_imageset.bin程序的使用格式:
convert_imageset [FLAGS] ROOTFOLDER/ LISTFILE DB_NAME需要帶四個(gè)參數(shù):
FLAGS: 圖片參數(shù)組,后面詳細(xì)介紹
ROOTFOLDER/: 圖片存放的絕對(duì)路徑,從Linux系統(tǒng)根目錄開始
LISTFILE: 圖片文件列表清單,一般為一個(gè)txt文件,一行一張圖片
DB_NAME: 最終生成的db文件存放目錄
2 訓(xùn)練文本LISTFILE生成
用gedit編輯如下shell代碼,并存為mktraintxt.sh# /usr/bin/env sh DATA=examples/images echo "Create train.txt..." rm -rf $DATA/train.txt find $DATA -name *cat.jpg | cut -d '/' -f3 | sed "s/$/ 1/">>$DATA/train.txt find $DATA -name *bike.jpg | cut -d '/' -f3 | sed "s/$/ 2/">>$DATA/tmp.txt cat $DATA/tmp.txt>>$DATA/train.txt rm -rf $DATA/tmp.txt echo "Done.."
3 圖像轉(zhuǎn)換代碼 sudo vim data/mydata/create_lmdb.sh(我的數(shù)據(jù)放在data文件下的mydata目錄下)。
#!/usr/bin/env sh
# This script converts the mnist data into lmdb/leveldb format,
# depending on the value assigned to $BACKEND.
set -e
EXAMPLE=examples/mnist
DATA=data/mnist
BUILD=build/examples/mnist
BACKEND="lmdb"
TRAIN_DATA_ROOT=/home/yan/image-face/train/
VAL_DATA_ROOT=/home/yan/image-face/val/
RESIZE=true
if $RESIZE; then
?? ?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_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 ${BACKEND}..."
GLOG_logtostderr=1 $TOOLS/convert_imageset \
??? --resize_height=$RESIZE_HEIGHT \
??? --resize_width=$RESIZE_WIDTH \
??? --shuffle \
??? $TRAIN_DATA_ROOT \
??? $DATA/train_all.txt \
??? $EXAMPLE/face_train_lmdb
echo "Creating val ${BACKEND}..."
GLOG_logtostderr=1 $TOOLS/convert_imageset \
??? --resize_height=$RESIZE_HEIGHT \
??? --resize_width=$RESIZE_WIDTH \
??? --shuffle \
??? $VAL_DATA_ROOT \
??? $DATA/val.txt \
??? $EXAMPLE/face_val_lmdb
echo "Done."
?
轉(zhuǎn)載于:https://www.cnblogs.com/gongdiwudu/p/6240190.html
總結(jié)
以上是生活随笔為你收集整理的Caffe应用篇----文件格式转换的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

- 上一篇: poj 3041
- 下一篇: 泛型DAO与泛型Service