text
stringlengths
1
93.6k
X_test_extend[i,0,:,:] = rex
X_test_extend[i,1,:,:] = rex
X_test_extend[i,2,:,:] = rex
X_test = X_test_extend
X_test_test_extend = np.zeros((X_test_test.shape[0], 3, 227, 227))
for i in xrange(X_test_test.shape[0]):
rex = np.resize(X_test_test[i,:,:,:], (227,227))
X_test_test_extend[i,0,:,:] = rex
X_test_test_extend[i,1,:,:] = rex
X_test_test_extend[i,2,:,:] = rex
X_test_test = X_test_test_extend
if pretrain: # 227*227
alexmodel = convnet('alexnet', weights_path='alexnet_weights.h5', heatmap=False, l1=l1factor, l2=l2factor)
model = convnet('alexnet', outdim=2, l1=l1factor, l2=l2factor, usemil=mil)
for layer, mylayer in zip(alexmodel.layers, model.layers):
print(layer.name)
if mylayer.name == 'mil_1' or mylayer.name == 'dense_3':
break
else:
weightsval = layer.get_weights()
print(len(weightsval))
mylayer.set_weights(weightsval)
else:
model = convnet('alexnet', outdim=2, l1=l1factor,l2=l2factor, usemil=mil)
X_test_test = X_test_test.astype('float32')
for f in os.listdir('./'):
metric = ['loss', 'auc', 'prec', 'reca', 'f1', 'acc']
for m in metric:
if f.endswith('.hdf5') and f.startswith(savename+m):
print(f)
weightname = f
model.load_weights(weightname)
y_pred_val = model.predict(X_test_test) # val for threshold
print(y_pred_val.shape)
#np.savetxt('maxyfold0.txt',y_pred_val)
y_pred_val = y_pred_val[:,1]
y_test = Y_test_test[:,1]
sortindex = np.argsort(y_pred_val)
y_pred_val = y_pred_val[sortindex]
y_test = y_test[sortindex]
bestacc, bestthre = np.mean(y_test == np.ones_like(y_test)), y_pred_val[0]-0.01
for thre in y_pred_val:
if np.mean((y_pred_val > thre) == y_test) > bestacc:
bestacc = np.mean((y_pred_val > thre) == y_test)
bestthre = thre
print(bestthre, bestacc)
y_pred = model.predict(X_test_test)
print(y_pred.shape, Y_test_test.shape)
score = roc_auc_score(Y_test_test[:,1], y_pred[:,1])
fpr, tpr, _ = roc_curve(Y_test_test[:,1], y_pred[:,1])
#np.savetxt('fpr.txt', fpr)
#np.savetxt('tpr.txt', tpr)
y_true = np.argmax(Y_test_test, axis=1)
y_score = np.argmax(y_pred, axis=1)
TP = np.sum(y_true[y_score==1]==1)*1. / sum(y_true)
FP = np.sum(y_true[y_score==1]==0)*1. / (y_true.shape[0]-sum(y_true))
prec = TP / (TP+FP+1e-6)
TP = np.sum(y_true[y_score==1]==1)*1. / sum(y_true)
FN = np.sum(y_true[y_score==0]==1)*1. / sum(y_true)
reca = TP / (TP+FN+1e-6)
f1 = 2*prec*reca / (prec+reca+1e-6)
acc = np.mean(y_true == y_score)
print(acc, score, prec, reca, f1)
# <FILESEP>
'''
Backend Kivy
=====
.. image:: images/backend_kivy_example.jpg
:align: right
The :class:`FigureCanvasKivy` widget is used to create a matplotlib graph.
This widget has the same properties as
:class:`kivy.ext.mpl.backend_kivyagg.FigureCanvasKivyAgg`. FigureCanvasKivy
instead of rendering a static image, uses the kivy graphics instructions
:class:`kivy.graphics.Line` and :class:`kivy.graphics.Mesh` to render on the
canvas.
Installation
------------
The matplotlib backend for kivy can be used by using the garden extension in
kivy following this .. _link: http://kivy.org/docs/api-kivy.garden.html ::
garden install matplotlib
Or if you want to include it directly on your application ::
cd myapp
garden install --app matplotlib
Initialization
--------------
A backend can be initialized in two ways. The first one is using pure pyplot
as explained
.. _here: http://matplotlib.org/faq/usage_faq.html#what-is-a-backend::
import matplotlib