jupyter notebook test
2016-10-05 17:33
274 查看
import os
import numpy as np
import scipy.io as sio
import Image
caffe_root = '../../../../'
import sys
sys.path.insert(0, caffe_root + 'python')
import caffe
data_root = '../../../../data/A_resize/'
test_dir = data_root+'test_data/images/'
gt_dir=data_root+'test_data/ground_truth/'
pathdir=os.listdir(test_dir)
error_all=0
error=np.zeros((1,len(pathdir)),dtype=np.float64)
pred=np.zeros((1,len(pathdir)),dtype=np.float64)
gt=np.zeros((1,len(pathdir)),dtype=np.float64)
i=0
pa=[]
for allpath in pathdir:
img_file_name =allpath
pa.append(allpath)
img = Image.open(test_dir+img_file_name)
img = np.array(img, dtype=np.float32)
if len(img.shape)==2 :
img2=np.empty((img.shape[0],img.shape[1],3),dtype=img.dtype)
img2[:,:,0]=img
img2[:,:,1]=img
img2[:,:,2]=img
img=img2
img = img[:,:,::-1]
img = img.transpose((2,0,1))
caffe.set_mode_gpu()
caffe.set_device(0)
model_root = './'
net = caffe.Net(model_root+'deploy.prototxt','./network_iter_4320000.caffemodel', caffe.TEST)
# shape for input (data blob is N x C x H x W), set data
net.blobs['data'].reshape(1, *img.shape)
net.blobs['data'].data[...] = img
# run net and take argmax for prediction
net.forward()
pred[0,i]=np.sum(net.blobs['score'].data[0][0,:,:])
label_name='GT_'+img_file_name[:-3]+'mat'
label_path=os.path.join(gt_dir,label_name)
label=sio.loadmat(label_path)
gt[0,i]=label['image_info'][0,0]['number']
error[0,i]=abs(gt[0,i]-pred[0,i])
error_all=error_all+error[0,i]
i=i+1
import numpy as np
import scipy.io as sio
import Image
caffe_root = '../../../../'
import sys
sys.path.insert(0, caffe_root + 'python')
import caffe
data_root = '../../../../data/A_resize/'
test_dir = data_root+'test_data/images/'
gt_dir=data_root+'test_data/ground_truth/'
pathdir=os.listdir(test_dir)
error_all=0
error=np.zeros((1,len(pathdir)),dtype=np.float64)
pred=np.zeros((1,len(pathdir)),dtype=np.float64)
gt=np.zeros((1,len(pathdir)),dtype=np.float64)
i=0
pa=[]
for allpath in pathdir:
img_file_name =allpath
pa.append(allpath)
img = Image.open(test_dir+img_file_name)
img = np.array(img, dtype=np.float32)
if len(img.shape)==2 :
img2=np.empty((img.shape[0],img.shape[1],3),dtype=img.dtype)
img2[:,:,0]=img
img2[:,:,1]=img
img2[:,:,2]=img
img=img2
img = img[:,:,::-1]
img = img.transpose((2,0,1))
caffe.set_mode_gpu()
caffe.set_device(0)
model_root = './'
net = caffe.Net(model_root+'deploy.prototxt','./network_iter_4320000.caffemodel', caffe.TEST)
# shape for input (data blob is N x C x H x W), set data
net.blobs['data'].reshape(1, *img.shape)
net.blobs['data'].data[...] = img
# run net and take argmax for prediction
net.forward()
pred[0,i]=np.sum(net.blobs['score'].data[0][0,:,:])
label_name='GT_'+img_file_name[:-3]+'mat'
label_path=os.path.join(gt_dir,label_name)
label=sio.loadmat(label_path)
gt[0,i]=label['image_info'][0,0]['number']
error[0,i]=abs(gt[0,i]-pred[0,i])
error_all=error_all+error[0,i]
i=i+1
相关文章推荐
- 机器学习(三) Jupyter Notebook, numpy和matplotlib的详细使用 (下)
- jupyter notebook使用技巧
- Jupyter Notebook使用笔记(二)
- jupyter notebook的一些技巧
- 远程访问jupyter notebook
- 如何修改jupyter notebook的默认工作路径
- Jupyter Notebook简洁教程
- jupyter notebook中美化pandas中DataFrame的输出
- 什么是Jupyter Notebook?
- 在Mac上使用Jupyter Notebook遇到打不开浏览器的情况
- Jupyter Notebook 初识
- 【Jupyter notebook】access remotly
- 跟我一起学python第二讲 开发工具Jupyter Notebook安装和远程访问设置
- jupyter notebook 的使用方法(持续更新)
- Jupyter Notebook 的快捷键
- Jupyter Notebook 的快捷键
- TensorFlow安装及jupyter notebook配置方法
- jupyter notebook 各种用法记录(陆续更新)
- 远程访问jupyter notebook
- 1.2 jupyter notebook 浏览器打开空白