[caffe(二)]Python加載訓練caffe模型並進行測試2


#coding=utf-8
import h5py
import numpy as np
import caffe

#1.導入數據
filename = 'testdata.h5'
f = h5py.File(filename, 'r')
n1 = f.get('data')
n1 = np.array(n1)
print n1[0]
n2=f.get( 'label_1d')
n2 = np.array(n2)
f.close()

#2.導入模型與網絡
deploy='gesture_deploy.prototxt'    #deploy文件
caffe_model= 'iter_iter_1000.caffemodel'   #訓練好的 caffemodel
net = caffe.Net(deploy,caffe_model,caffe.TEST)


count=0   #統計預測值和標簽相等的數量
t=1000    #t:樣本的數量
for i in range(t):
 #數據處理
 tempdata=n1[i,0:63]
 tempdata = np.reshape([[tempdata]], (1,1,63))
 tempdata= tempdata.astype(np.float32)
 net.blobs['data'].data[0] = tempdata

 #預測
 out = net.forward()
 output = out['outputs']
 result= np.where(output==np.max(output))
 predi=result[1][0]
 #判斷predi與label是否相等,並統計
 label = n2[i, 0]
 if predi==(label):
     count=count+1
 kk=[predi,label]
 print kk
print count

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM