FreeInpaintModel<T>
Models & Types · AiDotNet.Diffusion.ImageEditing
Free-form inpainting model using masked diffusion with irregular mask support.
Inheritance: DiffusionModelBase<T> → LatentDiffusionModelBase<T> → FreeInpaintModel<T>
For Beginners
Most inpainting works with simple rectangular masks. Free inpainting lets you draw any shape — circles, squiggles, complex outlines — and fills them in naturally. Great for detailed retouching and creative editing.
How It Works
Supports arbitrary free-form masks of any shape, not just rectangular regions. Uses mask-aware attention in the SD1.5 U-Net to ensure generated content respects irregular boundaries while maintaining visual coherence with surrounding context.
Technical specifications:
- Base model: Stable Diffusion 1.5 inpainting
- Text encoder: CLIP ViT-L/14 (768-dim)
- Input channels: 9 (4 latent + 4 masked image latent + 1 mask)
- Mask support: Arbitrary free-form shapes
- Mask-aware attention for boundary coherence
Example
var options = new DiffusionModelOptions<float> { LatentChannels = 4, DefaultInferenceSteps = 30 };
var maskedInput = Tensor<float>.CreateRandom(new[] { 1, 4, 64, 64 });
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 FreeInpaintModel<float>(options: options))
.Build(trainX, trainY);
var inpainted = result.Predict(maskedInput);
Constructors
| Constructor | Summary |
|---|---|
FreeInpaintModel(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() |