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
88b99f38
You need to sign in or sign up before continuing.
Commit
88b99f38
authored
Oct 30, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
public register_callback
parent
b4085f77
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
9 deletions
+11
-9
examples/GAN/GAN.py
examples/GAN/GAN.py
+3
-3
tensorpack/train/base.py
tensorpack/train/base.py
+7
-5
tensorpack/train/tower.py
tensorpack/train/tower.py
+1
-1
No files found.
examples/GAN/GAN.py
View file @
88b99f38
...
@@ -86,7 +86,7 @@ class GANTrainer(TowerTrainer):
...
@@ -86,7 +86,7 @@ class GANTrainer(TowerTrainer):
self
.
set_tower_func
(
tower_func
)
self
.
set_tower_func
(
tower_func
)
for
cb
in
cbs
:
for
cb
in
cbs
:
self
.
_
register_callback
(
cb
)
self
.
register_callback
(
cb
)
class
SeparateGANTrainer
(
TowerTrainer
):
class
SeparateGANTrainer
(
TowerTrainer
):
...
@@ -116,7 +116,7 @@ class SeparateGANTrainer(TowerTrainer):
...
@@ -116,7 +116,7 @@ class SeparateGANTrainer(TowerTrainer):
self
.
set_tower_func
(
tower_func
)
self
.
set_tower_func
(
tower_func
)
for
cb
in
cbs
:
for
cb
in
cbs
:
self
.
_
register_callback
(
cb
)
self
.
register_callback
(
cb
)
def
run_step
(
self
):
def
run_step
(
self
):
if
self
.
global_step
%
(
self
.
_d_period
)
==
0
:
if
self
.
global_step
%
(
self
.
_d_period
)
==
0
:
...
@@ -162,7 +162,7 @@ class MultiGPUGANTrainer(TowerTrainer):
...
@@ -162,7 +162,7 @@ class MultiGPUGANTrainer(TowerTrainer):
self
.
train_op
=
d_min
self
.
train_op
=
d_min
self
.
set_tower_func
(
tower_func
)
self
.
set_tower_func
(
tower_func
)
for
cb
in
cbs
:
for
cb
in
cbs
:
self
.
_
register_callback
(
cb
)
self
.
register_callback
(
cb
)
class
RandomZData
(
DataFlow
):
class
RandomZData
(
DataFlow
):
...
...
tensorpack/train/base.py
View file @
88b99f38
...
@@ -107,7 +107,7 @@ class Trainer(object):
...
@@ -107,7 +107,7 @@ class Trainer(object):
def
_register_callback
(
self
,
cb
):
def
_register_callback
(
self
,
cb
):
"""
"""
Register a callback to the trainer.
Register a callback to the trainer.
It can only be called before :meth:`Trainer.train
` gets called
.
It can only be called before :meth:`Trainer.train
()`
.
"""
"""
assert
isinstance
(
cb
,
Callback
),
cb
assert
isinstance
(
cb
,
Callback
),
cb
assert
not
isinstance
(
self
.
_callbacks
,
Callbacks
),
\
assert
not
isinstance
(
self
.
_callbacks
,
Callbacks
),
\
...
@@ -117,6 +117,8 @@ class Trainer(object):
...
@@ -117,6 +117,8 @@ class Trainer(object):
else
:
else
:
self
.
_callbacks
.
append
(
cb
)
self
.
_callbacks
.
append
(
cb
)
register_callback
=
_register_callback
def
run_step
(
self
):
def
run_step
(
self
):
"""
"""
Defines what to do in one iteration. The default is:
Defines what to do in one iteration. The default is:
...
@@ -138,15 +140,15 @@ class Trainer(object):
...
@@ -138,15 +140,15 @@ class Trainer(object):
"""
"""
describe_trainable_vars
()
# TODO weird
describe_trainable_vars
()
# TODO weird
self
.
_
register_callback
(
MaintainStepCounter
())
self
.
register_callback
(
MaintainStepCounter
())
for
cb
in
callbacks
:
for
cb
in
callbacks
:
self
.
_
register_callback
(
cb
)
self
.
register_callback
(
cb
)
for
cb
in
self
.
_callbacks
:
for
cb
in
self
.
_callbacks
:
assert
not
isinstance
(
cb
,
TrainingMonitor
),
"Monitor cannot be pre-registered for now!"
assert
not
isinstance
(
cb
,
TrainingMonitor
),
"Monitor cannot be pre-registered for now!"
for
m
in
monitors
:
for
m
in
monitors
:
self
.
_
register_callback
(
m
)
self
.
register_callback
(
m
)
self
.
monitors
=
Monitors
(
monitors
)
self
.
monitors
=
Monitors
(
monitors
)
self
.
_
register_callback
(
self
.
monitors
)
# monitors is also a callback
self
.
register_callback
(
self
.
monitors
)
# monitors is also a callback
# some final operations that might modify the graph
# some final operations that might modify the graph
logger
.
info
(
"Setup callbacks graph ..."
)
logger
.
info
(
"Setup callbacks graph ..."
)
...
...
tensorpack/train/tower.py
View file @
88b99f38
...
@@ -128,7 +128,7 @@ class SingleCostTrainer(TowerTrainer):
...
@@ -128,7 +128,7 @@ class SingleCostTrainer(TowerTrainer):
train_callbacks
=
self
.
_setup_graph
(
input
,
get_cost_fn
,
get_opt_fn
)
train_callbacks
=
self
.
_setup_graph
(
input
,
get_cost_fn
,
get_opt_fn
)
internal_callbacks
=
input_callbacks
+
train_callbacks
internal_callbacks
=
input_callbacks
+
train_callbacks
for
cb
in
internal_callbacks
:
for
cb
in
internal_callbacks
:
self
.
_
register_callback
(
cb
)
self
.
register_callback
(
cb
)
@
abstractmethod
@
abstractmethod
def
_setup_graph
(
self
,
input
,
get_cost_fn
,
get_opt_fn
):
def
_setup_graph
(
self
,
input
,
get_cost_fn
,
get_opt_fn
):
...
...
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