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
3fa1a499
Commit
3fa1a499
authored
Dec 05, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support sparse placeholder
parent
e3e21c61
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
14 deletions
+14
-14
examples/GAN/Image2Image.py
examples/GAN/Image2Image.py
+1
-1
tensorpack/models/model_desc.py
tensorpack/models/model_desc.py
+12
-12
tensorpack/tfutils/summary.py
tensorpack/tfutils/summary.py
+1
-1
No files found.
examples/GAN/Image2Image.py
View file @
3fa1a499
...
...
@@ -115,7 +115,7 @@ class Model(ModelDesc):
output
=
tf
.
image
.
grayscale_to_rgb
(
output
)
fake_output
=
tf
.
image
.
grayscale_to_rgb
(
fake_output
)
viz
=
(
tf
.
concat
(
2
,
[
input
,
output
,
fake_output
])
+
1.0
)
*
128.0
viz
=
tf
.
cast
(
viz
,
tf
.
uint8
,
name
=
'viz'
)
viz
=
tf
.
cast
(
tf
.
clip_by_value
(
viz
,
0
,
255
)
,
tf
.
uint8
,
name
=
'viz'
)
tf
.
image_summary
(
'gen'
,
viz
,
max_images
=
max
(
30
,
BATCH
))
all_vars
=
tf
.
trainable_variables
()
...
...
tensorpack/models/model_desc.py
View file @
3fa1a499
...
...
@@ -17,8 +17,12 @@ from ..tfutils.tower import get_current_tower_context
__all__
=
[
'ModelDesc'
,
'InputVar'
,
'ModelFromMetaGraph'
]
_InputVar
=
namedtuple
(
'InputVar'
,
[
'type'
,
'shape'
,
'name'
])
_InputVar
=
namedtuple
(
'InputVar'
,
[
'type'
,
'shape'
,
'name'
,
'sparse'
])
class
InputVar
(
_InputVar
):
def
__init__
(
self
,
type
,
shape
,
name
,
sparse
=
False
):
super
(
InputVar
,
self
)
.
__init__
(
type
,
shape
,
name
,
sparse
)
def
__new__
(
cls
,
type
,
shape
,
name
,
sparse
=
False
):
return
super
(
InputVar
,
cls
)
.
__new__
(
cls
,
type
,
shape
,
name
,
sparse
)
def
dumps
(
self
):
return
pickle
.
dumps
(
self
)
@
staticmethod
...
...
@@ -35,11 +39,11 @@ class ModelDesc(object):
:returns: the list of raw input vars in the graph
"""
try
:
return
self
.
_reuse_input_vars
()
except
KeyError
:
pass
return
self
.
get_placeholders
()
if
hasattr
(
self
,
'reuse_input_vars'
)
:
return
self
.
reuse_input_vars
ret
=
self
.
get_placeholders
()
self
.
reuse_input_vars
=
ret
return
ret
def
get_placeholders
(
self
,
prefix
=
''
):
""" build placeholders with optional prefix, for each InputVar
...
...
@@ -49,16 +53,12 @@ class ModelDesc(object):
tf
.
add_to_collection
(
INPUT_VARS_KEY
,
v
.
dumps
())
ret
=
[]
for
v
in
input_vars
:
ret
.
append
(
tf
.
placeholder
(
placehdr_f
=
tf
.
placeholder
if
not
v
.
sparse
else
tf
.
sparse_placeholder
ret
.
append
(
placehdr_f
(
v
.
type
,
shape
=
v
.
shape
,
name
=
prefix
+
v
.
name
))
return
ret
def
_reuse_input_vars
(
self
):
""" Find and return already-defined input_vars in default graph"""
input_var_names
=
[
k
.
name
for
k
in
self
.
_get_input_vars
()]
return
get_tensors_by_names
(
input_var_names
)
def
get_input_vars_desc
(
self
):
""" return a list of `InputVar` instance"""
return
self
.
_get_input_vars
()
...
...
tensorpack/tfutils/summary.py
View file @
3fa1a499
...
...
@@ -99,7 +99,7 @@ def add_moving_summary(v, *args):
v
=
[
v
]
v
.
extend
(
args
)
for
x
in
v
:
assert
x
.
get_shape
()
.
ndims
==
0
assert
x
.
get_shape
()
.
ndims
==
0
,
x
.
get_shape
()
tf
.
add_to_collection
(
MOVING_SUMMARY_VARS_KEY
,
x
)
@
memoized
...
...
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