Skip to content
Snippets Groups Projects
Commit 51fec0fd authored by merschie's avatar merschie
Browse files

better preprocessor for training data

parent a5e6d89c
Branches
Tags
Loading
...@@ -98,6 +98,7 @@ class Preprocessor: ...@@ -98,6 +98,7 @@ class Preprocessor:
# data augmentation # data augmentation
img = img.astype(np.float) img = img.astype(np.float)
if self.data_augmentation: if self.data_augmentation:
# photometric data augmentation # photometric data augmentation
if random.random() < 0.25: if random.random() < 0.25:
def rand_odd(): def rand_odd():
...@@ -128,13 +129,34 @@ class Preprocessor: ...@@ -128,13 +129,34 @@ class Preprocessor:
target = np.ones(self.img_size[::-1]) * 255 target = np.ones(self.img_size[::-1]) * 255
img = cv2.warpAffine(img, M, dsize=self.img_size, dst=target, borderMode=cv2.BORDER_TRANSPARENT) img = cv2.warpAffine(img, M, dsize=self.img_size, dst=target, borderMode=cv2.BORDER_TRANSPARENT)
# photometric data augmentation # # photometric data augmentation
if random.random() < 0.5: # if random.random() < 0.5:
img = img * (0.25 + random.random() * 0.75) # img = img * (0.25 + random.random() * 0.75)
if random.random() < 0.25: # if random.random() < 0.25:
img = np.clip(img + (np.random.random(img.shape) - 0.5) * random.randint(1, 25), 0, 255) # img = np.clip(img + (np.random.random(img.shape) - 0.5) * random.randint(1, 25), 0, 255)
if random.random() < 0.1: # if random.random() < 0.1:
img = 255 - img # img = 255 - img
#random line on picture
img=img.astype(np.uint8)
img = cv2.blur(img,(3,3))
img = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
cv2.THRESH_BINARY,11,2)
start_hight =32- random.randint(0, int(32/4))
end_hight =32- random.randint(0, int(32/4))
thickness = random.randint(1, 3)
#draw line on image, starting at 0,start_hight, ending at w, end_hight
cv2.line(img, (0, start_hight), (127, end_hight), (0), thickness)
# show_img = img.astype(np.uint8)
# cv2.imshow('img', show_img)
# cv2.waitKey(1000)
img = img.astype(np.float)
# no data augmentation # no data augmentation
else: else:
......
...@@ -18,7 +18,7 @@ csv_path = '../tns.csv' ...@@ -18,7 +18,7 @@ csv_path = '../tns.csv'
char_list = htr.char_list_from_file() char_list = htr.char_list_from_file()
chars = ''.join(char_list) chars = ''.join(char_list)
word_chars = open('../model/wordCharList.txt').read().splitlines()[0] #word_chars = open('../model/wordCharList.txt').read().splitlines()[0]
matrikel_numbers = [] matrikel_numbers = []
@app.route('/getNames', methods=['GET']) @app.route('/getNames', methods=['GET'])
...@@ -43,10 +43,7 @@ def predictNach(): ...@@ -43,10 +43,7 @@ def predictNach():
model_name.corpus = open('../data/Nachname.txt').read().split()[:200] model_name.corpus = open('../data/Nachname.txt').read().split()[:200]
#check time of infer_batch #check time of infer_batch
start = time.time()
recognized, probability = htr_model.Model.infer_batch(model_name, batch) recognized, probability = htr_model.Model.infer_batch(model_name, batch)
end = time.time()
print("infer_batch time: ", end-start)
processed_image = processed_image + 0.5 processed_image = processed_image + 0.5
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment