Building the generator

The generator needs to produce 32 x 32 x 3 images. This requires two slight changes to our network architecture that you can see here:

input = Input(noise_shape)
x = Dense(128 * 8 * 8, activation="relu")(input)
x = Reshape((8, 8, 128))(x)
x = BatchNormalization(momentum=0.8)(x)
x = UpSampling2D()(x)
x = Conv2D(128, kernel_size=3, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(momentum=0.8)(x)
x = UpSampling2D()(x)
x = Conv2D(64, kernel_size=3, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(momentum=0.8)(x)
x = Conv2D(3, kernel_size=3, padding="same")(x)
out = Activation("tanh")(x)
model = Model(input, out)

Since we need to end at 32, and we will upsample twice, we should begin at 8. This is easily accomplished by changing the dense layer and it's respective reshape layer from 128 * 7 * 7 to 128 * 8 * 8.

Since our image now contains three channels, the last convolutional layer needs to also contain three channels instead of one. That's all there is to it; we can now generate color images!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.82.154