Skip to main content

Seaweed Image Generation Using GANs

Project Overview This project focuses on generating images of seaweed using Generative Adversarial Networks (GANs). Similar to typical GAN architectures, it consists of two main components:
Generator: Creates synthetic seaweed images from random noise.
Discriminator: Distinguishes between real seaweed images and those created by the generator.

Visit github
  • Import and Setup
  • Model building
  • Training Process
  • Save Generated Images
Sample seaweed image generated by the GAN model

Imports and Setup

The project begins by importing necessary libraries, primarily using TensorFlow to build and train the neural networks. Key components include:

  • Layers: Dense, Conv2D, UpSampling2D
  • Optimizer: Adam

  • These are used to construct the generator and discriminator models.

    Code snippet showing the TensorFlow imports used to build the GAN

    Model Building

    Generator (build_generator())

  • The generator takes a latent vector as input and uses Dense, Reshape, Conv2D, and UpSampling2D layers to progressively upscale the vector into an image of size 1024x1024.
  • It starts from a small representation and increases the resolution step by step using UpSampling2D.
  • The final layer uses a tanh activation function to generate RGB images with values in the range [-1, 1].
  • Generator network architecture used to upscale latent vectors into seaweed images

    Discriminator (build_discriminator())

  • The discriminator takes an image as input and attempts to classify it as real or fake.
  • It consists of a series of Conv2D layers with strides of 2, followed by LeakyReLU activations and dropout layers to reduce overfitting.
  • The output layer uses a sigmoid activation function to produce a probability score indicating whether the input image is real or fake.
  • Discriminator network architecture used to classify real vs generated images

    Training Process

    The train_gan() function manages the training of both the discriminator and generator.
    Training Loop:

  • In each iteration:
  • The discriminator is trained on both real and generated images to minimize classification error for real images and maximize it for generated images.
  • The generator is trained via the combined model to produce images that the discriminator classifies as real.
  • Training loop output showing generator and discriminator updates
    Underwater background image

    Saving Generated Images

    This function generates and saves images produced by the generator during training.

  • Images are saved in PNG format, allowing the evaluation of the generator's performance at different training epochs.
  • Sample seaweed images saved to disk during training epochs