UNIT – 3
A GAN consists of two neural networks that compete with each other:
Generation of Images: Introduction to Generative Adversarial Networks
2. Working of GAN
Random Noise → Generator → Fake Image → Discriminator → Real/Fake
The process is:
ADVERSARIAL TRAINING PROCESS IN GENERATIVE AI
Adversarial training is a learning process in which two neural networks compete with each other to improve the quality of generated data. It is most commonly used in Generative Adversarial Networks (GANs).
Main Components
Generator (G)
Discriminator (D)
Training Process
Step 1: Generate Fake Data�Random noise is given to the Generator.
Step 2: Discriminator Evaluation�The Discriminator receives:
Step 3: Calculate Errors�The Discriminator learns to correctly distinguish real samples from generated samples.
Step 4: Update the Generator�The Generator is trained to produce increasingly realistic samples that can fool the Discriminator.
Step 5: Repeat the Competition�Generator and Discriminator are trained repeatedly in an adversarial manner.
Step 6: Convergence�Ideally, the Generator becomes capable of producing highly realistic data, while the Discriminator can no longer reliably distinguish fake data from real data.
NASH EQUILIBRIUM
Key Points:
Nash equilibrium vs Dominant strategy
Example of Nash equilibrium
In the given game, we have two players with strategies S1 and S2.
S1 being the optimal strategy considering both the players know each other’s approach or they are made aware of it and both will be moving their initial strategy. They will opt for it because they know deviating from it will not be in the interest of the match.
Hence in case they opt for S1, both will win. In other cases, deviating to S2 will result in defeat of one of them.
Variational Autoencoders
A Variational Autoencoder (VAE) is a Generative AI model that learns the hidden/latent representation of data and uses it to generate new, realistic samples similar to the training data.
1. Encoder (Understanding the Input)
The encoder takes input data like images or text and learns its key features. Instead of outputting one fixed value, it produces two vectors for each feature:
These two values define a range of possibilities instead of a single number.
2. Latent Space (Adding Some Randomness)
3. Decoder (Reconstructing or Creating New Data)
Encoder-Decoder Architectures
The encoder-decoder model is a neural network used for tasks where both input and output are sequences, often of different lengths. It is commonly applied in areas like translation, summarization and speech processing.
Encoder
The encoder processes the input sequence and converts it into a fixed representation (context vector) using an RNN or LSTM.
Decoder
The decoder uses the context vector from the encoder to generate the output sequence step by step.
Working of Encoder Decoder Model
The actual working of the encoder decoder model is shown in below diagram. Now we will understand it stepwise
Step 1: Tokenizing the Input Sentence
Step 2: Encoding the Input
Step 3: Passing the Context to the Decoder
Step 4: Decoder Generates Output Step-by-Step
Step 5: Attention Mechanism
Step 6: Producing the Final Output
Stable Diffusion is a latent diffusion-based Generative AI model used to generate images from text prompts. It creates an image by starting with random noise and gradually removing the noise until a meaningful image is produced.
Stable Diffusion Models
Introduction to Transformer-based Image Generation
Step 1: Input Prompt�The user provides a text description such as “A red car on a mountain road.”
Step 2: Tokenization and Encoding�The text is divided into tokens and converted into numerical representations called embeddings.
Step 3: Transformer Processing�The Transformer uses self-attention to understand relationships between words, image tokens, or visual features.
Step 4: Image Token Generation�The model predicts image tokens that represent different parts of the desired image.
Step 5: Image Reconstruction�The generated tokens are converted into pixels or decoded into a complete image.
Step 6: Final Image�The output is a new image corresponding to the given prompt.
CLIP (Contrastive Language–Image Pre-training)
CLIP (Contrastive Language-Image Pretraining) is a multimodal AI model that learns the relationship between images and text. By training on image–text pairs, it can understand visual content through natural language descriptions and perform image recognition without task-specific training.
Key Features
1. Text Encoder
CLIP uses a Transformer-based text encoder to convert text into dense embeddings that capture semantic meaning. The encoder contains 63 million parameters, 12 layers, and 8 attention heads.
2. Image Encoder
CLIP uses an image encoder to convert images into feature embeddings. It experimented with both ResNet and Vision Transformers (ViT), with ViT showing superior performance in image understanding.
3. Dataset
CLIP was trained on about 400 million image–text pairs collected from the web. The dataset, called WebImageText (WIT), covers around 500,000 words by focusing on terms frequently appearing in English Wikipedia, enabling strong generalization across diverse concepts.
4. Training Objective
CLIP learns to align image and text embeddings so that matching pairs are similar and non-matching pairs are far apart in a shared space.
Visual Transformers (ViT), DALL·E 2 and DALL·E 3 in Generative AI
Vision Transformer (ViT) is a Generative AI architecture that applies the Transformer mechanism to image processing. Instead of processing an image using convolution operations, ViT divides the image into small patches, converts them into tokens, and processes them using self-attention.
1. Image Patching and Embedding
This stage converts a 2D image into a sequence of patch embeddings, analogous to tokens in NLP. It forms the input for the Transformer by turning spatial information into a linear sequence.
2. Positional Encoding
3. Adding the Classification Token (CLS Token)
A learnable CLS token is prepended to the patch sequence to aggregate information from all patches, serving as the image-level representation for classification.
4. Transformer Encoder (Pre-LayerNorm Architecture)
8. Classification Head (MLP Head)
Converts the CLS token output into class probabilities using a small feed-forward network.
DALLE 2 Architecture
DALL-E 2, the successor to its predecessor DALL-E, represents an open-source breakthrough by OpenAI. While DALL-E 1 employed discrete variational autoencoders (dVAE) for image generation, its revolutionary approach had constraints in terms of image resolution, realism, and image refinement. In contrast, DALL-E 2's architecture pivots towards the diffusion model, departing from dVAE, allowing it to directly generate images from CLIP embeddings.
The inception of DALL-E 2 is documented in the paper "Hierarchical Text-Conditional Image Generation with CLIP Latents," initially introduced as UnCLIP. The nomenclature UnCLIP was chosen due to its unique approach of image generation by inversely utilizing the CLIP image encoder. Over time, this innovative model earned its more recognized title as DALL-E 2.
Dall-E 2 Architecture
There are three main components of DALLE-2:
Below is the overall architecture as presented in the original paper. Let us discuss each of the components in detail.
1. Contrastive Language-Image Pre-training (CLIP)
The component shown above the dotted line is the clip component. CLIP is trained first. The objective of CLIP is to align text embeddings and image embeddings. CLIP tells how much a given text relates to an image.Note - It does not tell the caption for an image. It only whether a given description is a good fit or not for a given image
CLIP is trained as per the below process.
2 . Diffusion Prior
After the training of CLI, P the diffusion prior and image decoder are trained. The objective of diffusion prior is to take text embedding and find its associated CLIP image embeddings. Too so it takes help for the CLIP model trained in step 1.
The diffusion prior is a decoder only transformed with a causal attention mask. The input consists of 4 vectors.
3. Image Decoder
The purpose of the image decoder is to use the CLIP image embedding predicted by the diffusion prior and generate an image based on this. The diffusion model of the image decoder is based on the paper GLIDE: Towards Photorealistic Image Generation and Editing with text-Guided Diffusion Models. The GLIDE paper combined the diffusion process with UNET architecture.
UNET Architecture
Diffusion process
�
�
�
GPT-4V (GPT-4 with Vision) is a multimodal Generative AI model developed by OpenAI. Unlike traditional language models that primarily process text, GPT-4V can understand both text and visual information such as images, charts, diagrams, and screenshots.
GPT-4V
2. Text Recognition:�It can understand text appearing inside images, documents, and screenshots.
3. Visual Question Answering:�Users can ask questions about an image, and the model can generate answers based on its visual content.
4. Chart and Graph Analysis:�It can analyze graphs, tables, and other visual representations of data.
5. Multimodal Reasoning:�It can combine information from text and images to produce a more context-aware response.
6. Image-Based Explanation:�It can explain diagrams, educational figures, and technical illustrations in natural language.
Main Features
Applications
GPT-4V can be used in:
Example
Suppose a student uploads an image of a bar chart and asks:
Issues of Image Generation Models: Mode Collapse and Stability
Image generation models, especially GANs (Generative Adversarial Networks), can produce realistic images, but they face several important challenges. Two major issues are Mode Collapse and Training Stability.
1. Mode Collapse
Definition:
�Mode collapse occurs when a generative model produces very similar or nearly identical images, even when different random inputs are provided.
Different Random Inputs
↓
┌────┼────┬────┐
z₁ z₂ z₃ z₄
↓ ↓ ↓ ↓
┌────┴────┴────┴────┐
Generator
↓
Similar Images
🖼️ 🖼️ 🖼️ 🖼️
Instead of learning the complete diversity of the training dataset, the generator discovers a small number of outputs that can successfully fool the discriminator.
Example:�If the training dataset contains cars, buses, trucks, and bikes, a collapsed generator may produce mostly cars.
Causes:
Effects:
Ways to reduce Mode Collapse:
2. Training Stability
Definition:
�Training stability refers to the ability of an image generation model to learn smoothly without sudden failures, oscillations, or divergence.
The Generator (G) tries to create realistic images, while the Discriminator (D) tries to distinguish real images from generated images.
If one becomes much stronger than the other, training can become unstable.
Problems caused by instability:
UNIT -4