-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
217 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import sys | ||
import os | ||
from preprocessing import parse_PAGE | ||
from collections import defaultdict | ||
import editdistance | ||
|
||
def read_xml(filename): | ||
with open(filename) as f: | ||
xml_string_data = f.read() | ||
# xml_string_data = f1.replace("&", "&") | ||
# xml_string_data = f1.replace("&", "&") | ||
|
||
return xml_string_data | ||
|
||
def get_lines_in_region(data): | ||
regions = defaultdict(list) | ||
for l in data['lines']: | ||
regions[l['region_id']].append(l) | ||
return regions | ||
|
||
if __name__ == "__main__": | ||
|
||
f1 = sys.argv[1] | ||
f2 = sys.argv[2] | ||
|
||
f1_files = {} | ||
for root, folders, files in os.walk(f1): | ||
for f in files: | ||
if f.endswith(".xml"): | ||
f1_files[f] = os.path.join(root, f) | ||
|
||
f2_files = {} | ||
for root, folders, files in os.walk(f2): | ||
for f in files: | ||
if f.endswith(".xml"): | ||
f2_files[f] = os.path.join(root, f) | ||
print len(f1_files) | ||
print len(f2_files) | ||
|
||
sum_dif = 0 | ||
results =[] | ||
running_sum = 0 | ||
|
||
for i, k in enumerate(sorted(f1_files)): | ||
filename = k | ||
f1 = f1_files[k] | ||
f2 = f2_files[k] | ||
|
||
xml1 = read_xml(f1) | ||
xml2 = read_xml(f2) | ||
|
||
data1 = parse_PAGE.readXMLFile(xml1)[0] | ||
data2 = parse_PAGE.readXMLFile(xml2)[0] | ||
|
||
|
||
region1 = get_lines_in_region(data1) | ||
region2 = get_lines_in_region(data2) | ||
|
||
joint_set = set(region1.keys()) | set(region2.keys()) | ||
xor_set = set(region1.keys()) ^ set(region2.keys()) | ||
|
||
if len(xor_set) != 0: | ||
print k, xor_set | ||
|
||
for k in set(region1.keys()) | set(region2.keys()): | ||
|
||
full_r1 = "\n".join([l['ground_truth'] for l in region1[k] ]) | ||
full_r2 = "\n".join([l['ground_truth'] for l in region2[k] ]) | ||
|
||
dis = editdistance.eval(full_r1, full_r2) | ||
|
||
length = (len(full_r1) + len(full_r2)) | ||
if length == 0: | ||
out = 0 | ||
else: | ||
out = dis / float(length) | ||
|
||
results.append((out, filename, k, i, full_r1, full_r2)) | ||
sum_dif += out | ||
print "WER", sum_dif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
network: | ||
sol: | ||
base0: 16 #architecture dependant - don't change | ||
base1: 16 #architecture dependant - don't change | ||
|
||
lf: | ||
look_ahead_matrix: | ||
step_bias: | ||
|
||
hw: | ||
num_of_outputs: 197 | ||
num_of_channels: 3 | ||
cnn_out_size: 1024 #architecture dependant | ||
input_height: 60 #architecture dependant | ||
char_set_path: "data/char_set.json" | ||
|
||
lm: | ||
fst_path: "../hwn5-comp-2017/data/comp_lm/data/graph/HCLG.fst" | ||
mdl_path: "../hwn5-comp-2017/data/comp_lm/data/lang_test/basic.mdl" | ||
words_path: "../hwn5-comp-2017/data/comp_lm/data/graph/words.txt" | ||
phones_path: "../hwn5-comp-2017/data/comp_lm/data/lang_test/phones.txt" | ||
beam: 8 | ||
|
||
pretraining: | ||
training_set: | ||
img_folder: "" | ||
json_folder: "" | ||
file_list: "data/train_a_training_set.json" | ||
|
||
validation_set: | ||
img_folder: "" | ||
json_folder: "" | ||
file_list: "data/train_a_validation_set.json" | ||
|
||
sol: | ||
alpha_alignment: 0.1 | ||
alpha_backprop: 0.1 | ||
learning_rate: 0.0001 #pyyaml bug: no scientific notation | ||
crop_params: | ||
prob_label: 0.5 | ||
crop_size: 256 | ||
training_rescale_range: [384, 640] | ||
validation_rescale_range: [512,512] #Don't validate on random range | ||
batch_size: 1 #During pretrain, only 45 images. If batch is 32 you would get 32 and 13 in an epoch | ||
images_per_epoch: 1000 | ||
stop_after_no_improvement: 10 | ||
|
||
lf: | ||
learning_rate: 0.0001 #pyyaml bug: no scientific notation | ||
batch_size: 1 | ||
images_per_epoch: 1000 | ||
stop_after_no_improvement: 10 | ||
|
||
hw: | ||
learning_rate: 0.0002 #pyyaml bug: no scientific notation | ||
batch_size: 8 | ||
images_per_epoch: 1000 | ||
stop_after_no_improvement: 10 | ||
|
||
snapshot_path: "data/snapshots/init" | ||
|
||
training: | ||
training_set: | ||
img_folder: "" | ||
json_folder: "" | ||
file_list: "data/train_b_training_set.json" | ||
|
||
validation_set: | ||
img_folder: "" | ||
json_folder: "" | ||
file_list: "data/train_b_validation_set.json" | ||
|
||
sol: | ||
alpha_alignment: 0.1 | ||
alpha_backprop: 0.1 | ||
learning_rate: 0.0001 #pyyaml bug: no scientific notation | ||
crop_params: | ||
prob_label: 0.5 | ||
crop_size: 256 | ||
training_rescale_range: [384, 640] | ||
validation_rescale_range: [512,512] #You should not validation on random range | ||
validation_subset_size: 1000 | ||
batch_size: 1 | ||
images_per_epoch: 10000 | ||
reset_interval: 3600 #seconds | ||
|
||
|
||
lf: | ||
learning_rate: 0.0001 #pyyaml bug: no scientific notation | ||
|
||
batch_size: 1 | ||
refresh_interval: 3600 #seconds | ||
images_per_epoch: 1000 #batches | ||
validation_subset_size: 100 #images | ||
reset_interval: 3600 #seconds | ||
|
||
hw: | ||
learning_rate: 0.0002 #pyyaml bug: no scientific notation | ||
|
||
batch_size: 8 | ||
refresh_interval: 3600 #seconds | ||
images_per_epoch: 20000 #batches | ||
validation_subset_size: 2000 #images | ||
reset_interval: 3600 #seconds | ||
|
||
alignment: | ||
accept_threshold: 0.1 | ||
sol_resize_width: 512 | ||
metric: "cer" | ||
train_refresh_groups: 10 | ||
|
||
validation_post_processing: | ||
sol_thresholds: [0.1,0.3,0.5,0.7,0.9] | ||
lf_nms_ranges: [[0,6],[0,16],[0,20]] | ||
lf_nms_thresholds: [0.1,0.3,0.5,0.7,0.9] | ||
|
||
snapshot: | ||
best_overall: "data/snapshots/best_overall" | ||
best_validation: "data/snapshots/best_validation" | ||
current: "data/snapshots/current" | ||
pretrain: "data/snapshots/init" | ||
|
||
post_processing: | ||
sol_threshold: 0.1 | ||
lf_nms_range: [0,6] | ||
lf_nms_threshold: 0.5 |