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
f9356946
Commit
f9356946
authored
Jun 26, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command line tools to profile a graph
parent
54e391c0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
18 deletions
+90
-18
scripts/checkpoint-manipulate.py
scripts/checkpoint-manipulate.py
+22
-16
scripts/checkpoint-prof.py
scripts/checkpoint-prof.py
+66
-0
scripts/dump-model-params.py
scripts/dump-model-params.py
+2
-2
No files found.
scripts/checkpoint-manipulate.py
View file @
f9356946
...
...
@@ -9,20 +9,26 @@ from tensorpack.tfutils.varmanip import dump_chkpt_vars
from
tensorpack.utils
import
logger
import
argparse
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'checkpoint'
)
parser
.
add_argument
(
'--dump'
,
help
=
'dump to an npy file'
)
parser
.
add_argument
(
'--shell'
,
action
=
'store_true'
,
help
=
'start a shell with the params'
)
args
=
parser
.
parse_args
()
if
args
.
checkpoint
.
endswith
(
'.npy'
):
params
=
np
.
load
(
args
.
checkpoint
)
.
item
()
else
:
params
=
dump_chkpt_vars
(
args
.
checkpoint
)
logger
.
info
(
"Variables in the checkpoint:"
)
logger
.
info
(
str
(
params
.
keys
()))
if
args
.
dump
:
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'model'
)
parser
.
add_argument
(
'--dump'
,
help
=
'dump to an npy file'
)
parser
.
add_argument
(
'--shell'
,
action
=
'store_true'
,
help
=
'start a shell with the params'
)
args
=
parser
.
parse_args
()
if
args
.
model
.
endswith
(
'.npy'
):
params
=
np
.
load
(
args
.
model
)
.
item
()
else
:
params
=
dump_chkpt_vars
(
args
.
model
)
logger
.
info
(
"Variables in the model:"
)
logger
.
info
(
str
(
params
.
keys
()))
if
args
.
dump
:
assert
args
.
dump
.
endswith
(
'.npy'
),
args
.
dump
np
.
save
(
args
.
dump
,
params
)
if
args
.
shell
:
if
args
.
shell
:
# params is a dict. play with it
import
IPython
as
IP
IP
.
embed
(
config
=
IP
.
terminal
.
ipapp
.
load_default_config
())
scripts/checkpoint-prof.py
0 → 100755
View file @
f9356946
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: checkpoint-prof.py
import
tensorflow
as
tf
import
numpy
as
np
from
tensorpack
import
get_default_sess_config
,
get_op_tensor_name
from
tensorpack.utils
import
logger
from
tensorpack.tfutils.sessinit
import
get_model_loader
import
argparse
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--model'
,
help
=
'model file'
)
parser
.
add_argument
(
'--meta'
,
help
=
'metagraph proto file. Will be used to load the graph'
,
required
=
True
)
parser
.
add_argument
(
'-i'
,
'--input'
,
nargs
=
'+'
,
help
=
'list of input tensors with their shapes.'
)
parser
.
add_argument
(
'-o'
,
'--output'
,
nargs
=
'+'
,
help
=
'list of output tensors'
)
parser
.
add_argument
(
'--warmup'
,
help
=
'warmup iterations'
,
type
=
int
,
default
=
5
)
parser
.
add_argument
(
'--print-flops'
,
action
=
'store_true'
)
parser
.
add_argument
(
'--print-params'
,
action
=
'store_true'
)
parser
.
add_argument
(
'--print-timing'
,
action
=
'store_true'
)
args
=
parser
.
parse_args
()
tf
.
train
.
import_meta_graph
(
args
.
meta
)
G
=
tf
.
get_default_graph
()
with
tf
.
Session
(
config
=
get_default_sess_config
())
as
sess
:
init
=
get_model_loader
(
args
.
model
)
init
.
init
(
sess
)
feed
=
{}
for
inp
in
args
.
input
:
inp
=
inp
.
split
(
'='
)
name
=
get_op_tensor_name
(
inp
[
0
]
.
strip
())[
1
]
shape
=
map
(
int
,
inp
[
1
]
.
strip
()
.
split
(
','
))
tensor
=
G
.
get_tensor_by_name
(
name
)
logger
.
info
(
"Feeding shape ({}) to tensor {}"
.
format
(
','
.
join
(
map
(
str
,
shape
)),
name
))
feed
[
tensor
]
=
np
.
random
.
rand
(
*
shape
)
fetches
=
[]
for
name
in
args
.
output
:
name
=
get_op_tensor_name
(
name
)[
1
]
fetches
.
append
(
G
.
get_tensor_by_name
(
name
))
logger
.
info
(
"Fetching tensors: {}"
.
format
(
', '
.
join
([
k
.
name
for
k
in
fetches
])))
for
_
in
range
(
args
.
warmup
):
sess
.
run
(
fetches
,
feed_dict
=
feed
)
opt
=
tf
.
RunOptions
()
opt
.
trace_level
=
tf
.
RunOptions
.
FULL_TRACE
meta
=
tf
.
RunMetadata
()
sess
.
run
(
fetches
,
feed_dict
=
feed
,
options
=
opt
,
run_metadata
=
meta
)
if
args
.
print_flops
:
tf
.
contrib
.
tfprof
.
model_analyzer
.
print_model_analysis
(
G
,
run_meta
=
meta
,
tfprof_options
=
tf
.
contrib
.
tfprof
.
model_analyzer
.
FLOAT_OPS_OPTIONS
)
if
args
.
print_params
:
tf
.
contrib
.
tfprof
.
model_analyzer
.
print_model_analysis
(
G
,
run_meta
=
meta
,
tfprof_options
=
tf
.
contrib
.
tfprof
.
model_analyzer
.
TRAINABLE_VARS_PARAMS_STAT_OPTIONS
)
if
args
.
print_timing
:
tf
.
contrib
.
tfprof
.
model_analyzer
.
print_model_analysis
(
G
,
run_meta
=
meta
,
tfprof_options
=
tf
.
contrib
.
tfprof
.
model_analyzer
.
PRINT_ALL_TIMING_MEMORY
)
scripts/dump-model-params.py
View file @
f9356946
...
...
@@ -8,7 +8,7 @@ import argparse
import
tensorflow
as
tf
import
imp
from
tensorpack
import
TowerContext
,
logger
,
ModelFromMetaGraph
from
tensorpack
import
TowerContext
,
logger
from
tensorpack.tfutils
import
sessinit
,
varmanip
parser
=
argparse
.
ArgumentParser
()
...
...
@@ -28,7 +28,7 @@ with tf.Graph().as_default() as G:
with
TowerContext
(
''
,
is_training
=
False
):
M
.
build_graph
(
M
.
get_reused_placehdrs
())
else
:
M
=
ModelFromMetaG
raph
(
args
.
meta
)
tf
.
train
.
import_meta_g
raph
(
args
.
meta
)
# loading...
if
args
.
model
.
endswith
(
'.npy'
):
...
...
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