2
$\begingroup$

I found this article about art generation which uses GAN architecture to generate art. Let's move to part where we define our generator model.

def build_generator(noise_size, channels):
    model = Sequential()
    model.add(Dense(4 * 4 * 256, activation=”relu”,       input_dim=noise_size))
    model.add(Reshape((4, 4, 256)))
    model.add(UpSampling2D())
    model.add(Conv2D(256, kernel_size=3, padding=”same”))
    model.add(BatchNormalization(momentum=0.8))
    model.add(Activation(“relu”))
    model.add(UpSampling2D())
    model.add(Conv2D(256, kernel_size=3, padding=”same”))
    model.add(BatchNormalization(momentum=0.8))
    model.add(Activation(“relu”))
    for i in range(GENERATE_RES):
         model.add(UpSampling2D())
         model.add(Conv2D(256, kernel_size=3, padding=”same”))
         model.add(BatchNormalization(momentum=0.8))
         model.add(Activation(“relu”))
    model.summary()
    model.add(Conv2D(channels, kernel_size=3, padding=”same”))
    model.add(Activation(“tanh”))
    input = Input(shape=(noise_size,))
    generated_image = model(input)
    return Model(input, generated_image)

I understand why we increase input to 4x4x256(model.add(Dense(4 * 4 * 256, activation=”relu”, input_dim=noise_size))), but generator returns image with shape 4x4x256. How to work with this image? What's going on? As i think, we can work only with gray(1 channel) images and RGB images(3 channels).

$\endgroup$

1 Answer 1

1
$\begingroup$

The number 4 has nothing to do with the number of channels but is simply used to define the dimension of the latent space (which is 2048 in total, 4 x 4 x 256). The generator outputs an image of shape (128, 128, 3), the height and width of the images are 128 pixels and the images have 3 channels. This can be seen when defining the last layer Conv2d layer of the generator:

model.add(Conv2D(channels, kernel_size=3, padding="same"))

The number of channels/filters for this layer is defined by the channels variable, which is an argument for the build_generator function. When this function is called later on you can see that the value provided is IMAGE_CHANNELS, which is set to 3 at the start of the article.

Nevertheless, it is possible to work with images with 4 channels. These images have a fourth dimension which represent the alpha in addition to red, green, and blue (RGBA).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.