forked from chineseocr/chineseocr
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
优化代码结构,新增pytorch转keras模型代码,新增darknet训练代码,优化web界面显示,更新相关模型
- Loading branch information
1 parent
f2fd9c2
commit 2da42b1
Showing
46 changed files
with
1,649 additions
and
207 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
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
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,42 @@ | ||
#coding:utf-8 | ||
from crnn.utils import strLabelConverter,resizeNormalize | ||
|
||
from crnn.network_keras import keras_crnn as CRNN | ||
import tensorflow as tf | ||
graph = tf.get_default_graph()##解决web.py 相关报错问题 | ||
|
||
from crnn import keys | ||
from config import ocrModelKeras | ||
import numpy as np | ||
def crnnSource(): | ||
alphabet = keys.alphabetChinese##中英文模型 | ||
converter = strLabelConverter(alphabet) | ||
model = CRNN(32, 1, len(alphabet)+1, 256, 1,lstmFlag=False) | ||
model.load_weights(ocrModelKeras) | ||
return model,converter | ||
|
||
##加载模型 | ||
model,converter = crnnSource() | ||
|
||
def crnnOcr(image): | ||
""" | ||
crnn模型,ocr识别 | ||
image:PIL.Image.convert("L") | ||
""" | ||
scale = image.size[1]*1.0 / 32 | ||
w = image.size[0] / scale | ||
w = int(w) | ||
transformer = resizeNormalize((w, 32)) | ||
image = transformer(image) | ||
image = image.astype(np.float32) | ||
image = np.array([[image]]) | ||
global graph | ||
with graph.as_default(): | ||
preds = model.predict(image) | ||
preds = preds[0] | ||
preds = np.argmax(preds,axis=2).reshape((-1,)) | ||
sim_pred = converter.decode(preds) | ||
return sim_pred | ||
|
||
|
||
|
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
Oops, something went wrong.