title: Implementation of a WGAN-GP in tensorflow
body: <p>Using <code>tensorflow</code>, I'm trying to reimplement the following architecture (for now I'm focusing on the <em>Generator</em> part):</p>
  <p><a href="https://i.stack.imgur.com/DWafB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DWafB.png" alt="enter image description here" /></a></p>
  <p>What I've done for now has been defining the generator in the following way:</p>
  <pre><code>N_Z = 128
  
  generator = [
      tf.keras.layers.Dense(units=6144, activation=&quot;relu&quot;),
      tf.keras.layers.Reshape(target_shape=(6, 4, 256)),
      tf.keras.layers.Conv2DTranspose(
          filters=128, kernel_size=(5,5), strides=(2, 2), padding=&quot;SAME&quot;, activation=&quot;relu&quot;
      ),
      tf.keras.layers.Conv2DTranspose(
          filters=128, kernel_size=(3,3), strides=(2, 1), padding=&quot;SAME&quot;, activation=&quot;relu&quot;
      ),
      tf.keras.layers.Conv2DTranspose(
          filters=64, kernel_size=(3,3), strides=(1, 1), padding=&quot;SAME&quot;, activation=&quot;relu&quot;
      ),
       tf.keras.layers.Conv2DTranspose(
          filters=64, kernel_size=(3,3), strides=(2, 1), padding=&quot;SAME&quot;, activation=&quot;relu&quot;
      ),
      tf.keras.layers.Conv2DTranspose(
          filters=32, kernel_size=(3,3), strides=(1, 1), padding=&quot;SAME&quot;, activation=&quot;relu&quot;
      )
      tf.keras.layers.Conv2DTranspose(
          filters=32, kernel_size=(3,3), strides=(2, 1), padding=&quot;SAME&quot;, activation=&quot;relu&quot;
      )
      tf.keras.layers.Conv2DTranspose(
          filters=1, kernel_size=(3,3), strides=(1, 1), padding=&quot;SAME&quot;, activation=&quot;relu&quot;
      )
  ]
  
  Generator = tf.keras.models.Sequential(generator)
  </code></pre>
  <p>But if I take some random noise and let the model process it, this is the final shape I get back:</p>
  <pre><code>noise = tf.random.normal((64,128))
  
  result = Generator(noise)
  
  result.shape
  
  TensorShape([64, 28, 28, 1])
  </code></pre>
  <p>What am I doing wrong here? I was also checking the <a href="https://github.com/originofmatter/MatGAN/blob/master/gan_model/WGANGP_OQMD.py" rel="nofollow noreferrer">original implementation</a> to see additional details but I can't find anything that makes me understand.</p>