Skip to content

Commit

Permalink
infer 精简
Browse files Browse the repository at this point in the history
  • Loading branch information
zzccchen committed Jan 28, 2019
1 parent a2a2851 commit f4449f1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 37 deletions.
5 changes: 1 addition & 4 deletions API/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,4 @@ iview-project-3.0/src/images/test_images/*.png
*.exe
log/*.log.*
log/*.log
*.cfg

*.png
*.png
*.cfg
32 changes: 2 additions & 30 deletions API/ocr_paddle/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import numpy as np
import paddle.fluid as fluid
from PIL import Image, ImageEnhance, ImageFilter
from PIL import Image, ImageFilter

from .crnn_ctc_model import ctc_infer
from .utility import get_ctc_feeder_data
Expand Down Expand Up @@ -69,7 +69,7 @@ def prepare_inferenc():

# define network
images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32')
ids = infer(images, num_classes, use_cudnn=True)
ids = infer(images, num_classes, use_cudnn=args.use_gpu)

# prepare environment
place = fluid.CUDAPlace(0)
Expand Down Expand Up @@ -121,34 +121,6 @@ def load_image(img):
39: '8', 40: '9'}


def deal_with_result(indexes, batch_time, dict_map_path=None):
# load dictionary
# dict_map = {}
# if dict_map_path is not None and os.path.isfile(dict_map_path):
# with open(dict_map_path) as dict_file:
# for i, word in enumerate(dict_file):
# dict_map[i] = word.strip()
# print("Loaded dict from %s" % dict_map_path)

temp_list = []
if len(dict_map) != 0: # 如果 dict 不空,那么就做映射
temp_list = []
keys = dict_map.keys()
for i in indexes:
if i in keys:
word = dict_map[i]
temp_list.append(word)
else:
temp_list.append('*')
else:
temp_list = indexes
print("latency: %.5f s, result: %s" % (
batch_time,
temp_list))
result = {"index": indexes, "mapped": temp_list, "batch_time": batch_time}
return result


def prune(words, sos, eos):
"""Remove unused tokens in prediction result."""
start_index = 0
Expand Down
6 changes: 4 additions & 2 deletions API/papi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

import json
import platform

import requests
# import os
from PIL import Image, ImageEnhance, ImageFilter
from PIL import Image
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop

from handler import BaseHandler
from log import LogBase
from route import app
from ocr_paddle import real_infer
from route import app

if ('2.' in platform.python_version()):
from StringIO import StringIO as Bytes2Data
else:
Expand Down
2 changes: 1 addition & 1 deletion frontpage/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "PeggyPeggy",
"name": "PeppaPeppa",
"version": "3.0.0",
"description": "A OCR verification code recognition module demo based on Paddlepaddle.",
"main": "index.js",
Expand Down

0 comments on commit f4449f1

Please sign in to comment.