1、目的
在上述訓(xùn)練模型的基礎(chǔ)上惠啄,測(cè)試自己手寫(xiě)的圖片,完成手寫(xiě)圖片的生成融柬、圖片轉(zhuǎn)caffe輸入格式文件生成以及模型測(cè)試粒氧。
2节腐、手寫(xiě)圖片、caffe輸入格式轉(zhuǎn)換
windows畫(huà)圖軟件门怪,屬性設(shè)置圖片像素28*28圖片黑底白字掷空,
用matlab將圖片轉(zhuǎn)化為mnist二進(jìn)制格式文件坦弟,
clc;
clear;
for i=1:10
imgOrigin=imread([num2str(i,'%d'),'.png']);
imgBinaryImg(i,:,:)= imgOrigin(:,:,1).';
end
imgMnist = fopen('test_img_ubyte', 'wb');
magic = 2051;
numImages = i;
numRows = 28;
numCols = 28;
fwrite(imgMnist, magic, 'int32', 0, 'ieee-be');
fwrite(imgMnist, numImages, 'int32', 0, 'ieee-be');
fwrite(imgMnist, numRows, 'int32', 0, 'ieee-be');
fwrite(imgMnist, numCols, 'int32', 0, 'ieee-be');
for i=1:10
imgBinaryImg1(numCols* numRows*(i-1)+1:numCols* numRows*i)= reshape(imgBinaryImg(i,:,:), 1, numCols* numRows);
end
fwrite(imgMnist, imgBinaryImg1, 'unsigned char');
fclose(imgMnist);
flabel = fopen('test_lable_ubyte', 'wb');
magic = 2049;
numLabels = i;
labels = [5 6 1 4 7 0 9 1 3 5];
fwrite(flabel, magic, 'int32', 0, 'ieee-be');
fwrite(flabel, numLabels, 'int32', 0, 'ieee-be');
fwrite(flabel, labels, 'unsigned char');
fclose(flabel);
運(yùn)行后產(chǎn)生文件將其放于\caffe\data\mnist文件夾烙懦。
git下運(yùn)行/mnist/create_mnist_byourownselves.sh 赤炒,產(chǎn)生caffe讀入文件
#!/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/x64/Release
BACKEND="lmdb"
echo "Creating ${BACKEND}..."
rm -rf $EXAMPLE/mnist_train_${BACKEND}
rm -rf $EXAMPLE/mnist_test_${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/test_img_ubyte \
$DATA/test_lable_ubyte $EXAMPLE/mnist_test_${BACKEND} --backend=${BACKEND}
echo "Done."
產(chǎn)生測(cè)試圖片為10張莺褒,修改lenet_train_test.prototxtbatch_size為10遵岩,
git bash下運(yùn)行,
./Build/x64/Release/caffe.exe test -model examples/mnist/lenet_train_test_byourself.prototxt -weights examples/mnist/lenet_iter_10000.caffemodel -iterations 1
測(cè)試結(jié)果為:所有代碼以及資料地址:
https://github.com/Alix1992/Caffe
參考博客:
https://blog.csdn.net/woyaopojie1990/article/details/50820526`