#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
原文地址:https://www.cnblogs.com/youngsea/p/9559646.html
时间: 2024-12-09 18:06:54