caffe文件夾下有.sh文件,如果是在linux平臺(tái)下訓(xùn)練caffe,可以直接在terminal上執(zhí)行.sh文件,非常方便。但如果是在windows平臺(tái)下就無(wú)法執(zhí)行.sh文件。以create_mnist.sh為例,用記事本打開.,可以看到如下代碼(中文部分是我添加的注解):
#!/usr/bin/env sh
# This script converts the mnist data into lmdb/leveldb format,
# depending on the value assigned to $BACKEND.
#把目錄設(shè)置為變量
EXAMPLE=examples/mnist
DATA=data/mnist
BUILD=build/examples/mnist
#生成文件后綴
BACKEND="lmdb"
#在屏幕上顯示文字
echo "Creating ${BACKEND}..."
# rm -rf 文件夾 該命令將目錄及目錄中的文件全部刪除并且不用確認(rèn)
# $表示引用目錄變量
rm -rf $EXAMPLE/mnist_train_${BACKEND}
rm -rf $EXAMPLE/mnist_test_${BACKEND}
# .bin為編譯生成的可執(zhí)行文件,兩個(gè)$DATA表示需要轉(zhuǎn)換的文件,
# $EXAMPLE表示轉(zhuǎn)換后的文件的存放目錄,--backend表示后綴
$BUILD/convert_mnist_data.bin $DATA/train-images-idx3-ubyte \
$DATA/train-labels-idx1-ubyte $EXAMPLE/mnist_train_${BACKEND} --backend=${BACKEND}
$BUILD/convert_mnist_data.bin $DATA/t10k-images-idx3-ubyte \
$DATA/t10k-labels-idx1-ubyte $EXAMPLE/mnist_test_${BACKEND} --backend=${BACKEND}
echo "Done."
但是.sh的shell代碼只能在linux下執(zhí)行,對(duì)應(yīng)到windows平臺(tái)上,應(yīng)該修改成.bat文件。修改之后的代碼如下:
:: !\usr\bin\env sh
:: This script converts the mnist data into lmdb\leveldb format,
:: depending on the value assigned to $BACKEND.
::把目錄設(shè)置為變量
::bat中用set來(lái)給變量賦值,set var=abcd
::取消賦值,set var=
set EXAMPLE=examples\mnist
set DATA=data\mnist
set BUILD=Build\x64\Release
::生成文件后綴
set BACKEND=lmdb
::在屏幕上顯示文字,通過(guò)%%引用變量
echo "Creating %BACKEND%..."
::刪除文件夾和文件夾中的文件,并且不需要確認(rèn)
rd /s /q %EXAMPLE%\mnist_train_%BACKEND%
rd /s /q %EXAMPLE%\mnist_test_%BACKEND%
::執(zhí)行.exe文件,兩個(gè)$DATA表示需要轉(zhuǎn)換的文件,
:: $EXAMPLE表示轉(zhuǎn)換后的文件的存放目錄,--backend表示后綴
%BUILD%\convert_mnist_data.exe %DATA%\train-images.idx3-ubyte %DATA%\train-labels.idx1-ubyte %EXAMPLE%\mnist_train_%BACKEND% --backend=%BACKEND%
%BUILD%\convert_mnist_data.exe %DATA%\t10k-images.idx3-ubyte %DATA%\t10k-labels.idx1-ubyte %EXAMPLE%\mnist_test_%BACKEND% --backend=%BACKEND%
echo "Done."
新建一個(gè)txt文件,命名為create_mnist.txt,把代碼復(fù)制進(jìn)去。注意,.sh代碼里的斜杠都是“/”,但.bat文件里要改成“\”,否則會(huì)報(bào)錯(cuò)。保存之后把文件后綴改成.bat,在cmd里運(yùn)行的時(shí)候,用start命令執(zhí)行該.bat文件,效果和linux上運(yùn)行.sh一樣。具體運(yùn)行步驟,參考caffe的examples/mnist/readme.md。