def predict_regress(model_path):
#redefine model
target_var = T.fmatrix('y')
target_labels = T.switch(T.gt(target_var, 0), 1, 0)
dnn_strategy = model_path.split('/')[-1].split('_')[0]
network = get_model_by_strategy(dnn_strategy)
#load params
params = []
with open(model_path, 'r') as f:
lines = f.readlines()
for line in lines:
params.append(np.array(json.loads(line)))
set_all_param_values(network, params)
predict_prediction = get_output(network, deterministic=True)
predict_labels = T.switch(T.gt(predict_prediction, 0), 1, 0)
predict_acc = binary_accuracy(predict_labels, target_labels, threshold=0).mean()
input_layer = get_all_layers(network)[0]
predict = theano.function([input_layer.input_var, target_var],[predict_prediction, predict_acc])
X, y, labels, values, _, _, _, _, _, _ = load_dataset('../../data/test')
predict_prediction, predict_acc = predict(X, y)
sys.stdout.write(" predict accuracy:\t\t\t{} %\n".format(predict_acc * 100))
#output predict result
with open('../../data/prediction', 'w') as f:
for ix in xrange(len(labels)):
line = str(labels[ix]) + '\t' + str(values[ix]) + '\t' + str(predict_prediction[ix][0]) + '\n'
f.write(line)
sys.stdout.flush()
评论列表
文章目录