ACGAN<T>

Models & Types · AiDotNet.NeuralNetworks

Represents an Auxiliary Classifier Generative Adversarial Network (AC-GAN), which extends conditional GANs by having the discriminator also predict the class label of the input.

Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → ImageGeneratorModelLayoutBase<T> → ACGAN<T>

For Beginners

AC-GAN generates specific types of images with better quality.

Key improvements over cGAN:

  • Discriminator has two tasks: “Is it real?” AND “What class is it?”
  • This dual task helps the discriminator learn better features
  • Generator must create images that fool both checks
  • Results in higher quality and more class-consistent images

Example use case:

  • Generate digit “7” that looks very realistic
  • Discriminator checks: 1) Is it real? 2) Is it a “7”?
  • This forces the generator to make better “7”s

Reference: Odena et al., “Conditional Image Synthesis with Auxiliary Classifier GANs” (2017)

How It Works

AC-GAN improves upon conditional GANs by:

  • Making the discriminator predict both authenticity AND class label
  • Providing stronger gradient signals for class-conditional generation
  • Improving image quality and class separability
  • Enabling better control over generated samples
  • Training more stable than basic conditional GANs

Example

var options = new ACGANOptions { };
var noise = Tensor<float>.CreateRandom(new[] { 1, 100 });
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
    var generatorArchitecture = new NeuralNetworkArchitecture<float>(inputFeatures: 8, outputSize: 8);
    var discriminatorArchitecture = new NeuralNetworkArchitecture<float>(inputFeatures: 8, outputSize: 1);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
    .ConfigureModel(new ACGAN<float>(
        generatorArchitecture, discriminatorArchitecture,
        numClasses: 10, inputType: InputType.OneDimensional))
    .Build(trainX, trainY);
var generated = result.Predict(noise);

Constructors

Constructor Summary
ACGAN(NeuralNetworkArchitecture<T> generatorArchitecture, NeuralNetworkArchitecture<T> discriminatorArchitecture, int numClasses, InputType inputType, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> generatorOptimizer, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> discriminatorOptimizer, ILossFunction<T> lossFunction, ACGANOptions options) Initializes a new instance of the ACGAN class.

Properties

Property Summary
NeuralNetworkBase<T> Discriminator { get; set; } Gets the discriminator network that predicts both authenticity and class.
NeuralNetworkBase<T> Generator { get; set; } Gets the generator network that creates class-conditional synthetic data.

Methods

Method Summary
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input)
ModelMetadata<T> GetModelMetadata()
Tensor<T> CreateOneHotLabels(int batchSize, int classIndex) Creates one-hot encoded class labels.
Tensor<T> GenerateConditional(Tensor<T> noise, Tensor<T> classLabels) Generates class-conditional images.
Tensor<T> GenerateRandomNoiseTensor(int batchSize, int noiseSize) Generates random noise tensor using vectorized Gaussian noise generation.
ValueTuple<T, T> TrainStep(Tensor<T> realImages, Tensor<T> realLabels, Tensor<T> noise, Tensor<T> fakeLabels) Performs one training step for the AC-GAN.
void ResetOptimizerState() Resets both optimizer states for a fresh training run.