def pred(model, X, char_set, label_set, post_correction): pred_res = model.predict(X) pred_res = [one_hot_decoder(i, char_set) for i in pred_res] pred_res = [list2str(i) for i in pred_res] # post correction if post_correction: pred_res = correction(pred_res, label_set) return pred_res
def pred(self, X): pred_res = self.model.predict(X, batch_size=256) self.pred_probs = pred_res pred_res = [one_hot_decoder(i, self.char_set) for i in pred_res] pred_res = [list2str(i) for i in pred_res] # post correction if self.post_correction: pred_res = correction(pred_res, self.label_set) return pred_res
def test(model, test_data, char_set, post_correction): test_X, test_y = test_data[0], test_data[1] test_y = [one_hot_decoder(i, char_set) for i in test_y] test_y = [list2str(i) for i in test_y] pred_res = pred(model, test_X, char_set, post_correction) nb_correct = sum(pred_res[i]==test_y[i] for i in range(len(pred_res))) for i in range(len(pred_res)): if test_y[i] != pred_res[i]: print ('test:', test_y[i]) print ('pred:', pred_res[i]) pass print ('nb_correct: ', nb_correct) print ('Acurracy: ', float(nb_correct) / len(pred_res))
def test(model, test_data, char_set, label_set, post_correction): test_X, test_y = test_data[0], test_data[1] test_y = [one_hot_decoder(i, char_set) for i in test_y] test_y = [list2str(i) for i in test_y] pred_res = pred(model, test_X, char_set, label_set, post_correction) # for i in pred_res: # print i nb_correct = sum(pred_res[i]==test_y[i] for i in range(len(pred_res))) for i in range(len(pred_res)): if test_y[i] != pred_res[i]: print 'test:', test_y[i] print 'pred:', pred_res[i] pass print 'nb_correct: ', nb_correct print 'Acurracy: ', float(nb_correct) / len(pred_res)