1

I'm using this code to train a DCGAN model to generate images. DCGAN

I want to be able to output (predict) images at a greater resolution than the model was trained at, and I'm told this is possible if convolution is used. In the following code, which describes the generator model, if I change the stride on the Conv2DTranspose layers I can increase the output shape (therefore image resolution). How can I set the stride to a different value during training than prediction? Or is there a different way to do what I want?

# Creates the generator model. This model has an input of random noise and
# generates an image that will try mislead the discriminator.

def construct_generator():
generator = Sequential()

generator.add(Dense(units=4 * 4 * 512,
                    kernel_initializer='glorot_uniform',
                    input_shape=(1, 1, 100)))
generator.add(Reshape(target_shape=(4, 4, 512)))
generator.add(BatchNormalization(momentum=0.5))
generator.add(Activation('relu'))

generator.add(Conv2DTranspose(filters=256, kernel_size=(5, 5),
                              strides=(2, 2), padding='same',
                              data_format='channels_last',
                              kernel_initializer='glorot_uniform'))
generator.add(BatchNormalization(momentum=0.5))
generator.add(Activation('relu'))

generator.add(Conv2DTranspose(filters=128, kernel_size=(5, 5),
                              strides=(2, 2), padding='same',
                              data_format='channels_last',
                              kernel_initializer='glorot_uniform'))
generator.add(BatchNormalization(momentum=0.5))
generator.add(Activation('relu'))

generator.add(Conv2DTranspose(filters=64, kernel_size=(5, 5),
                              strides=(2, 2), padding='same',
                              data_format='channels_last',
                              kernel_initializer='glorot_uniform'))
generator.add(BatchNormalization(momentum=0.5))
generator.add(Activation('relu'))

generator.add(Conv2DTranspose(filters=3, kernel_size=(5, 5),
                              strides=(2, 2), padding='same',
                              data_format='channels_last',
                              kernel_initializer='glorot_uniform'))
generator.add(Activation('tanh'))

optimizer = Adam(lr=0.00015, beta_1=0.5)
generator.compile(loss='binary_crossentropy',
                  optimizer=optimizer,
                  metrics=None)

return generator
mrboni
  • 11
  • 3
  • It is probably best to make your images the same resolution in training and inference. If you need higher resolution in inference, just increase the resolution of your training images. – iga Oct 25 '18 at 16:42

0 Answers0