teleware commited on
Commit
6c8238a
1 Parent(s): 76975f0

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +23 -0
utils.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ utils.py
4
+
5
+ COLAPSARimport numpy as np
6
+ import torch
7
+ from huggan.pytorch.lightweight_gan.lightweight_gan import LightweightGAN
8
+
9
+
10
+ ## Cargamos el modelo desde el Hub de Hugging Face
11
+ def carga_modelo(model_name="ceyda/butterfly_cropped_uniq1K_512", model_version=None):
12
+ gan = LightweightGAN.from_pretrained(model_name, version=model_version)
13
+ gan.eval()
14
+ return gan
15
+
16
+
17
+ ## Usamos el modelo GAN para generar imágenes
18
+ def genera(gan, batch_size=1):
19
+ with torch.no_grad():
20
+ ims = gan.G(torch.randn(batch_size, gan.latent_dim)).clamp_(0.0, 1.0) * 255
21
+ ims = ims.permute(0, 2, 3, 1).detach().cpu().numpy().astype(np.uint8)
22
+ return ims
23
+