Generative Adversarial Networks (GANs) are built upon a dynamic interaction between two neural networks: a generator and a discriminator. The generator transforms random noise into structured data resembling real samples, while the discriminator attempts to distinguish between authentic data and generated outputs. This adversarial relationship creates a learning process in which both models continuously improve, driven by opposing objectives.

© Image. https://www.geeksforgeeks.org/deep-learning/generative-adversarial-network-gan/
From Vectors to Images: The Role of Reshaping
A key design aspect in generator architectures is the transition from fully connected layers to convolutional layers. After the initial linear transformation, the data exists as a flat vector. However, convolutional operations require structured, multi-dimensional inputs. To bridge this gap, the generator reshapes the output of the fully connected layer from a two-dimensional tensor into a four-dimensional one of the form (batch size, channels, height, width).
This transformation is not merely a technical adjustment—it establishes the foundation for spatial reasoning. By reshaping the tensor into a small feature map (for example, 512 channels of size 4×4), the generator effectively constructs an initial “image-like” representation. This allows subsequent transposed convolution layers to progressively upsample and refine the data into a full-resolution image.
Output Activation and Data Normalization
Another critical design choice in GANs concerns the activation function used at the output of the generator. In many image generation tasks, real data is preprocessed so that pixel values lie within a specific range, commonly [-1, 1]. To ensure consistency between real and generated data, the generator must produce outputs within the same interval.
The hyperbolic tangent (Tanh) function naturally satisfies this requirement, as it maps its inputs into the range [-1, 1]. By using Tanh as the final activation, the generator aligns its output distribution with that of the normalized dataset. This alignment is essential for stable training, as it prevents the discriminator from exploiting simple differences in value ranges to distinguish real samples from fake ones.
The Logic of Adversarial Losses
The training of GANs is governed by carefully designed loss functions that reflect the competing goals of the two networks. The discriminator’s objective is straightforward: it learns to assign high confidence to real samples and low confidence to generated ones. This is typically achieved by computing separate losses for real and fake inputs and combining them during optimization.
The generator, however, follows a more subtle strategy. Its goal is not to directly classify data, but to produce outputs that the discriminator perceives as real. To accomplish this, the generator is trained using the discriminator’s predictions on fake samples, but with the target label set to “real.” In effect, the generator is rewarded when the discriminator is misled.
This formulation captures the essence of adversarial learning. By optimizing against the discriminator’s ability to detect fakes, the generator learns to approximate the true data distribution. Importantly, if the generator were instead trained to match fake labels, it would converge toward producing obviously artificial outputs, undermining the entire learning process.
A Competitive Learning Dynamic
The interplay between the generator and discriminator creates a feedback loop that drives both models toward improvement. As the discriminator becomes more accurate, it forces the generator to produce higher-quality samples. In response, as the generator improves, the discriminator must learn increasingly subtle distinctions. This iterative competition continues until an balance is reached, where generated data is indistinguishable from real data.
In this context, the generator’s loss function embodies the central principle of GANs: learning through deception. Rather than explicitly modeling the data distribution, the generator refines its outputs by attempting to fool an adaptive adversary. This indirect learning signal proves to be remarkably powerful, enabling GANs to produce highly realistic images and complex data representations.
Conclusion
The effectiveness of GANs lies in the coherence between architectural design and training objectives. Reshaping operations enable the transition from abstract representations to spatially structured data, while activation functions like Tanh ensure consistency with normalized datasets. Most importantly, the adversarial loss framework establishes a competitive environment where realism emerges as the outcome of strategic deception. Together, these elements form a cohesive system that has redefined generative modeling in deep learning.

© Image. https://www.geeksforgeeks.org/deep-learning/generative-adversarial-network-gan/
By following these steps we successfully implemented and trained a GAN that learns to generate realistic CIFAR-10 images through adversarial training.
Bonus
Write down your ideas.


@Yolanda Muriel 