Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
fc437d49
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
fc437d49
编写于
10月 16, 2019
作者:
W
whs
提交者:
GitHub
10月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change layers.data to fluid.data in ocr model (#3594)
1. Change layers.data to fluid.data 2. Add check_version in ocr model
上级
9e89cba0
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
40 addition
and
22 deletion
+40
-22
PaddleCV/ocr_recognition/README.md
PaddleCV/ocr_recognition/README.md
+1
-1
PaddleCV/ocr_recognition/attention_model.py
PaddleCV/ocr_recognition/attention_model.py
+14
-14
PaddleCV/ocr_recognition/crnn_ctc_model.py
PaddleCV/ocr_recognition/crnn_ctc_model.py
+3
-3
PaddleCV/ocr_recognition/data_reader.py
PaddleCV/ocr_recognition/data_reader.py
+1
-1
PaddleCV/ocr_recognition/eval.py
PaddleCV/ocr_recognition/eval.py
+2
-1
PaddleCV/ocr_recognition/infer.py
PaddleCV/ocr_recognition/infer.py
+2
-1
PaddleCV/ocr_recognition/train.py
PaddleCV/ocr_recognition/train.py
+2
-1
PaddleCV/ocr_recognition/utility.py
PaddleCV/ocr_recognition/utility.py
+15
-0
未找到文件。
PaddleCV/ocr_recognition/README.md
浏览文件 @
fc437d49
>注意:在paddle1.5版本上训练attention model有收敛问题,建议您暂时使用paddle1.4版本,后续我们会修复该问题。
>注意:在paddle1.5版本上训练attention model有收敛问题,建议您暂时使用paddle1.4版本
和models1.5分支
,后续我们会修复该问题。
## 代码结构
```
...
...
PaddleCV/ocr_recognition/attention_model.py
浏览文件 @
fc437d49
...
...
@@ -165,11 +165,11 @@ def gru_decoder_with_attention(target_embedding, encoder_vec, encoder_proj,
def
attention_train_net
(
args
,
data_shape
,
num_classes
):
images
=
fluid
.
layers
.
data
(
name
=
'pixel'
,
shape
=
data_shape
,
dtype
=
'float32'
)
label_in
=
fluid
.
layers
.
data
(
name
=
'label_in'
,
shape
=
[
1
],
dtype
=
'int32'
,
lod_level
=
1
)
label_out
=
fluid
.
layers
.
data
(
name
=
'label_out'
,
shape
=
[
1
],
dtype
=
'int32'
,
lod_level
=
1
)
images
=
fluid
.
data
(
name
=
'pixel'
,
shape
=
[
None
]
+
data_shape
,
dtype
=
'float32'
)
label_in
=
fluid
.
data
(
name
=
'label_in'
,
shape
=
[
None
,
1
],
dtype
=
'int32'
,
lod_level
=
1
)
label_out
=
fluid
.
data
(
name
=
'label_out'
,
shape
=
[
None
,
1
],
dtype
=
'int32'
,
lod_level
=
1
)
gru_backward
,
encoded_vector
,
encoded_proj
=
encoder_net
(
images
)
...
...
@@ -264,10 +264,10 @@ def attention_infer(images, num_classes, use_cudnn=True):
ids_array
=
fluid
.
layers
.
create_array
(
'int64'
)
scores_array
=
fluid
.
layers
.
create_array
(
'float32'
)
init_ids
=
fluid
.
layers
.
data
(
name
=
"init_ids"
,
shape
=
[
1
],
dtype
=
"int64"
,
lod_level
=
2
)
init_scores
=
fluid
.
layers
.
data
(
name
=
"init_scores"
,
shape
=
[
1
],
dtype
=
"float32"
,
lod_level
=
2
)
init_ids
=
fluid
.
data
(
name
=
"init_ids"
,
shape
=
[
None
,
1
],
dtype
=
"int64"
,
lod_level
=
2
)
init_scores
=
fluid
.
data
(
name
=
"init_scores"
,
shape
=
[
None
,
1
],
dtype
=
"float32"
,
lod_level
=
2
)
fluid
.
layers
.
array_write
(
init_ids
,
array
=
ids_array
,
i
=
counter
)
fluid
.
layers
.
array_write
(
init_scores
,
array
=
scores_array
,
i
=
counter
)
...
...
@@ -349,11 +349,11 @@ def attention_infer(images, num_classes, use_cudnn=True):
def
attention_eval
(
data_shape
,
num_classes
,
use_cudnn
=
True
):
images
=
fluid
.
layers
.
data
(
name
=
'pixel'
,
shape
=
data_shape
,
dtype
=
'float32'
)
label_in
=
fluid
.
layers
.
data
(
name
=
'label_in'
,
shape
=
[
1
],
dtype
=
'int32'
,
lod_level
=
1
)
label_out
=
fluid
.
layers
.
data
(
name
=
'label_out'
,
shape
=
[
1
],
dtype
=
'int32'
,
lod_level
=
1
)
images
=
fluid
.
data
(
name
=
'pixel'
,
shape
=
[
None
]
+
data_shape
,
dtype
=
'float32'
)
label_in
=
fluid
.
data
(
name
=
'label_in'
,
shape
=
[
None
,
1
],
dtype
=
'int32'
,
lod_level
=
1
)
label_out
=
fluid
.
data
(
name
=
'label_out'
,
shape
=
[
None
,
1
],
dtype
=
'int32'
,
lod_level
=
1
)
label_out
=
fluid
.
layers
.
cast
(
x
=
label_out
,
dtype
=
'int64'
)
label_in
=
fluid
.
layers
.
cast
(
x
=
label_in
,
dtype
=
'int64'
)
...
...
PaddleCV/ocr_recognition/crnn_ctc_model.py
浏览文件 @
fc437d49
...
...
@@ -190,9 +190,9 @@ def ctc_train_net(args, data_shape, num_classes):
learning_rate_decay
=
None
regularizer
=
fluid
.
regularizer
.
L2Decay
(
L2_RATE
)
images
=
fluid
.
layers
.
data
(
name
=
'pixel'
,
shape
=
data_shape
,
dtype
=
'float32'
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int32'
,
lod_level
=
1
)
images
=
fluid
.
data
(
name
=
'pixel'
,
shape
=
[
None
]
+
data_shape
,
dtype
=
'float32'
)
label
=
fluid
.
data
(
name
=
'label'
,
shape
=
[
None
,
1
],
dtype
=
'int32'
,
lod_level
=
1
)
fc_out
=
encoder_net
(
images
,
num_classes
,
...
...
PaddleCV/ocr_recognition/data_reader.py
浏览文件 @
fc437d49
...
...
@@ -32,7 +32,7 @@ except NameError:
SOS
=
0
EOS
=
1
NUM_CLASSES
=
95
DATA_SHAPE
=
[
1
,
48
,
512
]
DATA_SHAPE
=
[
1
,
48
,
None
]
DATA_MD5
=
"7256b1d5420d8c3e74815196e58cdad5"
DATA_URL
=
"http://paddle-ocr-data.bj.bcebos.com/data.tar.gz"
...
...
PaddleCV/ocr_recognition/eval.py
浏览文件 @
fc437d49
...
...
@@ -13,7 +13,7 @@
# limitations under the License.
import
paddle.fluid
as
fluid
from
utility
import
add_arguments
,
print_arguments
,
to_lodtensor
,
get_ctc_feeder_data
,
get_attention_feeder_data
from
utility
import
check_gpu
from
utility
import
check_gpu
,
check_version
from
attention_model
import
attention_eval
from
crnn_ctc_model
import
ctc_eval
import
data_reader
...
...
@@ -85,6 +85,7 @@ def main():
args
=
parser
.
parse_args
()
print_arguments
(
args
)
check_gpu
(
args
.
use_gpu
)
check_version
()
evaluate
(
args
)
...
...
PaddleCV/ocr_recognition/infer.py
浏览文件 @
fc437d49
...
...
@@ -14,7 +14,7 @@
from
__future__
import
print_function
import
paddle.fluid
as
fluid
from
utility
import
add_arguments
,
print_arguments
,
to_lodtensor
,
get_ctc_feeder_data
,
get_attention_feeder_for_infer
,
get_ctc_feeder_for_infer
from
utility
import
check_gpu
from
utility
import
check_gpu
,
check_version
import
paddle.fluid.profiler
as
profiler
from
crnn_ctc_model
import
ctc_infer
from
attention_model
import
attention_infer
...
...
@@ -153,6 +153,7 @@ def main():
args
=
parser
.
parse_args
()
print_arguments
(
args
)
check_gpu
(
args
.
use_gpu
)
check_version
()
if
args
.
profile
:
if
args
.
use_gpu
:
with
profiler
.
cuda_profiler
(
"cuda_profiler.txt"
,
'csv'
)
as
nvprof
:
...
...
PaddleCV/ocr_recognition/train.py
浏览文件 @
fc437d49
...
...
@@ -17,7 +17,7 @@ from __future__ import division
from
__future__
import
print_function
import
paddle.fluid
as
fluid
from
utility
import
add_arguments
,
print_arguments
,
to_lodtensor
,
get_ctc_feeder_data
,
get_attention_feeder_data
from
utility
import
check_gpu
from
utility
import
check_gpu
,
check_version
import
paddle.fluid.profiler
as
profiler
from
crnn_ctc_model
import
ctc_train_net
from
attention_model
import
attention_train_net
...
...
@@ -230,6 +230,7 @@ def main():
args
=
parser
.
parse_args
()
print_arguments
(
args
)
check_gpu
(
args
.
use_gpu
)
check_version
()
if
args
.
profile
:
if
args
.
use_gpu
:
with
profiler
.
cuda_profiler
(
"cuda_profiler.txt"
,
'csv'
)
as
nvprof
:
...
...
PaddleCV/ocr_recognition/utility.py
浏览文件 @
fc437d49
...
...
@@ -159,3 +159,18 @@ def check_gpu(use_gpu):
sys
.
exit
(
1
)
except
Exception
as
e
:
pass
def
check_version
():
"""
Log error and exit when the installed version of paddlepaddle is
not satisfied.
"""
err
=
"PaddlePaddle version 1.6 or higher is required, "
\
"or a suitable develop version is satisfied as well.
\n
"
\
"Please make sure the version is good with your code."
\
try
:
fluid
.
require_version
(
'1.6.0'
)
except
Exception
as
e
:
logger
.
error
(
err
)
sys
.
exit
(
1
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录