HDPainterModel<T>

Models & Types · AiDotNet.Diffusion.ImageEditing

HD-Painter model for high-resolution inpainting with Prompt-Aware Introverted Attention (PAIntA).

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

For Beginners

HD-Painter is designed for high-resolution inpainting. When you inpaint at resolutions larger than what the model was trained on (e.g., 2048x2048), regular models often produce artifacts. HD-Painter solves this with special attention mechanisms that work well at any resolution.

How It Works

HD-Painter addresses resolution limitations in standard inpainting by using Prompt-Aware Introverted Attention (PAIntA) that constrains self-attention to masked regions while using text guidance to steer content generation. This enables coherent inpainting at resolutions beyond the model’s native training resolution.

Technical specifications:

  • Base model: Stable Diffusion 1.5 inpainting (with PAIntA modification)
  • Text encoder: CLIP ViT-L/14 (768-dim)
  • Input channels: 9 (4 latent + 4 masked image latent + 1 mask)
  • PAIntA: Constrains self-attention to masked region with text guidance
  • Supports resolutions beyond training (2K+)

Reference: Manukyan et al., “HD-Painter: High-Resolution and Prompt-Faithful Text-Guided Image Inpainting with Diffusion Models”, 2024

Example

var options = new DiffusionModelOptions<float> { LatentChannels = 4, DefaultInferenceSteps = 30 };
var maskedInput = Tensor<float>.CreateRandom(new[] { 1, 9, 256, 256 });
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 HDPainterModel<float>(options: options))
    .Build(trainX, trainY);
var inpainted = result.Predict(maskedInput);

Constructors

Constructor Summary
HDPainterModel(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, UNetNoisePredictor<T> predictor, StandardVAE<T> vae, IConditioningModule<T> conditioner, int? seed)

Properties

Property Summary
IConditioningModule<T> Conditioner { get; }
INoisePredictor<T> NoisePredictor { get; }
IVAEModel<T> VAE { get; }
int LatentChannels { get; }

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()