InfoGAN<T>
Models & Types · AiDotNet.NeuralNetworks
Represents an Information Maximizing Generative Adversarial Network (InfoGAN), which learns disentangled representations in an unsupervised manner by maximizing mutual information between latent codes and generated observations.
Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → ImageGeneratorModelLayoutBase<T> → InfoGAN<T>
For Beginners
InfoGAN learns to separate different features automatically.
Key concept:
- Splits random input into two parts:
- Random noise (z): provides variety
- Latent codes (c): control specific features
- Learns what each code controls WITHOUT labels
- Example: For faces, might learn codes for:
- Code 1: controls rotation
- Code 2: controls width
- Code 3: controls lighting
How it works:
- Generator uses both z and c to create images
- Auxiliary network Q tries to predict c from the generated image
- If Q can predict c accurately, the codes are meaningful
- This forces codes to represent interpretable features
Use cases:
- Discover semantic features in datasets
- Disentangled representation learning
- Controllable image generation
- Feature manipulation (change one aspect, keep others)
Reference: Chen et al., “InfoGAN: Interpretable Representation Learning by Information Maximizing Generative Adversarial Nets” (2016)
How It Works
InfoGAN extends the GAN framework by:
- Decomposing the input noise into incompressible noise (z) and latent codes (c)
- Maximizing the mutual information I(c; G(z,c)) between codes and generated images
- Learning interpretable and disentangled representations automatically
- Using an auxiliary network Q to approximate the posterior P(c|x)
- Enabling control over semantic features without labeled data
Example
var architecture = new NeuralNetworkArchitecture<float>(inputFeatures: 8, outputSize: 4);
var noise = Tensor<float>.CreateRandom(new[] { 1, 74 });
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 InfoGAN<float>(architecture))
.Build(trainX, trainY);
var generated = result.Predict(noise);
Constructors
| Constructor | Summary |
|---|---|
InfoGAN(NeuralNetworkArchitecture<T> architecture, InfoGANOptions options) |
Creates an InfoGAN with default architectures derived from a single architecture. |
InfoGAN(NeuralNetworkArchitecture<T> generatorArchitecture, NeuralNetworkArchitecture<T> discriminatorArchitecture, NeuralNetworkArchitecture<T> qNetworkArchitecture, int latentCodeSize, InputType inputType, InfoGANOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> generatorOptimizer, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> discriminatorOptimizer, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> qNetworkOptimizer, ILossFunction<T> lossFunction) |
Initializes a new instance of the InfoGAN class with the specified architecture and training parameters. |
Properties
| Property | Summary |
|---|---|
NeuralNetworkBase<T> Discriminator { get; set; } |
Gets the discriminator network. |
NeuralNetworkBase<T> Generator { get; set; } |
Gets the generator network. |
NeuralNetworkBase<T> QNetwork { get; set; } |
Gets the auxiliary Q network that predicts latent codes from images. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input) |
Surfaces named activations from each sub-network so introspection invariants (NamedLayerActivations_ShouldBeNonEmpty) see real per-network state. |
ModelMetadata<T> GetModelMetadata() |
|
Tensor<T> ForwardForTraining(Tensor<T> input) |
Defines the InfoGAN forward graph for tape-based training. |
Tensor<T> Generate(Tensor<T> noise, Tensor<T> latentCodes) |
Generates images with specific latent codes. |
Tensor<T> GenerateRandomLatentCodes(int batchSize) |
Generates random latent codes: each categorical code one-hot over a uniformly drawn value, then each continuous code from Uniform(-1, 1). |
Tensor<T> GenerateRandomNoiseTensor(int batchSize, int noiseSize) |
Generates random noise tensor using vectorized Gaussian noise generation with CPU/GPU acceleration. |
ValueTuple<T, T, T> TrainStep(Tensor<T> realImages, Tensor<T> noise, Tensor<T> latentCodes) |
Performs one training step for InfoGAN. |
void ResetOptimizerState() |
Resets the state of all optimizers to their initial values. |