In [1]:
%load_ext autoreload
%autoreload 2
from matplotlib.pyplot import imshow
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
import sys
sys.path.append('../')
import gp
In [2]:
e_p = []
p = []
In [3]:
import cPickle as pickle
with open('../nets/IPMLB_FULL.p', 'rb') as f:
cnn = pickle.load(f)
cnn.uuid = 'IPMLB'
In [4]:
# here we just load p, and e_p
import cPickle as pickle
with open('/home/d/data/CYLPATCHES/e_p.p', 'rb') as f:
e_p = pickle.load(f)
with open('/home/d/data/CYLPATCHES/p.p', 'rb') as f:
p = pickle.load(f)
In [ ]:
#
# FOCUSED PROOFREADING
#
In [3]:
# cconvert to FP format with target
import neuroproof
import neuroproof.FocusedProofreading as fp
In [4]:
graphs = []
for z in range(250,299):
g = fp.Graph('/home/d/FP/cylinder/graph_'+str(z)+'.json')
graphs.append(g)
In [5]:
fp_y_test_proba = []
fp_y_test = []
gt_y_test = []
for z in range(49):
cur_e_p = e_p[z]
cur_p = p[z]
g = graphs[z]
for pa in cur_e_p:
# print pa['l'], pa['n']
label1 = pa['l']
label2 = pa['n']
graph_neighbors = sorted(g.find_close_bodies(label1,0,0.))
pred = [ne[1] for ne in graph_neighbors if ne[0] == label2]
fp_y_test.append(np.round(pred))
fp_y_test_proba.append(pred)
gt_y_test.append(1)
for pa in cur_p:
# print pa['l'], pa['n']
label1 = pa['l']
label2 = pa['n']
graph_neighbors = sorted(g.find_close_bodies(label1,0,0.))
pred = [ne[1] for ne in graph_neighbors if ne[0] == label2]
fp_y_test.append(np.round(pred))
fp_y_test_proba.append(pred)
gt_y_test.append(0)
print z
In [7]:
from sklearn.metrics import classification_report, accuracy_score, roc_curve, auc, precision_recall_fscore_support, f1_score, precision_recall_curve, average_precision_score, zero_one_loss
In [8]:
print 'Precision/Recall:'
print classification_report(np.array(gt_y_test), np.array(fp_y_test))
In [9]:
acc_score = accuracy_score(np.array(gt_y_test), np.array(fp_y_test))
print 'Accuracy Score:', acc_score
In [11]:
with open('/home/d/GPSTUDY/fp_y_test_proba_cyl.p','wb') as f:
pickle.dump(fp_y_test_proba, f)
In [ ]:
In [ ]:
#
# GUIDED PROOFREADING
#
In [5]:
gp_y_test_proba = []
gp_y_test = []
gt_y_test = []
for z in range(len(e_p)):
cur_e_p = e_p[z]
cur_p = p[z]
for pa in cur_e_p:
# print pa['l'], pa['n']
label1 = pa['l']
label2 = pa['n']
pa['prob'] = 1.-pa['prob']
pred = gp.Patch.test_and_unify([pa], cnn)
gp_y_test.append(np.round(pred))
gp_y_test_proba.append(pred)
gt_y_test.append(1)
for pa in cur_p:
# print pa['l'], pa['n']
label1 = pa['l']
label2 = pa['n']
pa['prob'] = 1.-pa['prob']
pred = gp.Patch.test_and_unify([pa], cnn)
gp_y_test.append(np.round(pred))
gp_y_test_proba.append(pred)
gt_y_test.append(0)
print z
In [6]:
from sklearn.metrics import classification_report, accuracy_score, roc_curve, auc, precision_recall_fscore_support, f1_score, precision_recall_curve, average_precision_score, zero_one_loss
In [7]:
print classification_report(np.array(gt_y_test), np.array(gp_y_test))
In [8]:
acc_score = accuracy_score(np.array(gt_y_test), np.array(gp_y_test))
print 'Accuracy Score:', acc_score
In [9]:
with open('/home/d/GPSTUDY/gp_y_test_proba_cyl.p','wb') as f:
pickle.dump(gp_y_test_proba, f)
In [10]:
with open('/home/d/GPSTUDY/gt_y_test_cyl.p','wb') as f:
pickle.dump(gt_y_test, f)
In [ ]:
In [ ]:
In [ ]:
#
# combined plots
#
In [15]:
# load fp and gp
with open('/home/d/GPSTUDY/gp_y_test_proba_cyl.p', 'rb') as f:
gp_y_test_proba = pickle.load(f)
with open('/home/d/GPSTUDY/fp_y_test_proba_cyl.p', 'rb') as f:
fp_y_test_proba = pickle.load(f)
with open('/home/d/GPSTUDY/gt_y_test_cyl.p', 'rb') as f:
gt_y_test = pickle.load(f)
In [16]:
gp_precision, gp_recall, gp_thresholds = precision_recall_curve(gt_y_test, gp_y_test_proba, pos_label=1)
fp_precision, fp_recall, fp_thresholds = precision_recall_curve(gt_y_test, fp_y_test_proba, pos_label=1)
plt.plot(gp_recall, gp_precision, color='blue')
plt.plot(fp_recall, fp_precision, color='red')
Out[16]:
In [20]:
fp_y_test_proba[0:20]
Out[20]:
In [21]:
gt_y_test[0:20]
Out[21]:
In [22]:
gp_y_test_proba[0:20]
Out[22]:
In [ ]: