| --- |
| license: cc-by-sa-4.0 |
| pipeline_tag: unconditional-image-generation |
| tags: |
| - GAN |
| --- |
| |
| ## Model Card: StyleGAN Model (128x128 Faces) |
|
|
| ### Model Details |
|
|
| * **Model Type:** Generative Adversarial Network (GAN) |
| * **Architecture:** Custom StyleGAN-inspired variant (Pure PyTorch implementation) |
| * **Resolution:** 128x128 (Inferred based on visual frequency outputs) |
| * **Parameters:** 19M |
| * **Training Hardware:** Kaggle (Single GPU - P100) |
| * **License:** cc-by-sa-4.0 |
|
|
| ### Model Description |
|
|
| This is a custom, from-scratch implementation of a StyleGAN-like architecture built entirely in native PyTorch. It strictly avoids NVIDIA's `dnnlib` and custom CUDA kernels (such as fused upsample/downsample and `upfirdn2d` filters). |
|
|
| The primary objective of this model is to serve as a compute-constrained proof-of-concept. It demonstrates that the global manifold of human faces can be successfully mapped using standard PyTorch operations on limited hardware (Kaggle free-tier GPUs), accepting the inherent trade-offs in memory overhead and operational latency. |
|
|
| ### Out-of-Scope Uses |
|
|
| * **High-Fidelity Generation:** This model lacks the capacity to resolve high-frequency spatial details (skin texture, fine hair, sharp ocular reflections). |
| * **Production Environments:** The reliance on unoptimized PyTorch operations makes inference slower and more memory-intensive compared to standard compiled StyleGAN models. |
|
|
| ### Limitations and Artifacts |
|
|
| Due to the architectural and computational constraints, users should expect specific structural anomalies: |
|
|
| * **Resolution Ceiling:** The output is bottlenecked at a low resolution, resulting in a smoothed, blurry appearance. |
| * **Geometric Instability:** At the edges of the learned distribution, the model struggles with background separation and asymmetrical feature alignment (e.g., glasses melting into skin, uneven eye placement). |
| * **Truncation Requirement:** To generate structurally coherent faces, a truncation trick factor of approximately $\psi = 0.7$ is required. Sampling from the unconstrained prior will likely yield severe artifacts. |
|
|
| ### Training Data |
|
|
| * **Dataset:** [[FFHQ downsampled](https://www.kaggle.com/datasets/arnaud58/flickrfaceshq-dataset-ffhq)] |
| * *Note on Bias:* Generative face models inherit the demographic biases present in their training data. Users should expect over-representation of specific ethnicities, ages, and lighting conditions based on the underlying dataset distribution. |
|
|
| ### How to Use (Code Snippet) |
|
|
| Because this repository contains a raw PyTorch `.pt` state dictionary rather than a Hugging Face compatible class, **you must define the network architecture locally before loading the weights.** |
|
|
| ```python |
| import torch |
| import torch.nn as nn |
| from huggingface_hub import hf_hub_download |
| |
| # 1. Define the exact Generator architecture used during training |
| class CustomStyleGANGenerator(nn.Module): |
| def __init__(self): |
| super().__init__() |
| # [USER MUST PASTE THE GENERATOR CLASS CODE HERE] |
| pass |
| |
| def forward(self, z): |
| # [USER MUST PASTE THE FORWARD PASS HERE] |
| pass |
| |
| # 2. Download and load the weights |
| repo_id = "Pradeep016/StyleGAN-FFHQ" |
| filename = "styleGAN_Model.pt" |
| |
| weights_path = hf_hub_download(repo_id=repo_id, filename=filename) |
| |
| # 3. Instantiate and load |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
| generator = CustomStyleGANGenerator().to(device) |
| generator.load_state_dict(torch.load(weights_path, map_location=device)) |
| generator.eval() |
| |
| # 4. Generate a sample (example using latent dim of 512) |
| with torch.no_grad(): |
| z = torch.randn(1, 512).to(device) |
| # Apply truncation psi=0.7 manually if required by your implementation |
| output_image = generator(z) |
| |
| ``` |
|  |
|
|
| [](https://colab.research.google.com/drive/1fGQ3GMXJ1RIjJPTYNdOR6Z6F4VRrVrUM?usp=sharing) |