2
$\begingroup$

I was coding a CGAN model using Keras along with the paper (https://arxiv.org/pdf/1411.1784.pdf) and I wanted to try and match the models to exactly what the paper says. I knew the models presented in the paper would be primitive but just wanted to replicate those and see. For example the generator model in the paper mentions this:

In the generator net, a noise prior z with dimensionality 100 was drawn from a uniform distribution within the unit hypercube. Both z and y are mapped to hidden layers with Rectified Linear Unit (ReLu) activation [4, 11], with layer sizes 200 and 1000 respectively, before both being mapped to second, combined hidden ReLu layer of dimensionality 1200. We then have a final sigmoid unit layer as our output for generating the 784-dimensional MNIST samples.

So for this I had the code like this:

def build_generator(self):

       model = Sequential()

       model.add(Dense(200, input_dim=self.latent_dim))
       model.add(Activation('relu'))
       model.add(BatchNormalization(momentum=0.8))

       model.add(Dense(1000))
       model.add(Activation('relu'))
       model.add(BatchNormalization(momentum=0.8))

       model.add(Dense(1200, input_dim=self.latent_dim))
       model.add(Activation('relu'))
       model.add(BatchNormalization(momentum=0.8))

       model.add(Dropout(0.5))

       model.add(Dense(np.prod(self.img_shape), activation='sigmoid'))
       model.add(Reshape(self.img_shape))


       model.summary()

       noise = Input(shape=(self.latent_dim,))
       label = Input(shape=(1,), dtype='int32')
       label_embedding = Flatten()(Embedding(self.num_classes, self.latent_dim)(label))

       model_input = multiply([noise, label_embedding])

       img = model(model_input)

       return Model([noise, label], img)

But still I think this not exactly what the paper means. What I understand from the paper is the noise and labels are first fed into two different layers and then combined to one layer.

Does this mean that there should be three separate models inside the generator? Or am I mistaken thinking that? Would like to hear any thoughts on this.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.