File size: 1,712 Bytes
fb9d001 cab1fbd 3fe3de5 6fdbe9b fb9d001 33d2a9d 3fe3de5 33d2a9d f28c741 33d2a9d 3fe3de5 779d7d6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
---
license: afl-3.0
tags:
- PyTorch
- huggan
- gan
- unconditional-image-generation
---
## Model Description
Generate Art using PyTorch and [DCGAN](https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html).
## How To Use
```python
from huggingface_hub import hf_hub_download
import torch
import matplotlib.pyplot as plt
import numpy as np
from torch import nn
class Generator(nn.Module):
def __init__(self):
super(Generator, self).__init__()
self.main = nn.Sequential(
nn.ConvTranspose2d(100, 64 * 8, 4, 1, 0, bias=False),
nn.BatchNorm2d(64 * 8),
nn.ReLU(True),
nn.ConvTranspose2d(64 * 8, 64 * 4, 4, 2, 1, bias=False),
nn.BatchNorm2d(64 * 4),
nn.ReLU(True),
nn.ConvTranspose2d(64 * 4, 64 * 2, 4, 2, 1, bias=False),
nn.BatchNorm2d(64 * 2),
nn.ReLU(True),
nn.ConvTranspose2d(64 * 2, 64, 4, 2, 1, bias=False),
nn.BatchNorm2d(64),
nn.ReLU(True),
nn.ConvTranspose2d(64, 3, 4, 2, 1, bias=False),
nn.Tanh()
)
def forward(self, input):
return self.main(input)
path = hf_hub_download('huggan/ArtGAN', 'ArtGAN.pt')
model = torch.load(path, map_location=torch.device('cpu'))
device = 'cuda' if torch.cuda.is_available() else 'cpu'
def generate(seed):
with torch.no_grad():
noise = torch.randn(seed, 100, 1, 1, device=device)
with torch.no_grad():
art = model(noise).detach().cpu()
gen = np.transpose(art[-1], (1, 2, 0))
fig = plt.figure(figsize=(5, 5))
plt.imshow(gen)
plt.axis('off')
generate(25)
```
## Generate Image

|