InstantIDModel<T>
Models & Types · AiDotNet.Diffusion.Control
InstantID model — zero-shot identity-preserving image generation.
Inheritance: DiffusionModelBase<T> → LatentDiffusionModelBase<T> → InstantIDModel<T>
For Beginners
InstantID generates images of a specific person from one photo:
Key characteristics:
- Single reference image: no training or fine-tuning needed
- Face identity preservation: maintains facial features
- Text prompt control: change style, pose, expression
- Works with SDXL for high-quality output
How InstantID works:
- Face encoder extracts identity embedding from reference image
- IP-Adapter injects identity into cross-attention layers
- IdentityNet provides spatial face guidance (landmarks)
- Text prompt controls style, background, and expression
Use InstantID when you need:
- Personalized image generation from one photo
- Face-consistent character generation
- Style transfer while preserving identity
How It Works
InstantID enables identity-preserving image generation from a single reference face image without any fine-tuning. It combines a face encoder, IP-Adapter, and IdentityNet to preserve facial identity while following text prompts.
Technical specifications:
- Architecture: SDXL + IP-Adapter + IdentityNet
- Face encoder: InsightFace (512-dim embedding)
- Base model: SDXL U-Net
- Control: face landmarks via IdentityNet
- Resolution: 1024x1024
Reference: Wang et al., “InstantID: Zero-shot Identity-Preserving Generation in Seconds”, 2024
Example
// Create InstantID for zero-shot identity-preserving generation
var options = new DiffusionModelOptions<float>
{
LatentChannels = 4,
DefaultInferenceSteps = 30
};
// Generate images of a specific person from one reference photo
var faceInput = Tensor<float>.CreateRandom(new[] { 1, 512 });
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 InstantIDModel<float>(options: options))
.Build(trainX, trainY);
var personalized = result.Predict(faceInput);
Constructors
| Constructor | Summary |
|---|---|
InstantIDModel(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, UNetNoisePredictor<T> unet, StandardVAE<T> vae, IConditioningModule<T> conditioner, int? seed) |
Properties
| Property | Summary |
|---|---|
IConditioningModule<T> Conditioner { get; } |
|
INoisePredictor<T> NoisePredictor { get; } |
|
IVAEModel<T> VAE { get; } |
|
int FaceEmbeddingDim { get; } |
Gets the face embedding dimension. |
int LatentChannels { get; } |
Methods
| Method | Summary |
|---|---|
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 |