Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
hapi
提交
2ad718f7
H
hapi
项目概览
PaddlePaddle
/
hapi
通知
11
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hapi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2ad718f7
编写于
4月 20, 2020
作者:
Q
qingqing01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean code
上级
ee2054da
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
8 addition
and
39 deletion
+8
-39
examples/ocr/data.py
examples/ocr/data.py
+0
-34
examples/ocr/eval.py
examples/ocr/eval.py
+3
-2
examples/ocr/predict.py
examples/ocr/predict.py
+2
-1
examples/ocr/train.py
examples/ocr/train.py
+3
-2
未找到文件。
examples/ocr/data.py
浏览文件 @
2ad718f7
...
@@ -29,40 +29,6 @@ TRAIN_LIST_FILE_NAME = "train.list"
...
@@ -29,40 +29,6 @@ TRAIN_LIST_FILE_NAME = "train.list"
TEST_LIST_FILE_NAME
=
"test.list"
TEST_LIST_FILE_NAME
=
"test.list"
class
BatchCompose
(
object
):
def
__init__
(
self
,
transforms
=
[]):
self
.
transforms
=
transforms
def
__call__
(
self
,
data
):
for
f
in
self
.
transforms
:
try
:
data
=
f
(
data
)
except
Exception
as
e
:
stack_info
=
traceback
.
format_exc
()
logger
.
info
(
"fail to perform batch transform [{}] with error: "
"{} and stack:
\n
{}"
.
format
(
f
,
e
,
str
(
stack_info
)))
raise
e
# sample list to batch data
batch
=
list
(
zip
(
*
data
))
return
batch
class
Compose
(
object
):
def
__init__
(
self
,
transforms
=
[]):
self
.
transforms
=
transforms
def
__call__
(
self
,
*
data
):
for
f
in
self
.
transforms
:
try
:
data
=
f
(
*
data
)
except
Exception
as
e
:
stack_info
=
traceback
.
format_exc
()
logger
.
info
(
"fail to perform transform [{}] with error: "
"{} and stack:
\n
{}"
.
format
(
f
,
e
,
str
(
stack_info
)))
raise
e
return
data
class
Resize
(
object
):
class
Resize
(
object
):
def
__init__
(
self
,
height
=
48
):
def
__init__
(
self
,
height
=
48
):
self
.
interp
=
Image
.
NEAREST
# Image.ANTIALIAS
self
.
interp
=
Image
.
NEAREST
# Image.ANTIALIAS
...
...
examples/ocr/eval.py
浏览文件 @
2ad718f7
...
@@ -20,6 +20,7 @@ import paddle.fluid.profiler as profiler
...
@@ -20,6 +20,7 @@ import paddle.fluid.profiler as profiler
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
hapi.model
import
Input
,
set_device
from
hapi.model
import
Input
,
set_device
from
hapi.vision.transforms
import
BatchCompose
from
utility
import
add_arguments
,
print_arguments
from
utility
import
add_arguments
,
print_arguments
from
utility
import
SeqAccuracy
,
MyProgBarLogger
,
SeqBeamAccuracy
from
utility
import
SeqAccuracy
,
MyProgBarLogger
,
SeqBeamAccuracy
...
@@ -73,7 +74,7 @@ def main(FLAGS):
...
@@ -73,7 +74,7 @@ def main(FLAGS):
model
.
load
(
FLAGS
.
init_model
)
model
.
load
(
FLAGS
.
init_model
)
test_dataset
=
data
.
test
()
test_dataset
=
data
.
test
()
test_collate_fn
=
data
.
BatchCompose
(
test_collate_fn
=
BatchCompose
(
[
data
.
Resize
(),
data
.
Normalize
(),
data
.
PadTarget
()])
[
data
.
Resize
(),
data
.
Normalize
(),
data
.
PadTarget
()])
test_sampler
=
data
.
MyBatchSampler
(
test_sampler
=
data
.
MyBatchSampler
(
test_dataset
,
test_dataset
,
...
@@ -122,7 +123,7 @@ def beam_search(FLAGS):
...
@@ -122,7 +123,7 @@ def beam_search(FLAGS):
model
.
load
(
FLAGS
.
init_model
)
model
.
load
(
FLAGS
.
init_model
)
test_dataset
=
data
.
test
()
test_dataset
=
data
.
test
()
test_collate_fn
=
data
.
BatchCompose
(
test_collate_fn
=
BatchCompose
(
[
data
.
Resize
(),
data
.
Normalize
(),
data
.
PadTarget
()])
[
data
.
Resize
(),
data
.
Normalize
(),
data
.
PadTarget
()])
test_sampler
=
data
.
MyBatchSampler
(
test_sampler
=
data
.
MyBatchSampler
(
test_dataset
,
test_dataset
,
...
...
examples/ocr/predict.py
浏览文件 @
2ad718f7
...
@@ -27,6 +27,7 @@ import paddle.fluid as fluid
...
@@ -27,6 +27,7 @@ import paddle.fluid as fluid
from
hapi.model
import
Input
,
set_device
from
hapi.model
import
Input
,
set_device
from
hapi.datasets.folder
import
ImageFolder
from
hapi.datasets.folder
import
ImageFolder
from
hapi.vision.transforms
import
BatchCompose
from
utility
import
add_arguments
,
print_arguments
from
utility
import
add_arguments
,
print_arguments
from
utility
import
postprocess
,
index2word
from
utility
import
postprocess
,
index2word
...
@@ -67,7 +68,7 @@ def main(FLAGS):
...
@@ -67,7 +68,7 @@ def main(FLAGS):
fn
=
lambda
p
:
Image
.
open
(
p
).
convert
(
'L'
)
fn
=
lambda
p
:
Image
.
open
(
p
).
convert
(
'L'
)
test_dataset
=
ImageFolder
(
FLAGS
.
image_path
,
loader
=
fn
)
test_dataset
=
ImageFolder
(
FLAGS
.
image_path
,
loader
=
fn
)
test_collate_fn
=
data
.
BatchCompose
([
data
.
Resize
(),
data
.
Normalize
()])
test_collate_fn
=
BatchCompose
([
data
.
Resize
(),
data
.
Normalize
()])
test_loader
=
fluid
.
io
.
DataLoader
(
test_loader
=
fluid
.
io
.
DataLoader
(
test_dataset
,
test_dataset
,
places
=
device
,
places
=
device
,
...
...
examples/ocr/train.py
浏览文件 @
2ad718f7
...
@@ -25,6 +25,7 @@ import paddle.fluid.profiler as profiler
...
@@ -25,6 +25,7 @@ import paddle.fluid.profiler as profiler
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
hapi.model
import
Input
,
set_device
from
hapi.model
import
Input
,
set_device
from
hapi.vision.transforms
import
BatchCompose
from
utility
import
add_arguments
,
print_arguments
from
utility
import
add_arguments
,
print_arguments
from
utility
import
SeqAccuracy
,
MyProgBarLogger
from
utility
import
SeqAccuracy
,
MyProgBarLogger
...
@@ -97,7 +98,7 @@ def main(FLAGS):
...
@@ -97,7 +98,7 @@ def main(FLAGS):
labels
=
labels
)
labels
=
labels
)
train_dataset
=
data
.
train
()
train_dataset
=
data
.
train
()
train_collate_fn
=
data
.
BatchCompose
(
train_collate_fn
=
BatchCompose
(
[
data
.
Resize
(),
data
.
Normalize
(),
data
.
PadTarget
()])
[
data
.
Resize
(),
data
.
Normalize
(),
data
.
PadTarget
()])
train_sampler
=
data
.
MyBatchSampler
(
train_sampler
=
data
.
MyBatchSampler
(
train_dataset
,
batch_size
=
FLAGS
.
batch_size
,
shuffle
=
True
)
train_dataset
,
batch_size
=
FLAGS
.
batch_size
,
shuffle
=
True
)
...
@@ -109,7 +110,7 @@ def main(FLAGS):
...
@@ -109,7 +110,7 @@ def main(FLAGS):
return_list
=
True
,
return_list
=
True
,
collate_fn
=
train_collate_fn
)
collate_fn
=
train_collate_fn
)
test_dataset
=
data
.
test
()
test_dataset
=
data
.
test
()
test_collate_fn
=
data
.
BatchCompose
(
test_collate_fn
=
BatchCompose
(
[
data
.
Resize
(),
data
.
Normalize
(),
data
.
PadTarget
()])
[
data
.
Resize
(),
data
.
Normalize
(),
data
.
PadTarget
()])
test_sampler
=
data
.
MyBatchSampler
(
test_sampler
=
data
.
MyBatchSampler
(
test_dataset
,
test_dataset
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录