#coding=utf-8import h5pyimport numpy as npimport 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' #训练好的 caffemodelnet = 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 kkprint count