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
8fe3b141
Commit
8fe3b141
authored
Aug 18, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add whitelist/blacklist to ScalarPrinter
parent
94a0df07
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
6 deletions
+29
-6
tensorpack/callbacks/monitor.py
tensorpack/callbacks/monitor.py
+29
-6
No files found.
tensorpack/callbacks/monitor.py
View file @
8fe3b141
...
...
@@ -19,7 +19,8 @@ from ..tfutils.summary import create_scalar_summary, create_image_summary
from
.base
import
Callback
__all__
=
[
'TrainingMonitor'
,
'Monitors'
,
'TFSummaryWriter'
,
'TFEventWriter'
,
'JSONWriter'
,
'ScalarPrinter'
,
'SendMonitorData'
]
'TFSummaryWriter'
,
'TFEventWriter'
,
'JSONWriter'
,
'ScalarPrinter'
,
'SendMonitorData'
]
def
image_to_nhwc
(
arr
):
...
...
@@ -271,14 +272,29 @@ class ScalarPrinter(TrainingMonitor):
"""
Print scalar data into terminal.
"""
def
__init__
(
self
,
enable_step
=
False
,
enable_epoch
=
True
):
def
__init__
(
self
,
enable_step
=
False
,
enable_epoch
=
True
,
whitelist
=
None
,
blacklist
=
None
):
"""
Args:
enable_step, enable_epoch (bool): whether to print the
monitor data (if any) between steps or between epochs.
whitelist (list[str] or None): A list of regex. Only names
matching some regex will be allowed for printing.
Defaults to match all names.
blacklist (list[str] or None): A list of regex. Names matching
any regex will not be printed. Defaults to match no names.
"""
self
.
_whitelist
=
None
self
.
_blacklist
=
set
([])
def
compile_regex
(
rs
):
if
rs
is
None
:
return
None
rs
=
set
([
r
if
isinstance
(
r
,
re
.
RegexObject
)
else
re
.
compile
(
r
)
for
r
in
rs
])
return
rs
self
.
_whitelist
=
compile_regex
(
whitelist
)
if
blacklist
is
None
:
blacklist
=
[]
self
.
_blacklist
=
compile_regex
(
blacklist
)
self
.
_enable_step
=
enable_step
self
.
_enable_epoch
=
enable_epoch
...
...
@@ -305,9 +321,16 @@ class ScalarPrinter(TrainingMonitor):
self
.
_dic
[
name
]
=
float
(
val
)
def
_print_stat
(
self
):
def
match_regex_list
(
regexs
,
name
):
for
r
in
regexs
:
if
r
.
search
(
name
)
is
not
None
:
return
True
return
False
for
k
,
v
in
sorted
(
self
.
_dic
.
items
(),
key
=
operator
.
itemgetter
(
0
)):
if
self
.
_whitelist
is
None
or
k
in
self
.
_whitelist
:
if
k
not
in
self
.
_blacklist
:
if
self
.
_whitelist
is
None
or
\
match_regex_list
(
self
.
_whitelist
,
k
):
if
not
match_regex_list
(
self
.
_blacklist
,
k
):
logger
.
info
(
'{}: {:.5g}'
.
format
(
k
,
v
))
self
.
_dic
=
{}
...
...
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