daybreak-u / chineseocr_lite Goto Github PK
View Code? Open in Web Editor NEW超轻量级中文ocr,支持竖排文字识别, 支持ncnn、mnn、tnn推理 ( dbnet(1.8M) + crnn(2.5M) + anglenet(378KB)) 总模型仅4.7M
License: GNU General Public License v2.0
超轻量级中文ocr,支持竖排文字识别, 支持ncnn、mnn、tnn推理 ( dbnet(1.8M) + crnn(2.5M) + anglenet(378KB)) 总模型仅4.7M
License: GNU General Public License v2.0
D:\chineseocrlite\chineseocr_lite-master\psenet\pse>make
FIND: 参数格式不正确
process_begin: CreateProcess(NULL, python3-config --cflags, ...) failed.
process_begin: CreateProcess(NULL, python3-config --ldflags, ...) failed.
g++ -o pse.so -I include -std=c++11 -O3 pse.cpp --shared -fPIC
In file included from include/pybind11/pytypes.h:12:0,
from include/pybind11/cast.h:13,
from include/pybind11/attr.h:13,
from include/pybind11/pybind11.h:44,
from pse.cpp:8:
include/pybind11/detail/common.h:112:20: fatal error: Python.h: No such file or
directory
#include <Python.h>
^
compilation terminated.
Makefile:10: recipe for target 'pse.so' failed
make: *** [pse.so] Error 1
Flask
server.import time
import uuid
import numpy as np
from PIL import Image
from flask import Flask, request, jsonify
from config import *
from model import text_predict, crnn_handle
from apphelper.image import base64_to_PIL
from application import trainTicket, idcard
file_lock = "file.lock"
if os.path.exists(file_lock):
os.remove(file_lock)
app = Flask(__name__)
@app.route("/ocr", methods=["POST"])
def ocr():
if request.method == "POST":
request_start_time = time.time()
uid_job = uuid.uuid1().__str__()
data = request.json
# 模型参数
bill_model = data.get("billModel", "")
# 文字检测
# text_angle = data.get('textAngle', False)
# 只进行单行识别
text_line = data.get("textLine", False)
img_str = data["imgString"].encode().split(b";base64,")[-1]
img = base64_to_PIL(img_str)
if img is None:
response_time = time.time() - request_start_time
return jsonify({"res": [], "timeTake": round(response_time, 4)})
else:
img = np.array(img)
h, w = img.shape[:2]
final_result: list = []
while time.time() - request_start_time <= TIMEOUT:
if os.path.exists(file_lock):
continue
else:
with open(file_lock, "w") as f:
f.write(uid_job)
if text_line:
# 单行识别
part_img = Image.fromarray(img)
text = crnn_handle.predict(part_img)
final_result = [
{"text": text, "name": "0", "box": [0, 0, w, 0, w, h, 0, h]}
]
os.remove(file_lock)
break
else:
result = text_predict(img)
if bill_model == "" or bill_model == "通用OCR":
final_result = [
{
"text": x["text"],
"name": str(i),
"box": {
"cx": x["cx"],
"cy": x["cy"],
"w": x["w"],
"h": x["h"],
"angle": x["degree"],
},
}
for i, x in enumerate(result)
]
elif bill_model == "火车票":
train_ticket_result = trainTicket.trainTicket(result)
result = train_ticket_result.res
final_result = [
{"text": result[key], "name": key, "box": {}}
for key in result
]
elif bill_model == "身份证":
id_card_result = idcard.idcard(result)
result = id_card_result.res
final_result = [
{"text": result[key], "name": key, "box": {}}
for key in result
]
os.remove(file_lock)
break
response_time = time.time() - request_start_time
return jsonify({"res": final_result, "timeTake": round(response_time, 4)})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=9001, debug=True)
flake8
, black
to format your code, and also focus some words spelling.这是在用anaconda配置好环境后,在IDEA和cmd中出错都是这个, 找不到对应的包或者模块导入,在网上找了许多方法无法解决,本人是在Windows下搭建运行,不能像Ubuntu那样下载运行.so文件,也不能使用make,求助这里面的模块属于python的哪些包
我的.so文件是linux下的,你可以尝试在windows下使用docker
Originally posted by @ouyanghuiyu in #45 (comment)
如果不能执行make,是不是我只能在Linux环境下运行了?[难过][伤心]
作者您好,想问下如何使用自己的数据集(只包含字母和数字)去训练一个模型呢?我应该从哪里开始看呢?期待回复,谢谢
您好,ncnn检测识别怎么操作呢,可不可以说一下具体的执行步骤呢?
跟下面一个说的一样,会经常被killed。 个人感觉这个会严重影响这个开源项目的质量。
from .pse import pse_cpp
ImportError: Python version mismatch: module was compiled for Python 3.6, but the interpreter version is incompatible: 3.7.1 (default, Dec 18 2019, 23:13:02)
g++: error: unrecognized command line option ‘-fno-plt’
Makefile:10: recipe for target 'pse.so' failed
make: *** [pse.so] Error 1
File "/usr/local/python3/lib/python3.8/site-packages/web/template.py", line 948, in compile_template
SafeVisitor().walk(ast_node, filename)
File "/usr/local/python3/lib/python3.8/site-packages/web/template.py", line 1167, in walk
raise SecurityError('\n'.join([str(err) for err in self.errors]))
web.template.SecurityError: /usr/local/python3/lib/python3.8/site-packages/web/debugerror.py:3 - execution of 'Constant' statements is denied
/usr/local/python3/lib/python3.8/site-packages/web/debugerror.py:6 - execution of 'Constant' statements is denied
/usr/local/python3/lib/python3.8/site-packages/web/debugerror.py:7 - execution of 'Constant' statements is denied
/usr/local/python3/lib/python3.8/site-packages/web/debugerror.py:8 - execution of 'Constant' statements is denied
/usr/local/python3/lib/python3.8/site-packages/web/debugerror.py:9 - execution of 'Constant' statements is denied
device: cpu
load model
device: cpu
load model
device: cpu
load model
device: cpu
load model
http://0.0.0.0:8080/
36.27.60.250:56848 - - [12/Mar/2020 11:14:48] "HTTP/1.1 GET /ocr" - 200 OK
Segmentation fault
上传一个图片识别后,直接就报了Segmentation fault这个错误,我是在阿里云上跑的,难道是硬件不支持?
[root@localhost chineseocr_lite-master]# python3.6 main.py 8080
Traceback (most recent call last):
File "main.py", line 8, in
from text.detector.detectors import TextDetector
ModuleNotFoundError: No module named 'text'
然后报错了,请教一下,我这边 执行安装了命令:pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
请教一下是什么库没有安装么?
@ouyanghuiyu 你好
1)请问三个模型的训练文件什么时候会开源
2)将模型转为ncnn库模型,再训练吗,这样做的目的是什么
Loading test image from web browser got this error:
`find: -xtype: unknown primary or operator
make: pse.so is up to date.
device: cpu
load models
device: cpu
load models
device: cpu
load models
device: cpu
load models
http://0.0.0.0:8080/
127.0.0.1:57218 - - [04/Mar/2020 16:53:54] "HTTP/1.1 GET /ocr" - 200 OK
Traceback (most recent call last):
File "/Users/oblivion/anaconda3/envs/tf37/lib/python3.7/site-packages/web/application.py", line 289, in process
return self.handle()
File "/Users/oblivion/anaconda3/envs/tf37/lib/python3.7/site-packages/web/application.py", line 280, in handle
return self._delegate(fn, self.fvars, args)
File "/Users/oblivion/anaconda3/envs/tf37/lib/python3.7/site-packages/web/application.py", line 530, in _delegate
return handle_class(cls)
File "/Users/oblivion/anaconda3/envs/tf37/lib/python3.7/site-packages/web/application.py", line 508, in handle_class
return tocall(*args)
File "/Users/oblivion/chineseocr_lite/app.py", line 83, in POST
result= text_predict(img)
File "/Users/oblivion/chineseocr_lite/model.py", line 119, in text_predict
preds, boxes_list, rects_re, t = text_handle.predict(img, long_size=pse_long_size)
File "/Users/oblivion/chineseocr_lite/psenet/PSENET.py", line 99, in predict
preds, boxes_list,rects = pse_decode(preds[0], self.scale)
File "/Users/oblivion/chineseocr_lite/psenet/pse/init.py", line 58, in decode
pred, label_values = pse_warpper(preds, 5)
File "/Users/oblivion/chineseocr_lite/psenet/pse/init.py", line 19, in pse_warpper
from .pse import pse_cpp
ImportError: dlopen(/Users/oblivion/chineseocr_lite/psenet/pse/pse.so, 2): no suitable image found. Did find:
/Users/oblivion/chineseocr_lite/psenet/pse/pse.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x03
/Users/oblivion/chineseocr_lite/psenet/pse/pse.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x03
127.0.0.1:57226 - - [04/Mar/2020 16:54:43] "HTTP/1.1 POST /ocr" - 500 Internal Server Error
`
Any idea what happened?
Platform: MacOS 10.15.3 Python 3.7 Pytorch 1.4.0
Windows直接执行Make命令报错,求大佬写个CMakeLists
#48 大佬表示根据Makefile写个CMakeLists.txt,利用cmake生成sln文件,用Visual Studio编译成Windows平台DLL库,再给python调用
对于这方面实在是无从下手,求指教,跪谢~~~
text_handle预测时候卡住10s后 段错误(吐核) 然后退出。
pip install torch==1.2.0 torchvision==0.4.0
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
find: -xtype: unknown primary or operator
make: `pse.so' is up to date.
device: cpu
load models
device: cpu
load models
device: cpu
load models
device: cpu
load model
Traceback (most recent call last):
File "/Users/dane/anaconda3/lib/python3.7/site-packages/web/utils.py", line 526, in take
yield next(seq)
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "app.py", line 126, in
app = web.application(urls, globals())
File "/Users/dane/anaconda3/lib/python3.7/site-packages/web/application.py", line 62, in init
self.init_mapping(mapping)
File "/Users/dane/anaconda3/lib/python3.7/site-packages/web/application.py", line 130, in init_mapping
self.mapping = list(utils.group(mapping, 2))
File "/Users/dane/anaconda3/lib/python3.7/site-packages/web/utils.py", line 531, in group
x = list(take(seq, size))
RuntimeError: generator raised StopIteration
出错信息:Segmentation fault: 11
位置是:psenet/PSENET.py 中 preds, boxes_list,rects = pse_decode(preds[0], self.scale)
不知道是否可以fix一下。。
ncnn不支持lstm,openvino好像可以。
你好,识别模型是怎么训练的,会开源代码吗
运行python app.py 8080后终端显示:
make: Entering directory '/home/amither/Downloads/chineseocr_lite-master/psenet/pse'
make: 'pse.so' is up to date.
make: Leaving directory '/home/amither/Downloads/chineseocr_lite-master/psenet/pse'
device: cpu
load models
device: cpu
load models
device: cpu
load models
device: cpu
load model
http://0.0.0.0:8080/
127.0.0.1:58938 - - [10/Mar/2020 16:34:06] "HTTP/1.1 GET /ocr" - 200 OK
然后当我选择了一张图片后,就会一直打转不出结果,终端显示如下:
127.0.0.1:58938 - - [10/Mar/2020 16:34:06] "HTTP/1.1 GET /favicon.ico" - 404 Not Found
Traceback (most recent call last):
File "/home/amither/tensorflow/lib/python3.5/site-packages/web/application.py", line 257, in process
return self.handle()
File "/home/amither/tensorflow/lib/python3.5/site-packages/web/application.py", line 248, in handle
return self._delegate(fn, self.fvars, args)
File "/home/amither/tensorflow/lib/python3.5/site-packages/web/application.py", line 488, in _delegate
return handle_class(cls)
File "/home/amither/tensorflow/lib/python3.5/site-packages/web/application.py", line 466, in handle_class
return tocall(*args)
File "/home/amither/Downloads/chineseocr_lite-master/app.py", line 51, in POST
data = json.loads(data)
File "/usr/lib/python3.5/json/init.py", line 312, in loads
s.class.name))
TypeError: the JSON object must be str, not 'bytes'
127.0.0.1:58938 - - [10/Mar/2020 16:34:12] "HTTP/1.1 POST /ocr" - 500 Internal Server Error
Platform: VMware Ubuntu 16.04 python3.5.2 Pytorch1.4.0+cpu
请问这是为什么?
不知道轻量的检测模型是如何训练的?
Traceback (most recent call last):
File "app.py", line 12, in
from model import text_predict,crnn_handle
File "/home/wangdawei/github/ocr/chineseocr_lite/model.py", line 1, in
from config import *
File "/home/wangdawei/github/ocr/chineseocr_lite/config.py", line 40, in
from crnn.keys import alphabetChinese as alphabet
File "/home/wangdawei/github/ocr/chineseocr_lite/crnn/init.py", line 3, in
from .CRNN import CRNNHandle
ModuleNotFoundError: No module named 'crnn.CRNN'
192.168.11.99:53801 - - [12/Mar/2020 17:36:51] "HTTP/1.1 POST /ocr" - 500 Internal Server Error
192.168.11.99:53995 - - [12/Mar/2020 17:40:27] "HTTP/1.1 GET /ocr" - 200 OK
192.168.11.99:54217 - - [12/Mar/2020 17:43:11] "HTTP/1.1 GET /ocr" - 200 OK
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.8/site-packages/web/application.py", line 257, in process
return self.handle()
File "/usr/local/python3/lib/python3.8/site-packages/web/application.py", line 248, in handle
return self._delegate(fn, self.fvars, args)
File "/usr/local/python3/lib/python3.8/site-packages/web/application.py", line 488, in _delegate
return handle_class(cls)
File "/usr/local/python3/lib/python3.8/site-packages/web/application.py", line 466, in handle_class
return tocall(*args)
File "/root/data/chineseocr_lite_0311/chineseocr_lite-master/app.py", line 120, in POST
return json.dumps({'res':res,'timeTake':round(timeTake,4)},ensure_ascii=False)
UnboundLocalError: local variable 'res' referenced before assignment
192.168.11.99:54227 - - [12/Mar/2020 17:43:52] "HTTP/1.1 POST /ocr" - 500 Internal Server Error
请问运行环境是怎样的
lable_map_dict = { 0 : "hengdao", 1:"hengzhen", 2:"shudao", 3:"shuzhen"}
rotae_map_dict = {"hengdao": 180 , "hengzhen": 0 , "shudao": 180 , "shuzhen": 0 }
如题,用docker ps看了下端口确实从6666映射到8080了
hi, I looked your crnn_lite.py and crnn_full.py ,according to your readme ,crnn_lite.py is the network trained for vertical text recognition, but the difference between orign and vertical text recognition network is what?
I saw the crnn_lite is also like crnn_full ,So could you tell me the difference between the orign and vertical text recognition networks?
Thank you very much!
想请教一下,anglenet的输出是什么意思?看ncnn_project里给的示例是判断文本行的正反,但是网络输出了四个分类结果,后面两个是什么意思?这部分是否有相关的参考文档?
楼主好,我看您的模型效果很好,请问是用的什么数据集训练的?
ModuleNotFoundError: No module named 'torchvision.models.utils',但是我已经安装了'torchvision
size = ( int(size[0] + min_size*alph ) , int(size[1] + min_size*alph) )
您好,是否方便提供少量的竖排训练集的样例呢?
你好,请问你用了多少数据集,训练了多久。
使用ncnn_project下的crnn显示LSTM层不支持。
./Text_recognition ../models/crnn_lite_lstm_v2.bin ../models/crnn_lite_lstm_v2.param test.jpg
输出:
输入尺寸 (277, 32, 1)
layer LSTM not exists or registered
段错误 (核心已转储)
编译使用的是ocr目录下的ncnn lib库和include头文件。
Traceback (most recent call last):
File "C:\Users\Administrator\Downloads\chineseocr_lite-master\app.py", line 8, in
import web
ModuleNotFoundError: No module named 'web'
缺少了web.py?
我是在Windows7 python3.7.4 x64下运行的
make
g++ -o pse.so -I include -std=c++11 -O3 -I/home/wuqiang/anaconda3/envs/OCR00/include/python3.6m -I/home/wuqiang/anaconda3/envs/OCR00/include/python3.6m -Wno-unused-result -Wsign-compare -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O3 -ffunction-sections -pipe -fdebug-prefix-map=/tmp/build/80754af9/python_1564510748219/work=/usr/local/src/conda/python-3.6.9 -fdebug-prefix-map=/home/wuqiang/anaconda3/envs/OCR00=/usr/local/src/conda-prefix -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -flto -DNDEBUG -fwrapv -O3 -Wall -L/home/wuqiang/anaconda3/envs/OCR00/lib/python3.6/config-3.6m-x86_64-linux-gnu -L/home/wuqiang/anaconda3/envs/OCR00/lib -lpython3.6m -lpthread -ldl -lutil -lrt -lm -Xlinker -export-dynamic pse.cpp --shared -fPIC
g++: error: unrecognized command line option ‘-fno-plt’
Makefile:10: recipe for target 'pse.so' failed
make: *** [pse.so] Error 1
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pse.so] Error 1
你好,我是部署到阿里云服务器docker里面的,我在浏览器里面可以访问到,但上传身份证图片进行识别的时候,一直在转,没有识别出结果。服务器有时候报错kill(直接退出)、有时候报RuntimeError: can't alloc,就卡在这里。不知道是什么原因?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.