Art generation with VQGAN + CLIP in Docker, with a simple web UI for anyone with a GPU. A simplified and expanded take on Kevin Costa's work.
aiai-artclipdockerdocker-composegpuhandcodedimagenetpythonpytorchtorchtorchvisionvqganvqgan-clip
1import torch
2import torch.nn as nn
3
4
5class Downsample(nn.Module):
6 def __init__(self, in_channels, with_conv):
7 super().__init__()
8 self.with_conv = with_conv
9 if self.with_conv:
10 # no asymmetric padding in torch conv, must do it ourselves
11 self.conv = torch.nn.Conv2d(
12 in_channels, in_channels, kernel_size=3, stride=2, padding=0
13 )
14
15 def forward(self, x):
16 if self.with_conv:
17 pad = (0, 1, 0, 1)
18 x = torch.nn.functional.pad(x, pad, mode="constant", value=0)
19 x = self.conv(x)
20 else:
21 x = torch.nn.functional.avg_pool2d(x, kernel_size=2, stride=2)
22 return x