Juan Sebastian Moncada Aguilar commited on
Commit
e496a88
·
1 Parent(s): d29db40

Carga del archivo app y utils

Browse files
Files changed (2) hide show
  1. app.py +0 -0
  2. utils.py +20 -0
app.py ADDED
File without changes
utils.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as numpy
2
+ import torch
3
+ from huggan.pytorch.lightweight_gan.lightweight_gan import LightweightGAN
4
+ # Modelo que genera gans, en este caso, nos ayuda a generar imagenes de mariposas
5
+
6
+
7
+ # Cargar modelo
8
+ def carga_modelo(model_name = "ceyda/butterfly_cropped_uniq1K_512", model_version = None):
9
+ gan = LightweightGAN.from_pretrained(model_name, version = model_version)
10
+ gan.eval()
11
+ return gan
12
+
13
+
14
+ # Ajustar el modelo para generar imagenes
15
+
16
+ def genera(gan, batch_size = 1):
17
+ with torch.no_grad():
18
+ ims = gan.G(torch.randn(batch_size, gan.latent_dim)).clamp_(0.0, 1.0) * 255
19
+ ims = ims.permute(0, 2, 3, 1).detach().cpu().numpy().astype(np.uint8)
20
+ return ims