def predict_cnn(teX, teY): _, _, h, w = teX.shape start = time.process_time() y_score = predict(teX) end = time.process_time() end = end-start auc_r = auc.roc_auc(np.argmax(teY, axis=1), y_score) return end, auc_r
w_h4 = init_weights((hidden, hidden)) w_o = init_weights((hidden, num_of_class)) # 10 <- output noise_h, noise_h2, noise_h3, noise_h4, noise_py_x = model(X, w_h, w_h2, w_h3, w_h4, w_o, 0.2, 0.5) h, h2, h3, h4, py_x = model(X, w_h, w_h2, w_h3, w_h4, w_o, 0., 0.) y_x = T.argmax(py_x, axis=1) cost = T.mean(T.nnet.categorical_crossentropy(noise_py_x, Y)) params = [w_h, w_h2, w_h3, w_h4, w_o] updates = RMSprop(cost, params, lr=0.001) train = theano.function(inputs=[X, Y], outputs=cost, updates=updates, allow_input_downcast=True) predict = theano.function(inputs=[X], outputs=y_x, allow_input_downcast=True) for i in range(100): for start, end in zip(range(0, len(trX), 128), range(128, len(trX), 128)): # 0,128; 128,256; ... cost = train(trX[start:end], trY[start:end]) y_score = predict(teX) print "AUC:", auc.roc_auc(np.argmax(teY, axis=1), y_score) deg, thresh, c1, c2, c3, c4, c5 = fusion_update(w_h, w_h2, w_h3, w_h4, w_o, rank) y_score = predict(teX) print "MF AUC:", auc.roc_auc(np.argmax(teY, axis=1), y_score), "deg:", np.mean(deg), "thresh:", np.mean(thresh) for i in range(50): for start, end in zip(range(0, len(trX), 128), range(128, len(trX), 128)): cost = train(trX[start:end], trY[start:end]) repair(w_h, w_h2, w_h3, w_h4, w_o, c1, c2, c3, c4, c5) y_score = predict(teX) print "AUC:", auc.roc_auc(np.argmax(teY, axis=1), y_score)