Coder Social home page Coder Social logo

table-detect's Introduction

本项目基于yolo3crnn 实现中文自然场景文字检测及识别

训练代码(master分支)

ocr训练数据集

ocr ctc训练数据集(压缩包解码:chineseocr)
百度网盘地址:链接: https://pan.baidu.com/s/1UcUKUUELLwdM29zfbztzdw 提取码: atwn
gofile地址:http://gofile.me/4Nlqh/uT32hAjbx 密码 https://github.com/chineseocr/chineseocr

实现功能

  • 文字方向检测 0、90、180、270度检测(支持dnn/tensorflow)
  • 支持(darknet/opencv dnn /keras)文字检测,支持darknet/keras训练
  • 不定长OCR训练(英文、中英文) crnn\dense ocr 识别及训练 ,新增pytorch转keras模型代码(tools/pytorch_to_keras.py)
  • 支持darknet 转keras, keras转darknet, pytorch 转keras模型
  • 身份证/火车票结构化数据识别
  • 新增CNN+ctc模型,支持DNN模块调用OCR,单行图像平均时间为0.02秒以下
  • CPU版本加速
  • 支持基于用户字典OCR识别
  • 新增语言模型修正OCR识别结果
  • 支持树莓派实时识别方案

环境部署

GPU部署 参考:setup.md
CPU部署 参考:setup-cpu.md

下载编译darknet(如果直接运用opencv dnn或者keras yolo3 可忽略darknet的编译)

git clone https://github.com/pjreddie/darknet.git 
mv darknet chineseocr/
##编译对GPU、cudnn的支持 修改 Makefile
#GPU=1
#CUDNN=1
#OPENCV=0
#OPENMP=0
make 

修改 darknet/python/darknet.py line 48
root = '/root/'##chineseocr所在目录
lib = CDLL(root+"chineseocr/darknet/libdarknet.so", RTLD_GLOBAL)

下载模型文件

模型文件地址:

模型转换(非必须)

pytorch ocr 转keras ocr

python tools/pytorch_to_keras.py  -weights_path models/ocr-dense.pth -output_path models/ocr-dense-keras.h5

darknet 转keras

python tools/darknet_to_keras.py -cfg_path models/text.cfg -weights_path models/text.weights -output_path models/text.h5

keras 转darknet

python tools/keras_to_darknet.py -cfg_path models/text.cfg -weights_path models/text.h5 -output_path models/text.weights

模型选择

参考config.py文件

构建docker镜像

##下载Anaconda3 python 环境安装包(https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh) 放置在chineseocr目录下   
##建立镜像   
docker build -t chineseocr .   
##启动服务   
docker run -d -p 8080:8080 chineseocr /root/anaconda3/bin/python app.py

web服务启动

cd chineseocr## 进入chineseocr目录
python app.py 8080 ##8080端口号,可以设置任意端口

访问服务

http://127.0.0.1:8080/ocr

识别结果展示

参考

  1. yolo3 https://github.com/pjreddie/darknet.git
  2. crnn https://github.com/meijieru/crnn.pytorch.git
  3. ctpn https://github.com/eragonruan/text-detection-ctpn
  4. CTPN https://github.com/tianzhi0549/CTPN
  5. keras yolo3 https://github.com/qqwweee/keras-yolo3.git
  6. darknet keras 模型转换参考 参考:https://www.cnblogs.com/shouhuxianjian/p/10567201.html
  7. 语言模型实现 https://github.com/lukhy/masr

table-detect's People

Contributors

wenlihaoyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

table-detect's Issues

线条检测不准

训练出来之后,用训练的图片测试,线条检测准
edc36cf4-803f-11ed-947d-18c04dbd683e
但重新拍照检测又不准了,这个会是什么问题
Uploading 9ef66d98-80ca-11ed-b0d0-18c04dbd683e.png…

Issue with accuracy and loss during training

Hello,

I tried training a model with my own data after annotating it using label-me. But while training I observed that my training loss is not converging nor is my accuracy increasing. It is stuck within a range of values (0.45 - 0.55 for accuracy). Any Idea why this is happening ?

Error

您好,请问下模型和cfg文件不匹配怎么解决?

训练数据集

尊敬的作者:
您好。
下载了您预训练好的表格线识别模型,效果挺好。想请教一下,您训练table-line这个模型,用的什么数据集。我看到您的代码目录里有5张用于训练表格线的图片及标注。难道就只是用这5张图片训练的吗?

关于数据集的问题

首先,非常感谢您的分享。我尝试了表格识别,然后后处理稍微修改一点,效果非常棒。
其中,如果我想 迁移学习,有什么公开数据集可以训练unet么?
下载了TableBank和其他的,他们的标签要么作表格检测,要么是预测 表格单元关系。
不会真的都要用 LabelImage制作segmentation img吧。 手动狗头

无线表格

该模型是不支持无线表格的分割吧

unet主干网络sigmoid选用

作者您好,感谢您对于表格识别的杰出工作,我这里现在有个问题
classify = Conv2D(num_classes, (1, 1), activation='sigmoid')(up0a)
这里既然num_classes是2,多分类问题了,为啥选用sigmoid作为激活函数呢?

Datasource / Paper?

Hi,

I am keen to know if there is any research information available about the line detection model. Is the model based on a paper? How and where did you get the training data set?

关于分割

您好,请问下如果不做检测,直接分割,为什么会产生这样的列分割线?? 无边框的也可以分割吗?
7AC44275-3F10-4BDB-B99F-EBAF99E3C774
Uploading 5B54C8D5-B8C6-4462-9490-ACE929C1A35C.jpeg…

数据标注问题

大佬您好,我想问一下,数据标注的时候,我看tablenet分成了两类,如果横向和纵向重叠的时候,该如何分类呢 @ @wenlihaoyu

检测到的横竖线中间被截断,或者整条横竖线不能被完全检测,只能检测到横竖线的部分线段如下图

标注了500张图片重新训练tableline模型,其中标注数据中有手拍表格图片,所以对于拍摄变形的图片中的表格横竖线,某一条横线如果只用一条横线标注,可能不能完全重合,因此一条横线可能被分成了两段或者三段横线进行标注。训练了10epoch,最终训练集上acc稳定到了0.99左右,loss0.019左右,但是用训练后的模型,在训练集上推理,检测到的横竖线效果很不好,同一条线段可能只能检测到线段上的部分,而不能完全检测整条线段。
请问是标注的训练数据的问题嘛,是不是训练数据的横竖线必须是横平
table-line
竖直那种横线,如果对于有拍摄畸变的图片,对于畸变横线标注时候也必须用一条横线标注,还是可以畸变横线被分成两段或者三段进行标注呢。
请问是训练数据太少呢,还是标注数据的问题呢还是训练epoch太少的原因呢,您给出的模型是用多少数据训练的呢

关于用自己训练数据,table_ceil.py报错

作者代码里train.py,训练是在table-line.h5 基础上迁移学习,我使用自己的数据,table_line.py,注释model.load_weights(tableModeLinePath),训练出来的模型,在运行预测table_ceil.py,报错,运行table_line.py,不报错,但是预测图片没有任何线条
GeForce GTX 1080 Ti, pci bus id: 0000:00:06.0, compute capability: 6.1) 1 Physical GPUs, 1 Logical GPUs 2020-10-15 17:30:16.059743: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7 Traceback (most recent call last): File "table_ceil.py", line 105, in <module> tableDetect = table(img) File "table_ceil.py", line 25, in __init__ self.table_ceil() ##表格单元格定位 File "table_ceil.py", line 71, in table_ceil ceilboxes[:, [0, 2, 4, 6]] += xmin IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

识别问题

检测完单元格后,对单元格的内容进行识别,会把表格的边框当成是文字进行识别,想问下这个问题怎么解决

utils.py模块中的adjust_lines函数存在使得line_to_line函数报分母为0的BUG

r = sqrt((x2, y2), (x3, y3))

稳定触发报错的例子:
1.ColsLines[i] = (189,5,189,92);ColsLines[j] = (202, 92, 202, 396),即(x2,y2) = (189, 92),(x3,y3) = (202, 92),r = sqrt((x2, y2), (x3, y3)) < alph 成立
2.会执行newColsLines.append([x2, y2, x3, y3]),但此处显然[189,92,202,92]是一条横线
3.newColsLines列表里混入横线后,运行到line_to_line函数时,只要与[189,92,202,92]计算的另一条横线y值相同,就会导致fit_line时直线系数A为0

A = y2 - y1

4.最后导致分母"A1B2-A2B1"为0报错
x = (B1 * C2 - B2 * C1) / (A1 * B2 - A2 * B1)

5.同样adjust_lines函数第152,156,176行这三条分支都会触发上述错误

问题导致原因:
RowsLines循环时,两条row_line特殊情况会产生一条垂直的col_line,需要增加判断条件加到newColsLines而非newRowsLines,ColsLines循环同理。

解决方案:增加调整后新增线段是否水平垂直

# 其他情况同理
r = sqrt((x1, y1), (x4, y4))
delta_x = x1 - x4
if r < alph:
    if delta_x == 0.0:
        newColsLines.append([x1, y1, x4, y4])
    else:
        newRowsLines.append([x1, y1, x4, y4])

训练

感谢您的分享,请问有训练模型的工程吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.