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
bc9d2e1a
Commit
bc9d2e1a
authored
Mar 01, 2018
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
misc small changes
parent
4142b9e7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
36 additions
and
28 deletions
+36
-28
docs/tutorial/performance-tuning.md
docs/tutorial/performance-tuning.md
+3
-4
examples/ResNet/README.md
examples/ResNet/README.md
+1
-1
examples/ResNet/imagenet_utils.py
examples/ResNet/imagenet_utils.py
+1
-1
examples/SuperResolution/enet-pat.py
examples/SuperResolution/enet-pat.py
+1
-1
tensorpack/callbacks/param.py
tensorpack/callbacks/param.py
+7
-1
tensorpack/tfutils/collection.py
tensorpack/tfutils/collection.py
+19
-7
tensorpack/tfutils/tower.py
tensorpack/tfutils/tower.py
+4
-3
tensorpack/utils/naming.py
tensorpack/utils/naming.py
+0
-10
No files found.
docs/tutorial/performance-tuning.md
View file @
bc9d2e1a
...
@@ -38,14 +38,13 @@ Benchmark your DataFlow with modifications to understand which part is the bottl
...
@@ -38,14 +38,13 @@ Benchmark your DataFlow with modifications to understand which part is the bottl
2.
Gradually add some pre-processing and see how the performance changes.
2.
Gradually add some pre-processing and see how the performance changes.
3.
Change the number of parallel processes or threads.
3.
Change the number of parallel processes or threads.
A DataFlow could be blocked by CPU/
hard
disk/network/IPC bandwidth. Only by benchmarking will you
A DataFlow could be blocked by CPU/disk/network/IPC bandwidth. Only by benchmarking will you
know the reason and improve it accordingly, e.g.:
know the reason and improve it accordingly, e.g.:
1.
Use single-file database to avoid random read on hard disk.
1.
Use single-file database to avoid random read on hard disk.
2.
Write faster pre-processing
with whatever tools you have.
2.
Use fewer pre-processings or write faster ones
with whatever tools you have.
3.
Move certain pre-processing (e.g. mean/std normalization) to the graph, if TF has fast implementation of it.
3.
Move certain pre-processing (e.g. mean/std normalization) to the graph, if TF has fast implementation of it.
4.
Compress your data (e.g. use uint8 images, or JPEG-compressed images) before sending them through
4.
Compress your data (e.g. use uint8 images, or JPEG-compressed images) before sending them through anything (network, ZMQ pipe, Python-TF copy etc.)
anything (network, ZMQ pipe, Python-TF copy etc.)
5.
Use distributed data preprocessing, with
`send_dataflow_zmq`
and
`RemoteDataZMQ`
.
5.
Use distributed data preprocessing, with
`send_dataflow_zmq`
and
`RemoteDataZMQ`
.
## Investigate TensorFlow
## Investigate TensorFlow
...
...
examples/ResNet/README.md
View file @
bc9d2e1a
...
@@ -28,7 +28,7 @@ To train, first decompress ImageNet data into [this structure](http://tensorpack
...
@@ -28,7 +28,7 @@ To train, first decompress ImageNet data into [this structure](http://tensorpack
You should be able to see good GPU utilization (95%~99%), if your data is fast enough.
You should be able to see good GPU utilization (95%~99%), if your data is fast enough.
It can finish training
[
within 20 hours
](
http://dawn.cs.stanford.edu/benchmark/ImageNet/train.html
)
on AWS p3.16xlarge.
It can finish training
[
within 20 hours
](
http://dawn.cs.stanford.edu/benchmark/ImageNet/train.html
)
on AWS p3.16xlarge.
The default data pipeline is probably OK for m
ost SSD system
s.
The default data pipeline is probably OK for m
achines with SSD + E5 CPU
s.
See the
[
tutorial
](
http://tensorpack.readthedocs.io/en/latest/tutorial/efficient-dataflow.html
)
on other options to speed up your data.
See the
[
tutorial
](
http://tensorpack.readthedocs.io/en/latest/tutorial/efficient-dataflow.html
)
on other options to speed up your data.


...
...
examples/ResNet/imagenet_utils.py
View file @
bc9d2e1a
...
@@ -58,7 +58,7 @@ def fbresnet_augmentor(isTrain):
...
@@ -58,7 +58,7 @@ def fbresnet_augmentor(isTrain):
if
isTrain
:
if
isTrain
:
augmentors
=
[
augmentors
=
[
GoogleNetResize
(),
GoogleNetResize
(),
imgaug
.
RandomOrderAug
(
imgaug
.
RandomOrderAug
(
# Remove these augs if your CPU is not fast enough
[
imgaug
.
BrightnessScale
((
0.6
,
1.4
),
clip
=
False
),
[
imgaug
.
BrightnessScale
((
0.6
,
1.4
),
clip
=
False
),
imgaug
.
Contrast
((
0.6
,
1.4
),
clip
=
False
),
imgaug
.
Contrast
((
0.6
,
1.4
),
clip
=
False
),
imgaug
.
Saturation
(
0.4
,
rgb
=
False
),
imgaug
.
Saturation
(
0.4
,
rgb
=
False
),
...
...
examples/SuperResolution/enet-pat.py
View file @
bc9d2e1a
...
@@ -30,7 +30,7 @@ GAN_FACTOR_PARAMETER = 2.
...
@@ -30,7 +30,7 @@ GAN_FACTOR_PARAMETER = 2.
def
normalize
(
v
):
def
normalize
(
v
):
assert
isinstance
(
v
,
tf
.
Tensor
)
assert
isinstance
(
v
,
tf
.
Tensor
)
v
.
get_shape
()
.
assert_has_rank
(
4
)
v
.
get_shape
()
.
assert_has_rank
(
4
)
return
v
/
tf
.
reduce_mean
(
v
,
axis
=
[
1
,
2
,
3
],
keep
_
dims
=
True
)
return
v
/
tf
.
reduce_mean
(
v
,
axis
=
[
1
,
2
,
3
],
keepdims
=
True
)
def
gram_matrix
(
v
):
def
gram_matrix
(
v
):
...
...
tensorpack/callbacks/param.py
View file @
bc9d2e1a
...
@@ -336,7 +336,13 @@ class StatMonitorParamSetter(HyperParamSetter):
...
@@ -336,7 +336,13 @@ class StatMonitorParamSetter(HyperParamSetter):
self
.
last_changed_epoch
=
0
self
.
last_changed_epoch
=
0
def
_get_value_to_set
(
self
):
def
_get_value_to_set
(
self
):
hist
=
self
.
trainer
.
monitors
.
get_history
(
self
.
stat_name
)
try
:
hist
=
self
.
trainer
.
monitors
.
get_history
(
self
.
stat_name
)
except
KeyError
:
logger
.
warn
(
"[StatMonitorParamSetter] Key {} not found in monitor history! Ignore it."
.
format
(
self
.
stat_name
))
return
None
if
len
(
hist
)
<
self
.
last_k
+
1
or
\
if
len
(
hist
)
<
self
.
last_k
+
1
or
\
self
.
epoch_num
-
self
.
last_changed_epoch
<
self
.
last_k
:
self
.
epoch_num
-
self
.
last_changed_epoch
<
self
.
last_k
:
return
None
return
None
...
...
tensorpack/tfutils/collection.py
View file @
bc9d2e1a
...
@@ -81,24 +81,36 @@ class CollectionGuard(object):
...
@@ -81,24 +81,36 @@ class CollectionGuard(object):
def
__init__
(
self
,
name
,
check_diff
,
def
__init__
(
self
,
name
,
check_diff
,
freeze_keys
=
[],
freeze_keys
=
[],
diff_whitelist
=
[
diff_whitelist
=
None
):
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
,
tf
.
GraphKeys
.
GLOBAL_VARIABLES
,
tf
.
GraphKeys
.
QUEUE_RUNNERS
,
tf
.
GraphKeys
.
LOCAL_VARIABLES
]):
"""
"""
Args:
Args:
name (str): name of the tower
name (str): name of the tower
check_diff (bool): whether to test and print about collection change
check_diff (bool): whether to check and print about collection change
when leaving this guard.
freeze_keys (list): list of keys to freeze
freeze_keys (list): list of keys to freeze
diff_whitelist (list): list of keys to not print, when check_diff is True
diff_whitelist (list): list of keys to ignore, when check_diff is True.
Defaults to some collections that are normally changed,
including variables, losses, contexts, queue runners.
"""
"""
self
.
_name
=
name
self
.
_name
=
name
self
.
_check_diff
=
check_diff
self
.
_check_diff
=
check_diff
if
diff_whitelist
is
None
:
diff_whitelist
=
CollectionGuard
.
_default_diff_whitelist
()
self
.
_whitelist
=
set
(
diff_whitelist
)
self
.
_whitelist
=
set
(
diff_whitelist
)
self
.
_freeze_keys
=
freeze_keys
self
.
_freeze_keys
=
freeze_keys
self
.
_inverse_graphkeys
=
get_inverse_graphkeys
()
self
.
_inverse_graphkeys
=
get_inverse_graphkeys
()
@
staticmethod
def
_default_diff_whitelist
():
ret
=
[
tf
.
GraphKeys
.
TRAINABLE_VARIABLES
,
tf
.
GraphKeys
.
GLOBAL_VARIABLES
,
tf
.
GraphKeys
.
QUEUE_RUNNERS
,
tf
.
GraphKeys
.
LOCAL_VARIABLES
]
for
newkey
in
[
'COND_CONTEXT'
,
'WHILE_CONTEXT'
,
'LOSSES'
]:
if
hasattr
(
tf
.
GraphKeys
,
newkey
):
ret
.
append
(
getattr
(
tf
.
GraphKeys
,
newkey
))
return
ret
def
_key_name
(
self
,
name
):
def
_key_name
(
self
,
name
):
return
self
.
_inverse_graphkeys
.
get
(
name
,
name
)
return
self
.
_inverse_graphkeys
.
get
(
name
,
name
)
...
...
tensorpack/tfutils/tower.py
View file @
bc9d2e1a
...
@@ -8,7 +8,7 @@ from six.moves import zip
...
@@ -8,7 +8,7 @@ from six.moves import zip
from
..utils
import
logger
from
..utils
import
logger
from
..utils.argtools
import
call_only_once
from
..utils.argtools
import
call_only_once
from
..utils.naming
import
TRAIN_TOWER_FREEZE_KEYS
,
PREDICT_TOWER_FREEZE_KEYS
from
..utils.naming
import
MOVING_SUMMARY_OPS_KEY
from
..utils.develop
import
HIDE_DOC
from
..utils.develop
import
HIDE_DOC
from
.collection
import
CollectionGuard
from
.collection
import
CollectionGuard
from
.common
import
get_tf_version_number
,
get_op_or_tensor_by_name
,
get_op_tensor_name
from
.common
import
get_tf_version_number
,
get_op_or_tensor_by_name
,
get_op_tensor_name
...
@@ -122,8 +122,9 @@ class TowerContext(object):
...
@@ -122,8 +122,9 @@ class TowerContext(object):
if
self
.
is_main_training_tower
:
if
self
.
is_main_training_tower
:
return
[]
return
[]
if
self
.
is_training
:
if
self
.
is_training
:
return
TRAIN_TOWER_FREEZE_KEYS
return
[
tf
.
GraphKeys
.
SUMMARIES
,
MOVING_SUMMARY_OPS_KEY
]
return
PREDICT_TOWER_FREEZE_KEYS
# freeze UPDATE_OPS during inference because they should never be used
return
[
tf
.
GraphKeys
.
SUMMARIES
,
MOVING_SUMMARY_OPS_KEY
,
tf
.
GraphKeys
.
UPDATE_OPS
]
def
__enter__
(
self
):
def
__enter__
(
self
):
global
_CurrentTowerContext
global
_CurrentTowerContext
...
...
tensorpack/utils/naming.py
View file @
bc9d2e1a
...
@@ -2,17 +2,7 @@
...
@@ -2,17 +2,7 @@
# File: naming.py
# File: naming.py
import
tensorflow
as
tf
GLOBAL_STEP_INCR_OP_NAME
=
'global_step_incr'
GLOBAL_STEP_INCR_OP_NAME
=
'global_step_incr'
GLOBAL_STEP_INCR_VAR_NAME
=
'global_step_incr:0'
# extra variables to summarize during training in a moving-average way
# extra variables to summarize during training in a moving-average way
MOVING_SUMMARY_OPS_KEY
=
'MOVING_SUMMARY_OPS'
MOVING_SUMMARY_OPS_KEY
=
'MOVING_SUMMARY_OPS'
SUMMARY_BACKUP_KEYS
=
[
tf
.
GraphKeys
.
SUMMARIES
,
MOVING_SUMMARY_OPS_KEY
]
TRAIN_TOWER_FREEZE_KEYS
=
SUMMARY_BACKUP_KEYS
PREDICT_TOWER_FREEZE_KEYS
=
SUMMARY_BACKUP_KEYS
+
[
tf
.
GraphKeys
.
UPDATE_OPS
]
# also freeze UPDATE_OPS in inference, because they should never be used
# TODO a better way to log and warn about collection change during build_graph.
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