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
1f498ed6
Commit
1f498ed6
authored
Dec 22, 2018
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tf.TensorSpec == InputDesc
parent
c667b1de
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
8 deletions
+24
-8
tensorpack/graph_builder/model_desc.py
tensorpack/graph_builder/model_desc.py
+24
-8
No files found.
tensorpack/graph_builder/model_desc.py
View file @
1f498ed6
...
...
@@ -7,10 +7,15 @@ import tensorflow as tf
from
..models.regularize
import
regularize_cost_from_collection
from
..tfutils.tower
import
get_current_tower_context
from
..tfutils.common
import
get_tf_version_tuple
from
..utils
import
logger
from
..utils.argtools
import
memoized_method
from
..utils.develop
import
log_deprecated
if
get_tf_version_tuple
()
>=
(
1
,
7
):
from
tensorflow.python.framework.tensor_spec
import
TensorSpec
__all__
=
[
'InputDesc'
,
'ModelDesc'
,
'ModelDescBase'
]
...
...
@@ -71,7 +76,7 @@ class InputDesc(
self
.
_cached_placeholder
[
graph
]
=
placeholder
@
staticmethod
def
from_placeholder
(
placeholder
):
def
_
from_placeholder
(
placeholder
):
name
=
placeholder
.
op
.
name
if
name
.
endswith
(
'_1'
)
or
name
.
endswith
(
'_2'
):
logger
.
error
(
"Creating InputDesc from a placeholder named {}."
.
format
(
name
))
...
...
@@ -83,6 +88,11 @@ class InputDesc(
ret
.
_register_cached_placeholder
(
placeholder
)
return
ret
@
staticmethod
def
_from_tensor_spec
(
spec
):
assert
spec
.
name
is
not
None
,
"TensorSpec should have a name!"
return
InputDesc
(
spec
.
dtype
,
tuple
(
spec
.
shape
.
as_list
()),
spec
.
name
)
class
ModelDescBase
(
object
):
"""
...
...
@@ -106,9 +116,14 @@ class ModelDescBase(object):
except
NotImplementedError
:
with
tf
.
Graph
()
.
as_default
()
as
G
:
# create these placeholder in a temporary graph
inputs
=
self
.
inputs
()
if
isinstance
(
inputs
[
0
],
tf
.
Tensor
):
for
p
in
inputs
:
assert
p
.
graph
==
G
,
"Placeholders returned by inputs() should be created inside inputs()!"
return
[
InputDesc
.
from_placeholder
(
p
)
for
p
in
inputs
]
return
[
InputDesc
.
_from_placeholder
(
p
)
for
p
in
inputs
]
else
:
for
p
in
inputs
:
assert
isinstance
(
p
,
TensorSpec
),
type
(
p
)
return
[
InputDesc
.
_from_tensor_spec
(
p
)
for
p
in
inputs
]
@
property
def
input_names
(
self
):
...
...
@@ -123,16 +138,17 @@ class ModelDescBase(object):
def
inputs
(
self
):
"""
__Create__ and returns a list of
placeholders.
Returns a list of :class:`tf.TensorSpec` or
placeholders.
A subclass is expected to implement this method.
The placeholders __have to__ be created inside this method.
Don't return placeholders created in other methods.
If returning placeholders,
the placeholders __have to__ be created inside this method.
Don't return placeholders created in other places.
Also, you should never call this method by yourself.
Returns:
a list of `tf.placeholder`
, to be converted to :class:`InputDesc`.
list[tf.placeholder] or list[tf.TensorSpec]
, to be converted to :class:`InputDesc`.
"""
raise
NotImplementedError
()
...
...
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