File size: 1,726 Bytes
9004bad
 
 
 
 
df3f948
 
 
 
 
 
 
 
 
 
 
1eb7a47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
library_name: pytorch
tags:
- dcgan
---
# cryptopunks-gan

A DCGAN trained to generate novel Cryptopunks.

Check out the code by Teddy Koker [here](https://github.com/teddykoker/cryptopunks-gan).

## Generated Punks

Here are some punks generated by this model:

![](fake_samples_epoch_999.png)

## Usage

You can try it out yourself, or you can play with the [demo](https://huggingface.co/spaces/nateraw/cryptopunks-generator).

To use it yourself - make sure you have `torch`, `torchvision`, and `huggingface_hub` installed. Then, run the following to generate a grid of 64 random punks:

```python
import torch
from huggingface_hub import hf_hub_download
from torch import nn
from torchvision.utils import save_image


class Generator(nn.Module):
    def __init__(self, nc=4, nz=100, ngf=64):
        super(Generator, self).__init__()
        self.network = nn.Sequential(
            nn.ConvTranspose2d(nz, ngf * 4, 3, 1, 0, bias=False),
            nn.BatchNorm2d(ngf * 4),
            nn.ReLU(True),
            nn.ConvTranspose2d(ngf * 4, ngf * 2, 3, 2, 1, bias=False),
            nn.BatchNorm2d(ngf * 2),
            nn.ReLU(True),
            nn.ConvTranspose2d(ngf * 2, ngf, 4, 2, 0, bias=False),
            nn.BatchNorm2d(ngf),
            nn.ReLU(True),
            nn.ConvTranspose2d(ngf, nc, 4, 2, 1, bias=False),
            nn.Tanh(),
        )

    def forward(self, input):
        output = self.network(input)
        return output


model = Generator()
weights_path = hf_hub_download('nateraw/cryptopunks-gan', 'generator.pth')
model.load_state_dict(torch.load(weights_path, map_location=torch.device('cpu')))

out = model(torch.randn(64, 100, 1, 1))
save_image(out, "punks.png", normalize=True)
```