rodragon737 commited on
Commit
ad3a7c1
1 Parent(s): 37c0e9c

refactory Utils

Browse files
Files changed (1) hide show
  1. utils.py +6 -4
utils.py CHANGED
@@ -2,13 +2,15 @@ import numpy as np
2
  import torch
3
  from huggan.pytorch.lightweight_gan.lightweight_gan import LightweightGAN
4
 
 
5
  def carga_modelo(model_name="ceyda/butterfly_cropped_uniq1K_512", model_version=None):
6
- gan = LightweightGAN.from_pretrained(model_name, versio=model_version)
7
  gan.eval()
8
  return gan
9
 
10
- def general(gan, batch_size=1):
 
11
  with torch.no_grad():
12
- ims = gan.G(torch.rand(batch_size, gan.latent_dim)).clamp_(0.0, 1.0) * 255
13
- ims = ims.permute(0,2,3,1).deatch().cpu().numpy().astype(np.uint8)
14
  return ims
 
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.uint8)
16
  return ims