def param_sweep(): test_dir = Path('test_files/words/KNMP') file_range = np.arange(4,50,2) # file_range = [10] minCutWindow_range = np.arange(0,40,5) minCutWindow_range[0] = 1 # minCutWindow_range = [1] maxCutWindow_range = np.arange(60,210,10) # maxCutWindow_range = [60] globalLexicon_range = [True, False] # globalLexicon_range = [True] with open('results.csv', 'wb') as csvfile: csv_writer = csv.writer(csvfile, delimiter=',') results = [] labels = ["minWindow", "maxWindow", "GlobalLexicon", "Right", "Wrong", "Accuracy"] results.append(labels) csv_writer.writerow(labels) for minCutWindow in minCutWindow_range: for maxCutWindow in maxCutWindow_range: for globalLexicon in globalLexicon_range: logging.info("Now testing %s\t%s\t%s" % (minCutWindow, maxCutWindow, globalLexicon)) globalRight = 0.0 globalWrong = 0.0 for file_nr in file_range: logging.info("File: %s" % str(file_nr)) img_file = str(file_nr) + ".jpg" img_path = Path(test_dir, img_file) logging.info("img path %s" % img_path) img = cv2.imread(img_path, 0) words_file = str(file_nr) + ".words" words_file_name = Path(test_dir, words_file) right, wrong = recognizer.main( state="internal", img=img, words_file_name=words_file_name, minCutWindow = minCutWindow, maxCutWindow=maxCutWindow, globalLexicon=globalLexicon ) globalRight += right globalWrong += wrong # Log the results accuracy = globalRight / (globalRight + globalWrong) result = [minCutWindow, maxCutWindow, globalLexicon, globalRight, globalWrong, accuracy] logging.info("Interim result:") logging.info(result) results.append(result) csv_writer.writerow(result) logging.info("Total result") logging.info(results)
def test_worker(taskqueue, resultqueue, logqueue): # Set up logging using the queue #h = logging.handlers.QueueHandler(logqueue) #root = logging.getLogger() #root.handlers = [] #root.addHandler(h) logger = logging.getLogger('Test worker') logger.info('Starting an experiment subprocess') while 1: try: task = taskqueue.get(True, 1) except Queue.Empty: time.sleep(1) if task == None: taskqueue.task_done() # Notify that we received STOP signal break # process task num, min_cut, max_cut, lexicon = task global_right = 0 global_wrong = 0 for file_nr in file_range: logging.info("File: {}".format(str(file_nr))) img_file = str(file_nr) + '.jpg' img_path = Path(test_dir, img_file) img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE) words_file = str(file_nr) + '.words' words_file_name = Path(test_dir, words_file) right, wrong = recognizer.main(state="internal", img=img, words_file_name=words_file_name, minCutWindow=min_cut, maxCutWindow=max_cut, globalLexicon=lexicon) global_right += right global_wrong += wrong # Return the results accuracy = global_right / float(global_right + global_wrong) result = (num, min_cut, max_cut, lexicon, global_right, global_wrong, accuracy) resultqueue.put(result) taskqueue.task_done() logger.info('Exiting experiment subprocess')
def go_children(x): Window.close() recognizer.main()