StyDiffModel<T>

Models & Types · AiDotNet.Diffusion.StyleTransfer

StyDiff model for diffusion-based artistic style transfer with content preservation.

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

For Beginners

StyDiff takes the artistic style from one image (like a painting) and applies it to another image (like a photo) while keeping the photo’s content intact. The result looks like the original photo painted in the reference style.

How It Works

StyDiff performs style transfer by injecting style features from a reference image into the diffusion process via cross-attention. Content structure is preserved through DDIM inversion while the style is transferred from the reference.

Example

var options = new DiffusionModelOptions<float> { LatentChannels = 4, DefaultInferenceSteps = 30 };
var input = 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 StyDiffModel<float>(options: options))
    .Build(trainX, trainY);
var stylized = result.Predict(input);

Constructors

Constructor Summary
StyDiffModel(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()