Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- pytorch
|
| 5 |
+
- gan
|
| 6 |
+
- dcgan
|
| 7 |
+
- image-generation
|
| 8 |
+
- face-generation
|
| 9 |
+
- celeba
|
| 10 |
+
datasets:
|
| 11 |
+
- huggan/celeba
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# DCGAN — Human Face Generation (CelebA)
|
| 15 |
+
|
| 16 |
+
A Deep Convolutional GAN trained on CelebA to generate 64×64 human face images.
|
| 17 |
+
|
| 18 |
+
## Config
|
| 19 |
+
|
| 20 |
+
| Property | Value |
|
| 21 |
+
|----------|-------|
|
| 22 |
+
| Architecture | DCGAN (Radford et al., 2015) |
|
| 23 |
+
| Dataset | CelebA — train split (162,770 images) |
|
| 24 |
+
| Resolution | 64×64 RGB |
|
| 25 |
+
| Latent dim | 100 |
|
| 26 |
+
| Epochs | 25 |
|
| 27 |
+
| Batch size | 256 |
|
| 28 |
+
| Optimizer | Adam lr=0.0002 β₁=0.5 |
|
| 29 |
+
| Mixed precision | torch.bfloat16 |
|
| 30 |
+
|
| 31 |
+
## Usage
|
| 32 |
+
|
| 33 |
+
```python
|
| 34 |
+
import torch, torch.nn as nn
|
| 35 |
+
from huggingface_hub import hf_hub_download
|
| 36 |
+
|
| 37 |
+
class Generator(nn.Module):
|
| 38 |
+
def __init__(self, nz=100, ngf=64, nc=3):
|
| 39 |
+
super().__init__()
|
| 40 |
+
self.main = nn.Sequential(
|
| 41 |
+
nn.ConvTranspose2d(nz, ngf*8, 4, 1, 0, bias=False), nn.BatchNorm2d(ngf*8), nn.ReLU(True),
|
| 42 |
+
nn.ConvTranspose2d(ngf*8, ngf*4, 4, 2, 1, bias=False), nn.BatchNorm2d(ngf*4), nn.ReLU(True),
|
| 43 |
+
nn.ConvTranspose2d(ngf*4, ngf*2, 4, 2, 1, bias=False), nn.BatchNorm2d(ngf*2), nn.ReLU(True),
|
| 44 |
+
nn.ConvTranspose2d(ngf*2, ngf, 4, 2, 1, bias=False), nn.BatchNorm2d(ngf), nn.ReLU(True),
|
| 45 |
+
nn.ConvTranspose2d(ngf, nc, 4, 2, 1, bias=False), nn.Tanh()
|
| 46 |
+
)
|
| 47 |
+
def forward(self, x): return self.main(x)
|
| 48 |
+
|
| 49 |
+
weights = hf_hub_download(repo_id="arzumanabbasov/DCGAN_CELEBA", filename="generator.pt")
|
| 50 |
+
netG = Generator()
|
| 51 |
+
netG.load_state_dict(torch.load(weights, map_location="cpu"))
|
| 52 |
+
netG.eval()
|
| 53 |
+
|
| 54 |
+
with torch.no_grad():
|
| 55 |
+
noise = torch.randn(16, 100, 1, 1)
|
| 56 |
+
faces = netG(noise) # (16, 3, 64, 64) in [-1, 1]
|
| 57 |
+
faces = (faces + 1) / 2 # → [0, 1] for display
|
| 58 |
+
```
|