Browse files

Replaced stride=2 conv2d_transpose with separate upscaling and stride…

  • Loading branch information...
1 parent 4367556 commit 67678fecac773fb13ea3e09236a853b2f9940304 David Garcia committed Oct 18, 2016
Showing with 15 additions and 2 deletions.
  1. +15 −2
@@ -287,6 +287,16 @@ def add_mean(self):
return self
+ def add_upscale(self):
+ """Adds a layer that upscales the output by 2x through nearest neighbor interpolation"""
+ prev_shape = self.get_output().get_shape()
+ size = [2 * int(s) for s in prev_shape[1:3]]
+ out = tf.image.resize_nearest_neighbor(self.get_output(), size)
+ self.outputs.append(out)
+ return self
def get_output(self):
"""Returns the output from the topmost layer of the network"""
return self.outputs[-1]
@@ -364,10 +374,13 @@ def _generator_model(sess, features, labels, channels):
for j in range(2):
model.add_residual_block(nunits, mapsize=mapsize)
- # Spatial upscale
+ # Spatial upscale (see
+ # and transposed convolution
+ model.add_upscale()
- model.add_conv2d_transpose(nunits, mapsize=mapsize, stride=2, stddev_factor=1.)
+ model.add_conv2d_transpose(nunits, mapsize=mapsize, stride=1, stddev_factor=1.)
# Finalization a la "all convolutional net"
nunits = res_units[-1]

6 comments on commit 67678fe


I could not run this code because an error raised 'the size of tensor is not right'


You need a more recent version of Tensorflow.

zceehua commented on 67678fe Nov 17, 2016 edited

It works after I restart my virtual machine, really wired. It would be so kind if you can offer some help to me on these questions that confused me a lot.
The shape of input is I=[batch-size,16,16,3] ,the shape of filter is F=[mapzise,mapsize,prev_units,num_units]. Let's consider the case I=[batch-size,16,16,3] and F=[1,1,3,256] for the convolution from input to first hidden layer:
1.What does mapsize mean,does it mean filter size?
2.The convolution of I and F really confused me. For example, the output after conv of I and F would be of shape [batch-size,16,16,256]. Does it mean the first hidden layer is matrix of shape [16,16,256] rather than [1,256]?
3.What is the purpose of discriminator model?

  1. Yes, mapsize represents the convolutional filter size in pixels.
  2. You may want to read a Tensorflow tutorial to understand how its convolutional operations work. Yes, the first hidden layer has dimensions [batch_size, 16, 16, 256].
  3. The network is similar to a DCGAN. The discriminator portion is needed to train the generator portion. See for details.
zceehua commented on 67678fe Jan 8, 2017

Hi I am back agian. Thanks for patience.
There is another quesiton is that in the function 'create_discriminator_loss' you have added 'cross_entropy_fake = tf.nn.sigmoid_cross_entropy_with_logits(disc_fake_output, tf.zeros_like(disc_fake_output))'.
Our goal is to make disc_fake_output larger while this step is doing the opposite.I do not quite catch the meaning of it.


You've had a few more days to think about this. Does it make sense now?

Please sign in to comment.