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
4c2bcb94
Commit
4c2bcb94
authored
Jul 17, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean-up legacy placeholder methods in ModelDesc
parent
f603636c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
34 deletions
+16
-34
scripts/dump-model-params.py
scripts/dump-model-params.py
+4
-1
tensorpack/graph_builder/model_desc.py
tensorpack/graph_builder/model_desc.py
+0
-26
tensorpack/graph_builder/predictor_factory.py
tensorpack/graph_builder/predictor_factory.py
+4
-3
tensorpack/predict/base.py
tensorpack/predict/base.py
+4
-2
tensorpack/tfutils/export.py
tensorpack/tfutils/export.py
+4
-2
No files found.
scripts/dump-model-params.py
View file @
4c2bcb94
...
...
@@ -10,6 +10,7 @@ import imp
from
tensorpack
import
TowerContext
,
logger
from
tensorpack.tfutils
import
sessinit
,
varmanip
from
tensorpack.graph_builder.input_source
import
PlaceholderInput
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--config'
,
help
=
'config file'
)
...
...
@@ -26,7 +27,9 @@ with tf.Graph().as_default() as G:
MODEL
=
imp
.
load_source
(
'config_script'
,
args
.
config
)
.
Model
M
=
MODEL
()
with
TowerContext
(
''
,
is_training
=
False
):
M
.
build_graph
(
M
.
get_reused_placehdrs
())
input
=
PlaceholderInput
()
input
.
setup
(
M
.
get_inputs_desc
())
M
.
build_graph
(
input
)
else
:
tf
.
train
.
import_meta_graph
(
args
.
meta
)
...
...
tensorpack/graph_builder/model_desc.py
View file @
4c2bcb94
...
...
@@ -93,32 +93,6 @@ class InputDesc(
class
ModelDescBase
(
object
):
""" Base class for a model description.
"""
# TODO remove this method? Now mainly used in predict/
@
memoized
def
get_reused_placehdrs
(
self
):
"""
Create or return (if already created) raw input TF placeholders in the graph.
Returns:
list[tf.Tensor]: the list of input placeholders in the graph.
"""
return
[
v
.
build_placeholder_reuse
()
for
v
in
self
.
get_inputs_desc
()]
def
build_placeholders
(
self
,
prefix
=
''
):
"""
For each InputDesc, create new placeholders with optional prefix and
return them. Useful when building new towers.
Returns:
list[tf.Tensor]: the list of built placeholders.
"""
inputs
=
self
.
get_inputs_desc
()
ret
=
[]
for
v
in
inputs
:
ret
.
append
(
v
.
build_placeholder
(
prefix
))
return
ret
@
memoized
def
get_inputs_desc
(
self
):
"""
...
...
tensorpack/graph_builder/predictor_factory.py
View file @
4c2bcb94
...
...
@@ -8,6 +8,7 @@ from ..tfutils.common import get_op_tensor_name, get_tensors_by_names
from
..tfutils.tower
import
TowerContext
from
..tfutils.collection
import
freeze_collection
from
..utils.naming
import
TOWER_FREEZE_KEYS
from
.input_source
import
PlaceholderInput
__all__
=
[
'PredictorFactory'
]
...
...
@@ -62,9 +63,9 @@ class PredictorFactory(object):
TowerContext
(
tower_name
,
is_training
=
False
),
\
freeze_collection
(
TOWER_FREEZE_KEYS
):
if
input
is
None
:
input
=
self
.
_model
.
get_reused_placehdrs
()
else
:
input
=
input
.
get_input_tensors
()
input
=
PlaceholderInput
()
input
.
setup
(
self
.
_model
.
get_inputs_desc
())
input
=
input
.
get_input_tensors
()
assert
isinstance
(
input
,
(
list
,
tuple
)),
input
self
.
_model
.
build_graph
(
input
)
...
...
tensorpack/predict/base.py
View file @
4c2bcb94
...
...
@@ -9,6 +9,7 @@ import six
from
..tfutils.common
import
get_tensors_by_names
from
..tfutils.tower
import
TowerContext
from
..graph_builder.input_source
import
PlaceholderInput
__all__
=
[
'PredictorBase'
,
'AsyncPredictorBase'
,
'OnlinePredictor'
,
'OfflinePredictor'
,
...
...
@@ -127,9 +128,10 @@ class OfflinePredictor(OnlinePredictor):
"""
self
.
graph
=
config
.
_maybe_create_graph
()
with
self
.
graph
.
as_default
():
input_placehdrs
=
config
.
model
.
get_reused_placehdrs
()
input
=
PlaceholderInput
()
input
.
setup
(
config
.
model
.
get_inputs_desc
())
with
TowerContext
(
''
,
is_training
=
False
):
config
.
model
.
build_graph
(
input
_placehdrs
)
config
.
model
.
build_graph
(
input
)
input_tensors
=
get_tensors_by_names
(
config
.
input_names
)
output_tensors
=
get_tensors_by_names
(
config
.
output_names
)
...
...
tensorpack/tfutils/export.py
View file @
4c2bcb94
...
...
@@ -10,6 +10,7 @@ This simplifies the process of exporting a model for TensorFlow serving.
import
tensorflow
as
tf
from
..utils
import
logger
from
..graph_builder.model_desc
import
ModelDesc
from
..graph_builder.input_source
import
PlaceholderInput
from
..tfutils
import
TowerContext
,
sessinit
...
...
@@ -61,7 +62,8 @@ class ModelExport(object):
logger
.
info
(
'[export] prepare new model export'
)
super
(
ModelExport
,
self
)
.
__init__
()
self
.
model
=
model
self
.
placehdrs
=
self
.
model
.
get_reused_placehdrs
()
self
.
input
=
PlaceholderInput
()
self
.
input
.
setup
(
self
.
model
.
get_inputs_desc
())
self
.
output_names
=
output_names
self
.
input_names
=
input_names
...
...
@@ -87,7 +89,7 @@ class ModelExport(object):
"""
logger
.
info
(
'[export] build model for
%
s'
%
checkpoint
)
with
TowerContext
(
''
,
is_training
=
False
):
self
.
model
.
_build_graph
(
self
.
placehdrs
)
self
.
model
.
_build_graph
(
self
.
input
)
self
.
sess
=
tf
.
Session
(
config
=
tf
.
ConfigProto
(
allow_soft_placement
=
True
))
# load values from latest checkpoint
...
...
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