標籤:model nump coding float get span res color out
#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
[caffe(二)]Python載入訓練caffe模型並進行測試2