Views
No views yet

torch, torchvision, and huggingface_hub installed. Then, run the following to generate a grid of 64 random punks:1import torch
2from huggingface_hub import hf_hub_download
3from torch import nn
4from torchvision.utils import save_image
5
6
7class Generator(nn.Module):
8 def __init__(self, nc=4, nz=100, ngf=64):
9 super(Generator, self).__init__()
10 self.network = nn.Sequential(
11 nn.ConvTranspose2d(nz, ngf * 4, 3, 1, 0, bias=False),
12 nn.BatchNorm2d(ngf * 4),
13 nn.ReLU(True),
14 nn.ConvTranspose2d(ngf * 4, ngf * 2, 3, 2, 1, bias=False),
15 nn.BatchNorm2d(ngf * 2),
16 nn.ReLU(True),
17 nn.ConvTranspose2d(ngf * 2, ngf, 4, 2, 0, bias=False),
18 nn.BatchNorm2d(ngf),
19 nn.ReLU(True),
20 nn.ConvTranspose2d(ngf, nc, 4, 2, 1, bias=False),
21 nn.Tanh(),
22 )
23
24 def forward(self, input):
25 output = self.network(input)
26 return output
27
28
29model = Generator()
30weights_path = hf_hub_download('nateraw/cryptopunks-gan', 'generator.pth')
31model.load_state_dict(torch.load(weights_path, map_location=torch.device('cpu')))
32
33out = model(torch.randn(64, 100, 1, 1))
34save_image(out, "punks.png", normalize=True)