ReferenceOnlyModel<T>

Models & Types · AiDotNet.Diffusion.Control

Reference-Only model that uses a reference image’s self-attention features for conditioning.

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

For Beginners

Instead of using edge maps or depth maps as control, this directly uses another image as a reference. The AI copies the style, colors, and feel of the reference image into the new generation. No special preprocessing of the reference image is needed.

How It Works

Reference-Only control injects self-attention features from a reference image into the denoising process without requiring a separate ControlNet encoder. This enables style and content transfer by sharing attention keys and values between the reference and generated images.

Example

// Create a Reference-Only model for style transfer
var options = new DiffusionModelOptions<float>
{
    LatentChannels = 4,
    DefaultInferenceSteps = 30
};
            
// Use a reference image to guide generation style
var referenceImage = 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 ReferenceOnlyModel<float>(options: options))
    .Build(trainX, trainY);
var styledOutput = result.Predict(referenceImage);

Constructors

Constructor Summary
ReferenceOnlyModel(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, UNetNoisePredictor<T> baseUNet, StandardVAE<T> vae, IConditioningModule<T> conditioner, double referenceWeight, int? seed) Initializes a new Reference-Only model.

Properties

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

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()