Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
paddle_dbnet
Commits
5e5ea853
Commit
5e5ea853
authored
Aug 04, 2020
by
littletomatodonkey
Browse files
add piecewise decay
parent
f7b5edcc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
5 deletions
+16
-5
ppocr/data/rec/img_tools.py
ppocr/data/rec/img_tools.py
+1
-1
ppocr/optimizer.py
ppocr/optimizer.py
+15
-4
No files found.
ppocr/data/rec/img_tools.py
View file @
5e5ea853
...
@@ -360,7 +360,7 @@ def process_image(img,
...
@@ -360,7 +360,7 @@ def process_image(img,
text
=
char_ops
.
encode
(
label
)
text
=
char_ops
.
encode
(
label
)
if
len
(
text
)
==
0
or
len
(
text
)
>
max_text_length
:
if
len
(
text
)
==
0
or
len
(
text
)
>
max_text_length
:
logger
.
info
(
logger
.
info
(
"Warning in ppocr/data/rec/img_tools.py:
line362:
Wrong data type."
"Warning in ppocr/data/rec/img_tools.py: Wrong data type."
"Excepted string with length between 1 and {}, but "
"Excepted string with length between 1 and {}, but "
"got '{}'. Label is '{}'"
.
format
(
max_text_length
,
"got '{}'. Label is '{}'"
.
format
(
max_text_length
,
len
(
text
),
label
))
len
(
text
),
label
))
...
...
ppocr/optimizer.py
View file @
5e5ea853
...
@@ -36,17 +36,28 @@ def AdamDecay(params, parameter_list=None):
...
@@ -36,17 +36,28 @@ def AdamDecay(params, parameter_list=None):
l2_decay
=
params
.
get
(
"l2_decay"
,
0.0
)
l2_decay
=
params
.
get
(
"l2_decay"
,
0.0
)
if
'decay'
in
params
:
if
'decay'
in
params
:
supported_decay_mode
=
[
"cosine_decay"
,
"piecewise_decay"
]
params
=
params
[
'decay'
]
params
=
params
[
'decay'
]
decay_mode
=
params
[
'function'
]
decay_mode
=
params
[
'function'
]
step_each_epoch
=
params
[
'step_each_epoch'
]
assert
decay_mode
in
supported_decay_mode
,
"Supported decay mode is {}, but got {}"
.
format
(
total_epoch
=
params
[
'total_epoch'
]
supported_decay_mode
,
decay_mode
)
if
decay_mode
==
"cosine_decay"
:
if
decay_mode
==
"cosine_decay"
:
step_each_epoch
=
params
[
'step_each_epoch'
]
total_epoch
=
params
[
'total_epoch'
]
base_lr
=
fluid
.
layers
.
cosine_decay
(
base_lr
=
fluid
.
layers
.
cosine_decay
(
learning_rate
=
base_lr
,
learning_rate
=
base_lr
,
step_each_epoch
=
step_each_epoch
,
step_each_epoch
=
step_each_epoch
,
epochs
=
total_epoch
)
epochs
=
total_epoch
)
else
:
elif
decay_mode
==
"piecewise_decay"
:
logger
.
info
(
"Only support Cosine decay currently"
)
boundaries
=
params
[
"boundaries"
]
decay_rate
=
params
[
"decay_rate"
]
values
=
[
base_lr
*
decay_rate
**
idx
for
idx
in
range
(
len
(
boundaries
)
+
1
)
]
base_lr
=
fluid
.
layers
.
piecewise_decay
(
boundaries
,
values
)
optimizer
=
fluid
.
optimizer
.
Adam
(
optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
base_lr
,
learning_rate
=
base_lr
,
beta1
=
beta1
,
beta1
=
beta1
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment