EugenioRoma commited on
Commit
a74b836
·
1 Parent(s): b77aff8

Update utils.py

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