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
7782e724
Commit
7782e724
authored
Apr 10, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add SendMonitorData
parent
eb57892e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
29 deletions
+63
-29
examples/ResNet/imagenet-resnet.py
examples/ResNet/imagenet-resnet.py
+4
-2
tensorpack/callbacks/monitor.py
tensorpack/callbacks/monitor.py
+53
-1
tensorpack/callbacks/stats.py
tensorpack/callbacks/stats.py
+6
-26
No files found.
examples/ResNet/imagenet-resnet.py
View file @
7782e724
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# File: imagenet-resnet.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
import
cv2
import
sys
...
...
@@ -27,6 +26,9 @@ class Model(ModelDesc):
self
.
data_format
=
data_format
def
_get_inputs
(
self
):
# uint8 instead of float32 is used as input type to reduce copy overhead.
# It might hurt the performance a liiiitle bit.
# The pretrained models were trained with float32.
return
[
InputDesc
(
tf
.
uint8
,
[
None
,
INPUT_SHAPE
,
INPUT_SHAPE
,
3
],
'input'
),
InputDesc
(
tf
.
int32
,
[
None
],
'label'
)]
...
...
@@ -197,6 +199,7 @@ def get_config(fake=False, data_format='NCHW'):
dataset_val
=
get_data
(
'val'
,
fake
=
fake
)
return
TrainConfig
(
model
=
Model
(
data_format
=
data_format
),
dataflow
=
dataset_train
,
callbacks
=
[
ModelSaver
(),
...
...
@@ -207,7 +210,6 @@ def get_config(fake=False, data_format='NCHW'):
[(
30
,
1e-2
),
(
60
,
1e-3
),
(
85
,
1e-4
),
(
95
,
1e-5
)]),
HumanHyperParamSetter
(
'learning_rate'
),
],
model
=
Model
(
data_format
=
data_format
),
steps_per_epoch
=
5000
,
max_epoch
=
110
,
)
...
...
tensorpack/callbacks/monitor.py
View file @
7782e724
...
...
@@ -16,7 +16,7 @@ from ..utils import logger
from
.base
import
Callback
__all__
=
[
'TrainingMonitor'
,
'Monitors'
,
'TFSummaryWriter'
,
'JSONWriter'
,
'ScalarPrinter'
]
'TFSummaryWriter'
,
'JSONWriter'
,
'ScalarPrinter'
,
'SendMonitorData'
]
class
TrainingMonitor
(
Callback
):
...
...
@@ -262,3 +262,55 @@ class ScalarHistory(TrainingMonitor):
def
get_history
(
self
,
name
):
return
self
.
_dic
[
name
]
class
SendMonitorData
(
TrainingMonitor
):
"""
Execute a command with some specific scalar monitor data.
This is useful for, e.g. building a custom statistics monitor.
It will try to send once receiving all the stats
"""
def
__init__
(
self
,
command
,
names
):
"""
Args:
command(str): a command to execute. Use format string with stat
names as keys.
names(list or str): data name(s) to use.
Example:
Send the stats to your phone through pushbullet:
.. code-block:: python
SendMonitorData('curl -u your_id: https://api.pushbullet.com/v2/pushes
\\
-d type=note -d title="validation error"
\\
-d body={validation_error} > /dev/null 2>&1',
'validation_error')
"""
self
.
command
=
command
if
not
isinstance
(
names
,
list
):
names
=
[
names
]
self
.
names
=
names
self
.
dic
=
{}
def
put_scalar
(
self
,
name
,
val
):
if
name
in
self
.
names
:
self
.
dic
[
name
]
=
val
def
_trigger_step
(
self
):
self
.
_try_send
()
def
_trigger_epoch
(
self
):
self
.
_try_send
()
def
_try_send
(
self
):
try
:
v
=
{
k
:
self
.
dic
[
k
]
for
k
in
self
.
names
}
except
KeyError
:
return
cmd
=
self
.
command
.
format
(
**
v
)
ret
=
os
.
system
(
cmd
)
if
ret
!=
0
:
logger
.
error
(
"Command {} failed with ret={}!"
.
format
(
cmd
,
ret
))
self
.
dic
=
{}
tensorpack/callbacks/stats.py
View file @
7782e724
...
...
@@ -18,37 +18,17 @@ class StatPrinter(Callback):
"2017-05-26"
)
# TODO make it into monitor?
class
SendStat
(
Callback
):
"""
Execute a command with some specific stats.
This is useful for, e.g. building a custom statistics monitor.
"""
def
__init__
(
self
,
command
,
stats
):
"""
Args:
command(str): a command to execute. Use format string with stat
names as keys.
stats(list or str): stat name(s) to use.
Example:
Send the stats to your phone through pushbullet:
.. code-block:: python
SendStat('curl -u your_id: https://api.pushbullet.com/v2/pushes
\\
-d type=note -d title="validation error"
\\
-d body={validation_error} > /dev/null 2>&1',
'validation_error')
"""
""" An equivalent of :class:`SendMonitorData`, but as a normal callback. """
def
__init__
(
self
,
command
,
names
):
self
.
command
=
command
if
not
isinstance
(
stat
s
,
list
):
stats
=
[
stat
s
]
self
.
stats
=
stat
s
if
not
isinstance
(
name
s
,
list
):
names
=
[
name
s
]
self
.
names
=
name
s
def
_trigger
(
self
):
M
=
self
.
trainer
.
monitors
v
=
{
k
:
M
.
get_latest
(
k
)
for
k
in
self
.
stat
s
}
v
=
{
k
:
M
.
get_latest
(
k
)
for
k
in
self
.
name
s
}
cmd
=
self
.
command
.
format
(
**
v
)
ret
=
os
.
system
(
cmd
)
if
ret
!=
0
:
...
...
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