Class DCGAN<T>
- Namespace
- AiDotNet.NeuralNetworks
- Assembly
- AiDotNet.dll
Represents a Deep Convolutional Generative Adversarial Network (DCGAN), an architecture that uses convolutional and transposed convolutional layers with specific design guidelines for stable training.
public class DCGAN<T> : GenerativeAdversarialNetwork<T>, INeuralNetworkModel<T>, INeuralNetwork<T>, IFullModel<T, Tensor<T>, Tensor<T>>, IModel<Tensor<T>, Tensor<T>, ModelMetadata<T>>, IModelSerializer, ICheckpointableModel, IParameterizable<T, Tensor<T>, Tensor<T>>, IFeatureAware, IFeatureImportance<T>, ICloneable<IFullModel<T, Tensor<T>, Tensor<T>>>, IGradientComputable<T, Tensor<T>, Tensor<T>>, IJitCompilable<T>, IInterpretableModel<T>, IInputGradientComputable<T>, IDisposable, IAuxiliaryLossLayer<T>, IDiagnosticsProvider
Type Parameters
TThe numeric type used for calculations, typically float or double.
- Inheritance
-
DCGAN<T>
- Implements
- Inherited Members
- Extension Methods
Remarks
DCGAN introduces several architectural constraints that improve training stability: - Replace pooling layers with strided convolutions (discriminator) and fractional-strided convolutions/transposed convolutions (generator) - Use batch normalization in both generator and discriminator - Remove fully connected hidden layers for deeper architectures - Use ReLU activation in generator for all layers except output (uses Tanh) - Use LeakyReLU activation in discriminator for all layers
For Beginners: DCGAN is an improved version of the basic GAN that uses specific design patterns to make training more stable and produce higher quality images.
Key improvements over vanilla GAN:
- Uses convolutional layers specifically designed for images
- Includes batch normalization to stabilize training
- Follows proven architectural guidelines
- Produces sharper, more realistic images
Reference: Radford et al., "Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks" (2015)
Constructors
DCGAN(int, int, int, int, int, int, ILossFunction<T>?)
Initializes a new instance of the DCGAN<T> class with default DCGAN architecture.
public DCGAN(int latentSize, int imageChannels, int imageHeight, int imageWidth, int generatorFeatureMaps = 64, int discriminatorFeatureMaps = 64, ILossFunction<T>? lossFunction = null)
Parameters
latentSizeintThe size of the latent (noise) vector input to the generator.
imageChannelsintThe number of channels in the output images (e.g., 1 for grayscale, 3 for RGB).
imageHeightintThe height of the output images.
imageWidthintThe width of the output images.
generatorFeatureMapsintThe number of feature maps in the generator's first layer.
discriminatorFeatureMapsintThe number of feature maps in the discriminator's first layer.
lossFunctionILossFunction<T>Optional loss function. If not provided, binary cross-entropy will be used.
Remarks
This constructor creates a DCGAN with the standard architecture following the guidelines from the original paper. The generator uses transposed convolutions to upsample the latent vector into a full image, while the discriminator uses strided convolutions to downsample images into a classification score.
For Beginners: This sets up a DCGAN with proven settings from the research paper.
Parameters explained:
- latentSize: How many random numbers to use as input (typically 100)
- imageChannels: 1 for black/white images, 3 for color images
- imageHeight/imageWidth: The size of images to generate (e.g., 64x64)
- generatorFeatureMaps: Controls the generator's capacity (typically 64)
- discriminatorFeatureMaps: Controls the discriminator's capacity (typically 64)
The default learning rate (0.0002) is lower than typical GANs for more stable training.