Skip to content

Commit

Permalink
feature: 扩充算术字符集,修改图片加载预处理
Browse files Browse the repository at this point in the history
  • Loading branch information
kerlomz committed Nov 5, 2020
1 parent ffe71b0 commit c1af547
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion category.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'V', 'W', 'X', 'Y', 'Z']
ALPHA_LOWER = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z']
ARITHMETIC = ['(', ')', '+', '-', '×', '÷', '=']
ARITHMETIC = ['(', ')', '+', '-', '×', '÷', '=', '?']
CHINESE_3500 = [
'一', '乙', '二', '十', '丁', '厂', '七', '卜', '人', '入', '八', '九', '几', '儿', '了', '力', '乃', '刀', '又', '三',
'于', '干', '亏', '士', '工', '土', '才', '寸', '下', '大', '丈', '与', '万', '上', '小', '口', '巾', '山', '千', '乞',
Expand Down Expand Up @@ -501,6 +501,7 @@
ALPHABET_UPPER=ALPHA_UPPER,
ALPHABET=ALPHA_LOWER + ALPHA_UPPER,
ARITHMETIC=NUMBER + ARITHMETIC,
ARITHMETIC_MIX_ALPHA_LOWER=NUMBER + ARITHMETIC + ALPHA_LOWER,
FLOAT=NUMBER + FLOAT,
CHS_3500=CHINESE_3500,
# Older Version
Expand Down
2 changes: 1 addition & 1 deletion resource/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20200923
20201101
2 changes: 1 addition & 1 deletion tornado_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def save_image(uid, label, image_bytes):
@run_on_executor
def predict(self, interface: Interface, image_batch, split_char):
result = interface.predict_batch(image_batch, split_char)
if interface.model_category == 'ARITHMETIC':
if 'ARITHMETIC' in interface.model_category:
if '=' in result or '+' in result or '-' in result or '×' in result or '÷' in result:
result = result.replace("×", "*").replace("÷", "/")
result = str(int(arithmetic.calc(result)))
Expand Down
10 changes: 8 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,14 @@ def load_image(image_bytes: bytes):

if (len(rgb) > 3 and model.pre_replace_transparent) and not gif_handle:
background = PIL_Image.new('RGB', pil_image.size, (255, 255, 255))
background.paste(pil_image, (0, 0, size[0], size[1]), pil_image)
pil_image = background
try:
background.paste(pil_image, (0, 0, size[0], size[1]), pil_image)
pil_image = background
except:
pil_image = pil_image.convert('RGB')

if len(pil_image.split()) > 3 and model.image_channel == 3:
pil_image = pil_image.convert('RGB')

if model.pre_concat_frames != -1:
im = concat_frames(pil_image, model.pre_concat_frames)
Expand Down

0 comments on commit c1af547

Please sign in to comment.