also dubbed the Light-GAN model. This model was trained using the script
here which is adapted from the lucidrains
repo.
Differently from the script above, I used the transforms from the official repo. Because our training images were already cropped and aligned.
official paper implementation
repo
1transform_list = [
2 transforms.Resize((int(im_size),int(im_size))),
3 transforms.RandomHorizontalFlip(),
4 transforms.ToTensor(),
5 transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
6 ]
1
2import torch
3from huggan.pytorch.lightweight_gan.lightweight_gan import LightweightGAN # install the community-events repo above
4
5gan = LightweightGAN.from_pretrained("ceyda/butterfly_cropped_uniq1K_512")
6gan.eval()
7batch_size = 1
8with torch.no_grad():
9 ims = gan.G(torch.randn(batch_size, gan.latent_dim)).clamp_(0., 1.)*255
10 ims = ims.permute(0,2,3,1).detach().cpu().numpy().astype(np.uint8)
11 # ims is [BxWxHxC] call Image.fromarray(ims[0])
1000 images are used, while it was possible to increase this number, we didn't have time to manually curate the dataset.
& also wanted to see if it was possible to do low data training as mention in the paper.
Trained on 2xA4000s for ~1day. Can see good results within 7-12h.
Importans params: "--batch_size 64 --gradient_accumulate_every 4 --image_size 512 --mixed_precision fp16"
Training logs can be seen
here
calculated FID score on 100 images. results for different checkpoints are
here
Made during the huggan sprint.
Additional contributions by Jonathan Whitaker
https://twitter.com/johnowhitaker