#-*- coding:utf-8 -*-
import sys
import methods
import cv2
import os 
from sklearn.metrics import confusion_matrix 
#%matplotlib inline  
caffe_root = '/home/nikoong/Algorithm_test/caffe-master'
sys.path.append(caffe_root+'python')  
import caffe  
 
net_file = '/home/nikoong/Algorithm_test/handwritting/lenet/lenet_deploy.prototxt'
pretrained = '/home/nikoong/Algorithm_test/handwritting/lenet/snapshots/ft_mnist_balance_lmdb_iter_30000.caffemodel'
txtpath = '/home/nikoong/Algorithm_test/handwritting/data/txt/finish/balance_val.txt'


net = caffe.Classifier(net_file, pretrained,raw_scale=1, image_dims=(28,28))   
caffe.set_mode_gpu
filelist,labellist = methods.Parsetxt(txtpath)#labellist ÊÇintÁÐ±í  
pre_y = []
for i in range(len(filelist)):
    input_image = caffe.io.load_image(filelist[i], color=False)
    prediction = net.predict([input_image])
    pre_y.append(prediction[0].argmax())
    if i%5000 == 0:print i
con_matrix = confusion_matrix(labellist, pre_y, labels=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) 
print "confusion_matrix",'\n',con_matrix
#predictions: (N x C)  (1 x 10)ndarray of class probabilities for N images and C classes.


