Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41840029
PaddleOCR
提交
b55b8eda
P
PaddleOCR
项目概览
weixin_41840029
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b55b8eda
编写于
6月 04, 2020
作者:
T
tink2123
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add windows doc
上级
8d9324ca
变更
17
显示空白变更内容
内联
并排
Showing
17 changed file
with
42 addition
and
31 deletion
+42
-31
README.md
README.md
+5
-0
configs/rec/rec_chinese_lite_train.yml
configs/rec/rec_chinese_lite_train.yml
+0
-1
configs/rec/rec_icdar15_train.yml
configs/rec/rec_icdar15_train.yml
+1
-2
configs/rec/rec_mv3_none_bilstm_ctc.yml
configs/rec/rec_mv3_none_bilstm_ctc.yml
+0
-1
configs/rec/rec_mv3_none_none_ctc.yml
configs/rec/rec_mv3_none_none_ctc.yml
+0
-1
configs/rec/rec_mv3_tps_bilstm_attn.yml
configs/rec/rec_mv3_tps_bilstm_attn.yml
+0
-1
configs/rec/rec_mv3_tps_bilstm_ctc.yml
configs/rec/rec_mv3_tps_bilstm_ctc.yml
+0
-1
configs/rec/rec_r34_vd_none_bilstm_ctc.yml
configs/rec/rec_r34_vd_none_bilstm_ctc.yml
+0
-1
configs/rec/rec_r34_vd_none_none_ctc.yml
configs/rec/rec_r34_vd_none_none_ctc.yml
+0
-1
configs/rec/rec_r34_vd_tps_bilstm_attn.yml
configs/rec/rec_r34_vd_tps_bilstm_attn.yml
+0
-1
configs/rec/rec_r34_vd_tps_bilstm_ctc.yml
configs/rec/rec_r34_vd_tps_bilstm_ctc.yml
+0
-1
doc/inference.md
doc/inference.md
+4
-0
doc/installation.md
doc/installation.md
+6
-0
doc/recognition.md
doc/recognition.md
+5
-2
ppocr/data/rec/dataset_traversal.py
ppocr/data/rec/dataset_traversal.py
+10
-9
ppocr/data/rec/img_tools.py
ppocr/data/rec/img_tools.py
+2
-6
tools/infer/predict_rec.py
tools/infer/predict_rec.py
+9
-3
未找到文件。
README.md
浏览文件 @
b55b8eda
...
...
@@ -36,6 +36,8 @@ PaddleOCR旨在打造一套丰富、领先、且实用的OCR工具库,助力
#### 2.inference模型下载
*windows 环境下没有如果没有安装wget,下载模型时可将链接复制到浏览器中下载,并解压放置在相应目录下*
#### (1)超轻量级中文OCR模型下载
```
mkdir inference && cd inference
...
...
@@ -63,6 +65,9 @@ cd ..
# 设置PYTHONPATH环境变量
export PYTHONPATH=.
# windows下设置环境变量
SET PYTHONPATH=.
# 预测image_dir指定的单张图像
python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_det_mv3_db/" --rec_model_dir="./inference/ch_rec_mv3_crnn/"
...
...
configs/rec/rec_chinese_lite_train.yml
浏览文件 @
b55b8eda
...
...
@@ -9,7 +9,6 @@ Global:
eval_batch_step
:
2000
train_batch_size_per_card
:
256
test_batch_size_per_card
:
256
drop_last
:
false
image_shape
:
[
3
,
32
,
320
]
max_text_length
:
25
character_type
:
ch
...
...
configs/rec/rec_icdar15_train.yml
浏览文件 @
b55b8eda
...
...
@@ -9,13 +9,12 @@ Global:
eval_batch_step
:
500
train_batch_size_per_card
:
256
test_batch_size_per_card
:
256
drop_last
:
false
image_shape
:
[
3
,
32
,
100
]
max_text_length
:
25
character_type
:
en
loss_type
:
ctc
reader_yml
:
./configs/rec/rec_icdar15_reader.yml
pretrain_weights
:
pretrain_weights
:
./pretrain_models/rec_mv3_none_bilstm_ctc/best_accuracy
checkpoints
:
save_inference_dir
:
infer_img
:
...
...
configs/rec/rec_mv3_none_bilstm_ctc.yml
浏览文件 @
b55b8eda
...
...
@@ -9,7 +9,6 @@ Global:
eval_batch_step
:
2000
train_batch_size_per_card
:
256
test_batch_size_per_card
:
256
drop_last
:
false
image_shape
:
[
3
,
32
,
100
]
max_text_length
:
25
character_type
:
en
...
...
configs/rec/rec_mv3_none_none_ctc.yml
浏览文件 @
b55b8eda
...
...
@@ -9,7 +9,6 @@ Global:
eval_batch_step
:
2000
train_batch_size_per_card
:
256
test_batch_size_per_card
:
256
drop_last
:
false
image_shape
:
[
3
,
32
,
100
]
max_text_length
:
25
character_type
:
en
...
...
configs/rec/rec_mv3_tps_bilstm_attn.yml
浏览文件 @
b55b8eda
...
...
@@ -9,7 +9,6 @@ Global:
eval_batch_step
:
2000
train_batch_size_per_card
:
256
test_batch_size_per_card
:
256
drop_last
:
false
image_shape
:
[
3
,
32
,
100
]
max_text_length
:
25
character_type
:
en
...
...
configs/rec/rec_mv3_tps_bilstm_ctc.yml
浏览文件 @
b55b8eda
...
...
@@ -9,7 +9,6 @@ Global:
eval_batch_step
:
2000
train_batch_size_per_card
:
256
test_batch_size_per_card
:
256
drop_last
:
false
image_shape
:
[
3
,
32
,
100
]
max_text_length
:
25
character_type
:
en
...
...
configs/rec/rec_r34_vd_none_bilstm_ctc.yml
浏览文件 @
b55b8eda
...
...
@@ -9,7 +9,6 @@ Global:
eval_batch_step
:
2000
train_batch_size_per_card
:
256
test_batch_size_per_card
:
256
drop_last
:
false
image_shape
:
[
3
,
32
,
100
]
max_text_length
:
25
character_type
:
en
...
...
configs/rec/rec_r34_vd_none_none_ctc.yml
浏览文件 @
b55b8eda
...
...
@@ -9,7 +9,6 @@ Global:
eval_batch_step
:
2000
train_batch_size_per_card
:
256
test_batch_size_per_card
:
256
drop_last
:
false
image_shape
:
[
3
,
32
,
100
]
max_text_length
:
25
character_type
:
en
...
...
configs/rec/rec_r34_vd_tps_bilstm_attn.yml
浏览文件 @
b55b8eda
...
...
@@ -9,7 +9,6 @@ Global:
eval_batch_step
:
2000
train_batch_size_per_card
:
256
test_batch_size_per_card
:
256
drop_last
:
false
image_shape
:
[
3
,
32
,
100
]
max_text_length
:
25
character_type
:
en
...
...
configs/rec/rec_r34_vd_tps_bilstm_ctc.yml
浏览文件 @
b55b8eda
...
...
@@ -9,7 +9,6 @@ Global:
eval_batch_step
:
2000
train_batch_size_per_card
:
256
test_batch_size_per_card
:
256
drop_last
:
false
image_shape
:
[
3
,
32
,
100
]
max_text_length
:
25
character_type
:
en
...
...
doc/inference.md
浏览文件 @
b55b8eda
...
...
@@ -166,6 +166,10 @@ STAR-Net文本识别模型推理,可以执行如下命令:
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_336.png" --rec_model_dir="./inference/starnet/" --rec_image_shape="3, 32, 100" --rec_char_type="en"
```
### 3.基于Attention损失的识别模型推理
基于Attention损失的识别模型与ctc不同,需要额外设置识别算法参数 --rec_algorithm="RARE"
RARE 文本识别模型推理,可以执行如下命令:
```
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_336.png" --rec_model_dir="./inference/sare/" --rec_image_shape="3, 32, 100" --rec_char_type="en" --rec_algorithm="RARE"
...
...
doc/installation.md
浏览文件 @
b55b8eda
...
...
@@ -8,6 +8,8 @@ PaddleOCR 工作环境
建议使用我们提供的docker运行PaddleOCR,有关docker使用请参考
[
链接
](
https://docs.docker.com/get-started/
)
。
*如您希望使用 mac 或 windows直接运行预测代码,可以从第2步开始执行。*
1.
(建议)准备docker环境。第一次使用这个镜像,会自动下载该镜像,请耐心等待。
```
# 切换到工作目录下
...
...
@@ -54,6 +56,10 @@ python3 -m pip install paddlepaddle-gpu==1.7.2.post97 -i https://pypi.tuna.tsing
如果您的机器安装的是CUDA10,请运行以下命令安装
python3 -m pip install paddlepaddle-gpu==1.7.2.post107 -i https://pypi.tuna.tsinghua.edu.cn/simple
如果您的机器是CPU,请运行以下命令安装
python3 -m pip install paddlepaddle==1.7.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
更多的版本需求,请参照[安装文档](https://www.paddlepaddle.org.cn/install/quick)中的说明进行操作。
```
...
...
doc/recognition.md
浏览文件 @
b55b8eda
...
...
@@ -41,6 +41,8 @@ PaddleOCR 提供了一份用于训练 icdar2015 数据集的标签文件,通
wget -P ./train_data/ic15_data https://paddleocr.bj.bcebos.com/dataset/rec_gt_train.txt
# 测试集标签
wget -P ./train_data/ic15_data https://paddleocr.bj.bcebos.com/dataset/rec_gt_test.txt
```
最终训练集应有如下文件结构:
...
...
@@ -168,10 +170,11 @@ Global:
评估数据集可以通过
`configs/rec/rec_icdar15_reader.yml`
修改EvalReader中的
`label_file_path`
设置。
*注意*
评估时必须确保配置文件中 infer_img 字段为空
```
export CUDA_VISIBLE_DEVICES=0
# GPU 评估, Global.checkpoints 为待测权重
python3 tools/eval.py -c configs/rec/rec_
chinese_lite
_train.yml -o Global.checkpoints={path/to/weights}/best_accuracy
python3 tools/eval.py -c configs/rec/rec_
icdar15
_train.yml -o Global.checkpoints={path/to/weights}/best_accuracy
```
### 预测
...
...
@@ -184,7 +187,7 @@ python3 tools/eval.py -c configs/rec/rec_chinese_lite_train.yml -o Global.checkp
```
# 预测英文结果
python3 tools/infer_rec.py -c configs/rec/rec_
chinese_lite
_train.yml -o Global.checkpoints={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
python3 tools/infer_rec.py -c configs/rec/rec_
icdar15
_train.yml -o Global.checkpoints={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png
```
预测图片:
...
...
ppocr/data/rec/dataset_traversal.py
浏览文件 @
b55b8eda
...
...
@@ -42,14 +42,15 @@ class LMDBReader(object):
self
.
max_text_length
=
params
[
'max_text_length'
]
self
.
mode
=
params
[
'mode'
]
self
.
drop_last
=
False
self
.
tps
=
False
self
.
use_
tps
=
False
if
"tps"
in
params
:
self
.
tps
=
True
self
.
ues_
tps
=
True
if
params
[
'mode'
]
==
'train'
:
self
.
batch_size
=
params
[
'train_batch_size_per_card'
]
self
.
drop_last
=
params
[
'drop_last'
]
self
.
drop_last
=
True
else
:
self
.
batch_size
=
params
[
'test_batch_size_per_card'
]
self
.
drop_last
=
False
self
.
infer_img
=
params
[
'infer_img'
]
def
load_hierarchical_lmdb_dataset
(
self
):
...
...
@@ -114,7 +115,7 @@ class LMDBReader(object):
img
=
img
,
image_shape
=
self
.
image_shape
,
char_ops
=
self
.
char_ops
,
tps
=
self
.
tps
,
tps
=
self
.
use_
tps
,
infer_mode
=
True
)
yield
norm_img
else
:
...
...
@@ -181,15 +182,15 @@ class SimpleReader(object):
self
.
max_text_length
=
params
[
'max_text_length'
]
self
.
mode
=
params
[
'mode'
]
self
.
infer_img
=
params
[
'infer_img'
]
self
.
tps
=
False
self
.
use_
tps
=
False
if
"tps"
in
params
:
self
.
tps
=
True
self
.
drop_last
=
False
self
.
ues_tps
=
True
if
params
[
'mode'
]
==
'train'
:
self
.
batch_size
=
params
[
'train_batch_size_per_card'
]
self
.
drop_last
=
params
[
'drop_last'
]
self
.
drop_last
=
True
else
:
self
.
batch_size
=
params
[
'test_batch_size_per_card'
]
self
.
drop_last
=
False
def
__call__
(
self
,
process_id
):
if
self
.
mode
!=
'train'
:
...
...
@@ -206,7 +207,7 @@ class SimpleReader(object):
img
=
img
,
image_shape
=
self
.
image_shape
,
char_ops
=
self
.
char_ops
,
tps
=
self
.
tps
,
tps
=
self
.
use_
tps
,
infer_mode
=
True
)
yield
norm_img
else
:
...
...
ppocr/data/rec/img_tools.py
浏览文件 @
b55b8eda
...
...
@@ -95,11 +95,7 @@ def process_image(img,
max_text_length
=
None
,
tps
=
None
,
infer_mode
=
False
):
if
not
infer_mode
or
char_ops
.
character_type
==
"en"
:
norm_img
=
resize_norm_img
(
img
,
image_shape
)
else
:
if
tps
!=
None
and
char_ops
.
character_type
==
"ch"
:
image_shape
=
[
3
,
32
,
320
]
if
not
infer_mode
or
char_ops
.
character_type
==
"en"
or
tps
!=
None
:
norm_img
=
resize_norm_img
(
img
,
image_shape
)
else
:
norm_img
=
resize_norm_img_chinese
(
img
,
image_shape
)
...
...
tools/infer/predict_rec.py
浏览文件 @
b55b8eda
...
...
@@ -38,8 +38,10 @@ class TextRecognizer(object):
char_ops_params
[
"character_dict_path"
]
=
args
.
rec_char_dict_path
if
self
.
rec_algorithm
!=
"RARE"
:
char_ops_params
[
'loss_type'
]
=
'ctc'
self
.
loss_type
=
'ctc'
else
:
char_ops_params
[
'loss_type'
]
=
'attention'
self
.
loss_type
=
'attention'
self
.
char_ops
=
CharacterOps
(
char_ops_params
)
def
resize_norm_img
(
self
,
img
,
max_wh_ratio
):
...
...
@@ -85,7 +87,7 @@ class TextRecognizer(object):
self
.
input_tensor
.
copy_from_cpu
(
norm_img_batch
)
self
.
predictor
.
zero_copy_run
()
if
self
.
rec_algorithm
!=
"RARE
"
:
if
self
.
loss_type
==
"ctc
"
:
rec_idx_batch
=
self
.
output_tensors
[
0
].
copy_to_cpu
()
rec_idx_lod
=
self
.
output_tensors
[
0
].
lod
()[
0
]
predict_batch
=
self
.
output_tensors
[
1
].
copy_to_cpu
()
...
...
@@ -139,9 +141,13 @@ if __name__ == "__main__":
img_list
.
append
(
img
)
try
:
rec_res
,
predict_time
=
text_recognizer
(
img_list
)
except
:
except
Exception
as
e
:
print
(
e
)
logger
.
info
(
"ERROR!!
\n
Input image shape is not equal with config. TPS does not support variable shape.
\n
"
"ERROR!!!!
\n
"
"Please read the FAQ:https://github.com/PaddlePaddle/PaddleOCR#faq
\n
"
"If your model has tps module: "
"TPS does not support variable shape.
\n
"
"Please set --rec_image_shape=input_shape and --rec_char_type='en' "
)
exit
()
for
ino
in
range
(
len
(
img_list
)):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录