Spaces:
Runtime error
Runtime error
Commit
·
a8421f6
1
Parent(s):
d9d0590
utils
Browse files
utils.py
CHANGED
|
@@ -1,16 +1,18 @@
|
|
| 1 |
import numpy as np
|
| 2 |
import torch
|
| 3 |
-
from huggan.pytorch.
|
| 4 |
|
|
|
|
| 5 |
def carga_modelo(model_name="ceyda/butterfly_cropped_uniq1k_512", model_version=None):
|
| 6 |
gan = LigthweigthGAN.from_pretrained(model_name, version=model_version)
|
| 7 |
gan.eval()
|
| 8 |
return gan
|
| 9 |
|
|
|
|
| 10 |
def genera(gan, batch_size=1):
|
| 11 |
with torch.no-grad():
|
| 12 |
ims = gan.G(torch.randn(batch_size, gan.latent_dim)).clamp_(0.0, 1.0)*255
|
| 13 |
ims = ims.permute(0,2,3,1).detach().cpu().numpy().astype(np.unit8)
|
| 14 |
-
|
| 15 |
|
| 16 |
|
|
|
|
| 1 |
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 = LigthweigthGAN.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 |
|