Commit 0652d859 authored by Yuxin Wu's avatar Yuxin Wu

shapeless placeholder

parent 15befae4
......@@ -32,7 +32,6 @@ class GaussianWithUniformSample(GaussianDistribution):
class Model(GANModelDesc):
def _get_input_vars(self):
return [InputVar(tf.float32, (None, 28, 28), 'input')]
......@@ -75,10 +74,10 @@ class Model(GANModelDesc):
prior = tf.constant([0.1] * 10 + [0, 0], tf.float32, [12], name='prior')
batch_prior = tf.tile(tf.expand_dims(prior, 0), [BATCH, 1], name='batch_prior')
# sample the latent code zc:
zc = symbf.remove_shape(self.factors.sample(BATCH, prior), 0, name='z_code')
z_noise = symbf.remove_shape(
# sample the latent code:
zc = symbf.shapeless_placeholder(
self.factors.sample(BATCH, prior), 0, name='z_code')
z_noise = symbf.shapeless_placeholder(
tf.random_uniform([BATCH, NOISE_DIM], -1, 1), 0, name='z_noise')
z = tf.concat_v2([zc, z_noise], 1, name='z')
......
......@@ -363,21 +363,24 @@ def soft_triplet_loss(anchor, positive, negative, extra=True):
return loss
# TODO not a good name.
def remove_shape(x, axis, name):
def shapeless_placeholder(x, axis, name):
"""
Make the static shape of a tensor less specific, by
using :func:`tf.placeholder_with_default`.
Make the static shape of a tensor less specific.
If you want to feed to a tensor, the shape of the feed value must match
the tensor's static shape. This function creates a placeholder which
defaults to x if not fed, but has a less specific static shape.
See `tensorflow#5680
<https://github.com/tensorflow/tensorflow/issues/5680>`_.
Args:
x: a tensor
axis(int or list of ints): the axes to reset shape to None.
axis(int or list of ints): these axes of ``x.get_shape()`` will become
None in the output.
name(str): name of the output tensor
Returns:
a tensor equal to x, but shape information is partially cleared
a tensor equal to x, but shape information is partially cleared.
"""
shp = x.get_shape().as_list()
if not isinstance(axis, list):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment