def main_app(doc_name1, doc_name2, queue=None, test_mode=False): _global.init('hebrew', test_mode=test_mode) output = "" gui_output = "" ''' Prepare Documents, Detection & Recognition Phases ''' doc1 = init_doc(Document(doc_name1)) doc2 = init_doc(Document(doc_name2)) ''' Verification Phase ''' compare_docs = CompareDocuments(doc1, doc2) compare_docs.monkey_results() compare_docs.letters_autoencoder_results() s_count = compare_docs.ssim_count s_pred = s_count / compare_docs.ssim_total print("Ssim: count: {}, pred: {}".format(s_count, s_pred)) output = output + "Monkey Result:{}\nAE result: {}".format(\ compare_docs.monkey_results,\ compare_docs.letters_ae_results) gui_output += "Algo1: Monkey Result:\n\t<{0}> [Confident: {1:.2f}%]\n".format(compare_docs.monkey_results['result'],\ compare_docs.monkey_results['precent']*100) gui_output += "Algo2: AutoEncoder Letters Result:\n\t<{}> [Confident: {:.2f}%]\n\tResult By Predictions:\n\t<{}> [Confident: {:.2f}%]\n".format(\ compare_docs.letters_ae_results['result'],\ compare_docs.letters_ae_results['precent']*100, compare_docs.letters_ae_results['result_by_predictions'],\ compare_docs.letters_ae_results['precent_by_predictions']*100) gui_output += "\n\nFinal Result:\n\t<" conclusion = compare_docs.monkey_results['result'] + ">" if\ compare_docs.monkey_results['result'] == compare_docs.letters_ae_results['result']\ else "Conflict>" gui_output += conclusion conclusion2 = "\n\tWith AE by predictions:\n\t<" conclusion2 += compare_docs.monkey_results['result'] + ">" if\ compare_docs.monkey_results['result'] == compare_docs.letters_ae_results['result_by_predictions']\ else "Conflict>" gui_output += conclusion2 if queue is not None: queue.put(gui_output) print(output)
# +:+ +:+ +:+ # # By: gaennuye <*****@*****.**> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/02/29 14:29:06 by gaennuye #+# #+# # # Updated: 2020/03/02 17:15:08 by gaennuye ### ########lyon.fr # # # # **************************************************************************** # import _global as g import plot as p import matplotlib.pyplot as plt import numpy as np import progressbar g.init() # Estimating the price depending on the mileage def estimatePrice(km): res = g.theta[1] * km + g.theta[0] return res # For each point, calculating the difference between the # computed price and the "real" price with the current thetas def computeDiff(points): error = [0, 0] for km, price in points:
print("") print("True-Negative-Precent: mean:{0:.2f} std:{0:.2f}".format( np.mean(tn_prec, axis=0), np.std(tn_prec, axis=0))) print("False-Negative-Precent: mean:{0:.2f} std:{0:.2f}".format( np.mean(fn_prec, axis=0), np.std(fn_prec, axis=0))) print("False-Positive-Precent: mean:{0:.2f} std:{0:.2f}".format( np.mean(fp_prec, axis=0), np.std(fp_prec, axis=0))) print("True-Positive-Precent: mean:{0:.2f} std:{0:.2f}".format( np.mean(tp_prec, axis=0), np.std(tp_prec, axis=0))) if __name__ == "__main__": if len(sys.argv) > 1: if 'by_vectors' in sys.argv: BY_VECTORS = True _global.init('hebrew', monkey_by_vectors=BY_VECTORS) if sys.argv[1] == 'conf_matrix': test_conf_matrix() sys.exit(0) if sys.argv[1] == 'all_same': test_all_same() sys.exit(0) TEST_FILE_1 = sys.argv[1] TEST_FILE_2 = sys.argv[2] test_model(TEST_FILE_1, TEST_FILE_2) else: print( 'Usgae Option1: python test_monkey <file1> <file2> [by_sum/by_vectors]' ) print('Usage Option2: python test_monkey all_same [by_sum/by_vectors]')
compare_docs = CompareDocuments(doc1, doc2) get_ae_monkey_results(s, compare_docs) s.count_num_of_tests += 1 if test_random_different != 0: for i in range(test_random_different): sampled_list = random.sample(all_files, 2) doc1 = get_doc_by_name(all_docs, sampled_list[0]) doc2 = get_doc_by_name(all_docs, sampled_list[1]) if doc1.name.replace('b','') == doc2.name or doc2.name.replace('b','') == doc1.name\ or doc1.name == doc2.name: continue s.same_author = False print("\n---------------------") print("Test: {} {}".format(doc1.name, doc2.name)) compare_docs = CompareDocuments(doc1, doc2) get_ae_monkey_results(s, compare_docs) s.count_num_of_tests += 1 print_ae_monkey_results(s, len(b_files)) if __name__ == "__main__": # if(len(sys.argv) < 2): # print("Usage: python main.py <[save_all]/[file_name]> ") # sys.exit(1) #TODO: think how to determine monkey algo by_sum/by_vectors _global.init('hebrew', monkey_by_vectors=True, print_globals=True) test_all_same(106) # main_app('10.tiff', '14.tiff', test_mode=True)
done_list.append(doc_name) file = open(done_path, "a") file.write("{}{}".format(doc_name,"\n")) file.close() def main_save_all(): done_list = read_done_file() # read the files we already done with for root, dirs, files in os.walk(_global.DATA_PATH): for file in files: doc_name = file.split('.')[0] print(doc_name) if doc_name in done_list: print("{} already done".format(file)) continue img_name = _global.DATA_PATH + file img = get_prepared_doc(img_name) lines = get_lines(img, img_name) letters = get_letters(lines) found_letters = save_letters(letters, doc_name) write_done_file(done_list,doc_name) print("done") if __name__ == "__main__": _global.init('hebrew') createOutputDirs() # create the folders to collect the data main_save_all()