Imagen2Model<T>

Models & Types · AiDotNet.Diffusion.TextToImage

Imagen 2 model for improved cascaded text-to-image generation.

Inheritance: DiffusionModelBase<T> → LatentDiffusionModelBase<T> → Imagen2Model<T>

For Beginners

Imagen 2 is Google’s upgraded image generator:

Key improvements over Imagen 1:

  • Much better text rendering in images
  • Improved photorealism and detail
  • Better safety filtering
  • Enhanced prompt following

How Imagen 2 works:

  1. Text encoder produces rich embeddings
  2. Base model generates low-resolution image (64x64)
  3. Cascaded super-resolution: 64 -> 256 -> 1024
  4. Each stage uses U-Net with cross-attention to text

Use Imagen 2 when you need:

  • Photorealistic image generation
  • Text rendered correctly in images
  • High fidelity to complex prompts

How It Works

Imagen 2 is Google DeepMind’s improved text-to-image model, successor to the original Imagen. It features improved image quality, better text rendering, and enhanced prompt following.

Technical specifications:

  • Architecture: Cascaded latent diffusion with Efficient U-Net
  • Base model: 64x64 generation
  • Super-resolution stages: 64->256, 256->1024
  • Text encoder: T5-XXL (frozen, 4096-dim)
  • Dynamic thresholding for high guidance scales

Reference: Google DeepMind, “Imagen 2”, 2023

Example

var options = new DiffusionModelOptions<float> { LatentChannels = 4, DefaultInferenceSteps = 50 };
var noise = Tensor<float>.CreateRandom(new[] { 1, 4, 8, 8 });
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
    .ConfigureModel(new Imagen2Model<float>(options: options))
    .Build(trainX, trainY);
var generated = result.Predict(noise);

Constructors

Constructor Summary
Imagen2Model(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, UNetNoisePredictor<T> unet, StandardVAE<T> vae, IConditioningModule<T> conditioner, bool isImagen3, int? seed) Initializes a new instance of Imagen2Model with full customization support.

Properties

Property Summary
IConditioningModule<T> Conditioner { get; }
INoisePredictor<T> NoisePredictor { get; }
IVAEModel<T> VAE { get; }
bool IsImagen3 { get; } Counts the flat-API parameter surface (predictor + VAE).
int LatentChannels { get; }

Methods

Method Summary
Imagen2Model<T> CreateImagen3(int? seed) Creates an Imagen 3 model instance.
ModelMetadata<T> GetModelMetadata()
Tensor<T> GenerateFromText(string prompt, string negativePrompt, int width, int height, int numInferenceSteps, double? guidanceScale, int? seed)

Fields

Field Summary
int DefaultHeight
int DefaultWidth