Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
a7d6b1af
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看板
提交
a7d6b1af
编写于
1月 22, 2018
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix some issues
上级
fbbf6c04
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
16 addition
and
19 deletion
+16
-19
fluid/ocr_ctc/train.py
fluid/ocr_ctc/train.py
+16
-19
未找到文件。
fluid/ocr_ctc/train.py
浏览文件 @
a7d6b1af
...
@@ -11,8 +11,6 @@
...
@@ -11,8 +11,6 @@
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#See the License for the specific language governing permissions and
#limitations under the License.
#limitations under the License.
from
__future__
import
print_function
import
sys
import
sys
import
paddle.v2
as
paddle
import
paddle.v2
as
paddle
...
@@ -42,7 +40,7 @@ def ocr_conv(input, num, with_bn):
...
@@ -42,7 +40,7 @@ def ocr_conv(input, num, with_bn):
num_classes
=
9054
num_classes
=
9054
data_shape
=
[
3
,
32
,
3
2
]
data_shape
=
[
1
,
512
,
51
2
]
images
=
fluid
.
layers
.
data
(
name
=
'pixel'
,
shape
=
data_shape
,
dtype
=
'float32'
)
images
=
fluid
.
layers
.
data
(
name
=
'pixel'
,
shape
=
data_shape
,
dtype
=
'float32'
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
...
@@ -57,11 +55,10 @@ sliced_feature = fluid.layers.im2sequence(
...
@@ -57,11 +55,10 @@ sliced_feature = fluid.layers.im2sequence(
block_x
=
1
,
block_x
=
1
,
block_y
=
3
,
)
block_y
=
3
,
)
gru_forward
=
fluid
.
layers
.
gru
(
input
=
sliced_feature
,
size
=
200
,
act
=
"relu"
)
# TODO(wanghaoshuang): repaced by GRU
gru_backward
=
fluid
.
layers
.
gru
(
input
=
sliced_feature
,
gru_forward
=
fluid
.
layers
.
lstm
(
input
=
sliced_feature
,
size
=
200
,
act
=
"relu"
)
size
=
200
,
gru_backward
=
fluid
.
layers
.
lstm
(
reverse
=
True
,
input
=
sliced_feature
,
size
=
200
,
reverse
=
True
,
act
=
"relu"
)
act
=
"relu"
)
out
=
fluid
.
layers
.
fc
(
input
=
[
gru_forward
,
gru_backward
],
size
=
num_classes
+
1
)
out
=
fluid
.
layers
.
fc
(
input
=
[
gru_forward
,
gru_backward
],
size
=
num_classes
+
1
)
cost
=
fluid
.
layers
.
warpctc
(
cost
=
fluid
.
layers
.
warpctc
(
...
@@ -70,17 +67,20 @@ cost = fluid.layers.warpctc(
...
@@ -70,17 +67,20 @@ cost = fluid.layers.warpctc(
size
=
num_classes
+
1
,
size
=
num_classes
+
1
,
blank
=
num_classes
,
blank
=
num_classes
,
norm_by_times
=
True
)
norm_by_times
=
True
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
# TODO(wanghaoshuang): set clipping
optimizer
=
fluid
.
optimizer
.
Momentum
(
optimizer
=
fluid
.
optimizer
.
Momentum
(
learning_rate
=
((
1.0e-3
)
/
16
),
momentum
=
0.9
)
learning_rate
=
((
1.0e-3
)
/
16
),
momentum
=
0.9
)
opts
=
optimizer
.
minimize
(
cost
)
opts
=
optimizer
.
minimize
(
cost
)
decoded_out
=
fluid
.
layers
.
ctc_greedy_decoder
(
input
=
output
,
blank
=
class_num
)
decoded_out
=
fluid
.
layers
.
ctc_greedy_decoder
(
input
=
output
,
blank
=
class_num
)
error
=
fluid
.
evaluator
.
EditDistance
(
input
=
decoded_out
,
label
=
label
)
error
_evaluator
=
fluid
.
evaluator
.
EditDistance
(
input
=
decoded_out
,
label
=
label
)
BATCH_SIZE
=
16
BATCH_SIZE
=
16
PASS_NUM
=
1
PASS_NUM
=
1
# TODO(wanghaoshuang): replaced by correct data reader
train_reader
=
paddle
.
batch
(
train_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
cifar
.
train10
(),
buf_size
=
128
*
10
),
paddle
.
dataset
.
cifar
.
train10
(),
buf_size
=
128
*
10
),
...
@@ -92,14 +92,11 @@ feeder = fluid.DataFeeder(place=place, feed_list=[images, label])
...
@@ -92,14 +92,11 @@ feeder = fluid.DataFeeder(place=place, feed_list=[images, label])
exe
.
run
(
fluid
.
default_startup_program
())
exe
.
run
(
fluid
.
default_startup_program
())
for
pass_id
in
range
(
PASS_NUM
):
for
pass_id
in
range
(
PASS_NUM
):
accuracy
.
reset
(
exe
)
error_evaluator
.
reset
(
exe
)
for
data
in
train_reader
():
for
data
in
train_reader
():
loss
,
acc
=
exe
.
run
(
fluid
.
default_main_program
(),
loss
,
error
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
feeder
.
feed
(
data
),
feed
=
feeder
.
feed
(
data
),
fetch_list
=
[
avg_cost
]
+
accuracy
.
metrics
)
fetch_list
=
[
avg_cost
]
+
error
.
metrics
)
pass_acc
=
accuracy
.
eval
(
exe
)
pass_error
=
error_evaluator
.
eval
(
exe
)
print
(
"loss:"
+
str
(
loss
)
+
" acc:"
+
str
(
acc
)
+
" pass_acc:"
+
str
(
print
"loss: %s; distance error: %s; pass_dis_error: %s;"
%
(
pass_acc
))
str
(
loss
),
str
(
error
),
str
(
pass_error
))
# this model is slow, so if we can train two mini batch, we think it works properly.
exit
(
0
)
exit
(
1
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录