Update Gerador.py
Browse files- Gerador.py +11 -5
Gerador.py
CHANGED
|
@@ -32,16 +32,22 @@ class Gerador(nn.Module):
|
|
| 32 |
nn.Tanh() # Valor entre -1 e 1
|
| 33 |
)
|
| 34 |
|
| 35 |
-
def forward(self, x):
|
| 36 |
-
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
# Ruído gaussiano, mesmo tamanho espacial de x
|
| 39 |
-
ruido = torch.randn(
|
| 40 |
ruido_feat = self.ruido_proj(ruido)
|
| 41 |
|
| 42 |
# Concatena ruído aos features da imagem
|
| 43 |
-
x = torch.cat([
|
| 44 |
|
| 45 |
x = self.super(x)
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
nn.Tanh() # Valor entre -1 e 1
|
| 33 |
)
|
| 34 |
|
| 35 |
+
def forward(self, x, return_embedding=False, only_embedding=False):
|
| 36 |
+
embedding = self.encoder(x)
|
| 37 |
|
| 38 |
+
if only_embedding:
|
| 39 |
+
return embedding
|
| 40 |
+
|
| 41 |
# Ruído gaussiano, mesmo tamanho espacial de x
|
| 42 |
+
ruido = torch.randn(embedding.size(0), 1, embedding.size(2), embedding.size(3), device=embedding.device)
|
| 43 |
ruido_feat = self.ruido_proj(ruido)
|
| 44 |
|
| 45 |
# Concatena ruído aos features da imagem
|
| 46 |
+
x = torch.cat([embedding, ruido_feat], dim=1)
|
| 47 |
|
| 48 |
x = self.super(x)
|
| 49 |
|
| 50 |
+
if return_embedding:
|
| 51 |
+
return (embedding, x)
|
| 52 |
+
else:
|
| 53 |
+
return x
|