1. 執行%caffe_root%\examples\mnist\test_lenet.sh
caffe.exe test -model=examples/mnist/lenet_train_test.prototxt -weights=examples/mnist/lenet_iter_10000.caffemodel
其中caffe.exe在目錄%caffe_root%\build\tools\release目錄下。
2. 用python寫指令碼,通過predict函式**
import sys
import caffe
import struct
import time
caffe_root = r"d:\caffe"
sys.path.insert(0, caffe_root+r'\python')
test_mnist_label = caffe_root + r"\data\mnist\t10k-labels-idx1-ubyte"
# prepare label
index = 0
print("test label data:" + test_mnist_label)
binfile = open(test_mnist_label, 'rb')
buf = binfile.read()
magic, numimages = struct.unpack_from('>ii', buf, index)
print(magic, numimages)
index += struct.calcsize('>ii')
label =
for i in range(numimages):
tmp, = struct.unpack_from('>b', buf, index)
index += struct.calcsize('>b')
# prepare image data
test_data_dir = caffe_root + r"\examples\mnist\mytest\data\mnist_test"
input_image =
for i in range(numimages):
test_data_file = test_data_dir + r"\test_%s.bmp"%i
if0 == i % 1000:
print (len(input_image), test_data_file)
# prediction
start = time.clock()
model_file = caffe_root + r"\examples\mnist\lenet.prototxt"
pretrained = caffe_root + r"\examples\mnist\lenet_iter_10000.caffemodel"
net = caffe.classifier(model_file, pretrained, image_dims = [28, 28])
predi =
prediction = net.predict(input_image, oversample=false)
end = time.clock()
print("done in time:%f(s)" % (end - start))
for i in range(numimages):
if0 == i%1000:
print (i, prediction[i], predi[i])
# get accelerate
count = 0
wrong =
for i in range(numimages):
if label[i] in predi[i][-1:]:
count += 1
else:
print ("accelerate:%.2f[count = %d]%%"%(float(count)/numimages*100, count))
print ("wrong:", wrong[:20])
* 測試結果
用1方法測試得accuracy=98.68%,用2方法測試得accuracy=99.09%。兩種方法精度並不相同,而訓練結束時測試得accuracy=99.08%也與之不同。難到是資料輸入時有轉換誤差?或是train_test網路與deploy網路有所不同?或是用不同的patch會影響測試結果?原因還有待調查。
centos下兩種方法安裝git
來自 今天下個包需要使用git,網上找了下看到大多數只有編譯安裝,並且編譯安裝還有錯,不知道他們也沒有實驗過,這裡我來給大家介紹下編譯安裝和yum安裝git.系統 centos 5.5 需要的軟體包 git latest.tar.gz epel release 5 4.noarch.rpm 1.先給...
centos下兩種方法安裝git
今天下個包需要使用git,網上找了下看到大多數只有編譯安裝,並且編譯安裝還有錯,不知道他們也沒有實驗過,這裡我來給大家介紹下編譯安裝和yum安裝git.系統 centos 5.5 需要的軟體包 git latest.tar.gz epel release 5 4.noarch.rpm 1.先給大家說...
LCA兩種方法
lca least common ancestors 即最近公共祖先,是指在有根樹中,找出某兩個結點u和v最近的公共祖先。模板題 anc i j 表示第i個點的2 j的祖先的標號 整個過程就是兩個點往上跳到同一深度,再一起往上跳找到lca include include using namespac...