Update README.md
Browse files
README.md
CHANGED
|
@@ -14,3 +14,46 @@ Check out the code by Teddy Koker [here](https://github.com/teddykoker/cryptopun
|
|
| 14 |
Here are some punks generated by this model:
|
| 15 |
|
| 16 |

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
Here are some punks generated by this model:
|
| 15 |
|
| 16 |

|
| 17 |
+
|
| 18 |
+
## Usage
|
| 19 |
+
|
| 20 |
+
You can try it out yourself, or you can play with the [demo](https://huggingface.co/spaces/nateraw/cryptopunks-generator).
|
| 21 |
+
|
| 22 |
+
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:
|
| 23 |
+
|
| 24 |
+
```python
|
| 25 |
+
import torch
|
| 26 |
+
from huggingface_hub import hf_hub_download
|
| 27 |
+
from torch import nn
|
| 28 |
+
from torchvision.utils import save_image
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class Generator(nn.Module):
|
| 32 |
+
def __init__(self, nc=4, nz=100, ngf=64):
|
| 33 |
+
super(Generator, self).__init__()
|
| 34 |
+
self.network = nn.Sequential(
|
| 35 |
+
nn.ConvTranspose2d(nz, ngf * 4, 3, 1, 0, bias=False),
|
| 36 |
+
nn.BatchNorm2d(ngf * 4),
|
| 37 |
+
nn.ReLU(True),
|
| 38 |
+
nn.ConvTranspose2d(ngf * 4, ngf * 2, 3, 2, 1, bias=False),
|
| 39 |
+
nn.BatchNorm2d(ngf * 2),
|
| 40 |
+
nn.ReLU(True),
|
| 41 |
+
nn.ConvTranspose2d(ngf * 2, ngf, 4, 2, 0, bias=False),
|
| 42 |
+
nn.BatchNorm2d(ngf),
|
| 43 |
+
nn.ReLU(True),
|
| 44 |
+
nn.ConvTranspose2d(ngf, nc, 4, 2, 1, bias=False),
|
| 45 |
+
nn.Tanh(),
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
def forward(self, input):
|
| 49 |
+
output = self.network(input)
|
| 50 |
+
return output
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
model = Generator()
|
| 54 |
+
weights_path = hf_hub_download('nateraw/cryptopunks-gan', 'generator.pth')
|
| 55 |
+
model.load_state_dict(torch.load(weights_path, map_location=torch.device('cpu')))
|
| 56 |
+
|
| 57 |
+
out = model(torch.randn(64, 100, 1, 1))
|
| 58 |
+
save_image(out, "punks.png", normalize=True)
|
| 59 |
+
```
|