def run(entry_path, set_path, en_path, de_path, _set): entryset = p.load(open(entry_path)) nmt = NMT(entryset, _set) # translate to german entryset = nmt.postprocess() entryset = order.run(entryset, 'de') # order german # referring expressions entryset = reg.run(entryset, 'en') lexsize, templates, templates_de, entities, references = stats.run( entryset) # run xml generator parser.run_generator(entryset=entryset, input_dir=set_path, output_dir=en_path, lng='en') parser.run_generator(entryset=entryset, input_dir=set_path, output_dir=de_path, lng='de') # extract and generate templates based on sentence segmentation en_temp = template.run(entryset) json.dump(en_temp, open(os.path.join(en_path, 'templates.json'), 'w'), indent=4, separators=(',', ': ')) de_temp = template.run(entryset, 'de') json.dump(de_temp, open(os.path.join(de_path, 'templates.json'), 'w'), indent=4, separators=(',', ': ')) return lexsize, templates, templates_de, entities, references
't_dayOfWeek_train', 'current_local_flow_train', 'stack_local_flow_train', 'global_flow_train' ] ] param_dict['test_data'] = [ data[name] for name in [ 'g_hour_test', 'g_dayOfWeek_test', 't_hour_test', 't_dayOfWeek_test', 'current_local_flow_test', 'stack_local_flow_test', 'global_flow_test' ] ] param_dict['train_ground'] = data['ground_truth_train'] param_dict['test_ground'] = data['ground_truth_test'] param_dict['max'], param_dict['min'] = mmn._max, mmn._min param_dict['start_time'], param_dict['end_time'] = data[ 'predict_time_test'][0], data['predict_time_test'][-1] # special, add one model parameter for different map size param_dict['model'][2][ 'width'] = 32 if param_dict['dataset'] == 'bj_taxi' else 16 param_dict['model'][2][ 'height'] = 32 if param_dict['dataset'] == 'bj_taxi' else 8 print('\n Load data elapsed time : %.3f seconds\n' % (time.time() - ts)) print('=' * 30) # =============================================================== template.run(param_dict)
def image_to_text(str): img = cv2.imread(str, 0) # img = cv2.resize(img, (50, 50), interpolation=cv2.INTER_CUBIC) with open('KNNClassifier.pkl', 'rb') as f: clf2 = pickle.load(f) with open('ExtraTreesClassifier.pkl', 'rb') as f: clf1 = pickle.load(f) with open('MPLClassifier4.pkl', 'rb') as f: clf3 = pickle.load(f) with open('scaler4.pkl', 'rb') as f: scaler = pickle.load(f) list_chars = template.run(img) # print(len(list_chars)) # print(len(list_chars[0])) ret_str = "" for word_list in list_chars: chars = [] for char_img in word_list: datas = get_data(char_img) # util.display_image(char_img) chars.append(datas) chars = scaler.transform(chars) out_vec1 = clf1.predict(chars) out_vec2 = clf2.predict(chars) out_vec3 = clf3.predict(chars) x1 = "" for vec in out_vec1: cnt = 0 for i in vec: cnt = cnt + 1 if i == 1: break val = "" if cnt < 11: cnt = cnt - 1 val = chr(48 + cnt) elif cnt > 10 and cnt < 37: cnt = cnt - 11 val = chr(65 + cnt) else: cnt -= 37 val = chr(97 + cnt) x1 = x1 + val x2 = "" for vec in out_vec2: cnt = 0 for i in vec: cnt = cnt + 1 if i == 1: break val = "" if cnt < 11: cnt = cnt - 1 val = chr(48 + cnt) elif cnt > 10 and cnt < 37: cnt = cnt - 11 val = chr(65 + cnt) else: cnt -= 37 val = chr(97 + cnt) x2 = x2 + val x3 = "" for vec in out_vec3: cnt = 0 for i in vec: cnt = cnt + 1 if i == 1: break val = "" if cnt < 11: cnt = cnt - 1 val = chr(48 + cnt) elif cnt > 10 and cnt < 37: cnt = cnt - 11 val = chr(65 + cnt) else: cnt -= 37 val = chr(97 + cnt) x3 = x3 + val finalx = "" for i in range(0, len(x1)): l = [] if x1[i] != 'z': l.append(x1[i]) if x2[i] != 'z': l.append(x2[i]) if x3[i] != 'z': l.append(x3[i]) if len(l) == 0: finalx += 'z' else: finalx += l[0] ret_str += finalx ret_str += " " return ret_str