File size: 563 Bytes
aa0a746
8abe14f
 
b934874
aa0a746
 
ce89ca9
aa0a746
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import numpy as np
import torch
import os
from huggan.pytorch.lightweight_gan.lightweight_gan import LightweightGAN

def load_model(model_name='ceyda/butterfly_cropped_uniq1K_512', model_version=None):
    gan = LightweightGAN.from_pretrained(model_name, version=model_version, use_auth_token=False)
    gan.eval()
    return gan

def generate(gan, batch_size=1):
    with torch.no_grad():
        ims = gan.G(torch.randn(batch_size, gan.latent_dim)).clamp_(0.0, 1.0) * 255
        ims = ims.permute(0,2,3,1).detach().cpu().numpy().astype(np.uint8)
    return ims