Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
5aab2d2d
Commit
5aab2d2d
authored
Oct 31, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use statmonitor similar to PVANet
parent
5deebdcb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
24 deletions
+22
-24
tensorpack/callbacks/inference.py
tensorpack/callbacks/inference.py
+1
-1
tensorpack/callbacks/param.py
tensorpack/callbacks/param.py
+21
-23
No files found.
tensorpack/callbacks/inference.py
View file @
5aab2d2d
...
...
@@ -188,7 +188,7 @@ class ClassificationError(Inferencer):
testing (because the size of test set might not be a multiple of batch size).
Therefore the result is different from averaging the error rate of each batch.
"""
def
__init__
(
self
,
wrong_var_name
=
'wrong:0'
,
summary_name
=
'val
idation
_error'
):
def
__init__
(
self
,
wrong_var_name
=
'wrong:0'
,
summary_name
=
'val_error'
):
"""
:param wrong_var_name: name of the `wrong` variable
:param summary_name: the name for logging
...
...
tensorpack/callbacks/param.py
View file @
5aab2d2d
...
...
@@ -199,18 +199,16 @@ class ScheduledHyperParamSetter(HyperParamSetter):
class
StatMonitorParamSetter
(
HyperParamSetter
):
"""
Set hyperparameter by a func,
if
a specific stat wasn't
monotonically decreasing/increasing $a$ times out of the last $b
$ epochs
Set hyperparameter by a func,
when
a specific stat wasn't
decreasing/increasing enough in the last $k
$ epochs
"""
def
__init__
(
self
,
param
,
stat_name
,
value_func
,
last_k
=
5
,
min_non_decreasing
=
2
,
reverse
=
False
def
__init__
(
self
,
param
,
stat_name
,
value_func
,
threshold
,
last_k
,
reverse
=
False
):
"""
Change param by `new_value = value_func(old_value)`,
if `stat_name` wasn't decreasing >
=2 times in the lastest 5 times of
statistics update.
if `stat_name` wasn't decreasing >
threshold times in the lastest
last_k times of
statistics update.
For example, if error wasn't decreasing, anneal the learning rate:
StatMonitorParamSetter('learning_rate', 'val-error', lambda x: x * 0.2)
...
...
@@ -221,13 +219,10 @@ class StatMonitorParamSetter(HyperParamSetter):
self
.
stat_name
=
stat_name
self
.
value_func
=
value_func
self
.
last_k
=
last_k
self
.
min_non_decreasing
=
min_non_decreasing
self
.
last_changed_epoch
=
0
self
.
threshold
=
threshold
self
.
reverse
=
reverse
if
not
reverse
:
self
.
less_than
=
lambda
x
,
y
:
x
<=
y
else
:
self
.
less_than
=
lambda
x
,
y
:
x
>=
y
self
.
last_changed_epoch
=
0
def
_get_value_to_set
(
self
):
holder
=
self
.
trainer
.
stat_holder
...
...
@@ -236,13 +231,16 @@ class StatMonitorParamSetter(HyperParamSetter):
self
.
epoch_num
-
self
.
last_changed_epoch
<
self
.
last_k
:
return
None
hist
=
hist
[
-
self
.
last_k
-
1
:]
# len==last_k+1
cnt
=
0
for
k
in
range
(
self
.
last_k
):
if
self
.
less_than
(
hist
[
k
],
hist
[
k
+
1
]):
cnt
+=
1
if
cnt
>=
self
.
min_non_decreasing
\
and
self
.
less_than
(
hist
[
0
],
hist
[
-
1
]):
hist_first
=
hist
[
0
]
if
not
self
.
reverse
:
hist_min
=
min
(
hist
)
if
hist_min
<=
hist_first
-
self
.
threshold
:
# small enough
return
None
else
:
hist_max
=
max
(
hist
)
if
hist_max
>=
hist_first
+
self
.
threshold
:
# large enough
return
None
self
.
last_changed_epoch
=
self
.
epoch_num
return
self
.
value_func
(
self
.
get_current_value
())
return
None
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