Welcome to GAN Studio, a sophisticated, high-performance framework designed for the exploration, training, and deployment of Generative Adversarial Networks (GANs). This repository provides a robust environment for synthesizing high-fidelity imagery using state-of-the-art architectures, specifically tailored for stability and efficiency in constrained hardware environments.
GAN Studio bridges the gap between theoretical deep learning and practical implementation. It features a Streamlit-based interface that allows for real-time monitoring of the adversarial game, hyperparameter tuning, and latent space exploration. The framework supports both traditional Multi-Layer Perceptron (MLP) based GANs and Deep Convolutional GANs (DCGAN) enhanced with Wasserstein Loss and Gradient Penalty (WGAN-GP).
At its core, the system implements the fundamental GAN objective, where a Generator (
To mitigate common failure modes such as mode collapse and vanishing gradients, this repository defaults to the Wasserstein GAN formulation. Unlike traditional GANs that minimize the Jensen-Shannon divergence, WGAN minimizes the Earth Mover's (EM) distance or Wasserstein-1 distance:
Through the Kantorovich-Rubinstein duality, the objective for the Critic (
To enforce the 1-Lipschitz continuity constraint on the Critic without the drawbacks of weight clipping, we implement a Gradient Penalty term:
$$L_{GP} = \lambda \mathbb{E}{\hat{x} \sim P{\hat{x}}}[(|\nabla_{\hat{x}} D(\hat{x})|_2 - 1)^2]$$
where
- Simple GAN (MLP): A baseline architecture utilizing fully connected layers with LeakyReLU activations and Batch Normalization. Ideal for lower-dimensional manifolds and rapid prototyping.
- DCGAN (Deep Convolutional): Employs transposed convolutions for upsampling in the Generator and strided convolutions in the Discriminator. This architecture leverages spatial hierarchies in image data for superior synthesis quality.
GAN Studio is meticulously optimized for consumer-grade GPUs, specifically targeting environments with 4GB of VRAM. This is achieved through:
- Efficient memory buffer management during the backpropagation of the Gradient Penalty.
- Adaptive batch sizing relative to image resolution (32px, 64px, 128px).
The framework utilizes TinyDB for a lightweight, document-oriented persistence layer. This ensures that:
- Hyperparameter configurations are versioned.
- Training progress and loss metrics are logged for post-hoc analysis.
- Model checkpoints are indexed for seamless resumption of training.
Ensure you have a Python 3.8+ environment. It is highly recommended to use a virtual environment or Conda.
-
Clone the Repository:
git clone https://github.com/your-repo/gan-studio.git cd gan-studio -
Install Dependencies:
pip install -r requirements.txt
-
Launch the Studio:
streamlit run app.py
- Configuration: Select your desired architecture (Simple or DCGAN) and resolution via the sidebar.
-
Hyperparameter Tuning: Adjust the learning rate (
$\alpha$ ), coefficients for the Adam optimizer ($\beta_1, \beta_2$ ), and the Gradient Penalty coefficient ($\lambda$ ). - Training: Initiate the training loop and observe the Critic/Generator loss curves in real-time.
- Inference: Once trained, use the "Inference" mode to sample from the latent space and generate novel imagery.
-
$G(z)$ : Generator function mapping noise$z$ to data space. -
$D(x)$ : Critic/Discriminator score for input$x$ . -
$\mathbb{E}$ : Expected value. -
$\nabla$ : Gradient operator. -
$|\cdot|_2$ :$L_2$ norm.
Thank you for exploring GAN Studio. We hope this tool empowers your research and creative endeavors in the field of generative modeling. For any technical inquiries or contributions, please feel free to open an issue or pull request.
