rafavidal1709 commited on
Commit
b6f0ddb
·
verified ·
1 Parent(s): 782db8e

Update Gerador.py

Browse files
Files changed (1) hide show
  1. 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
- x = self.encoder(x)
37
 
 
 
 
38
  # Ruído gaussiano, mesmo tamanho espacial de x
39
- ruido = torch.randn(x.size(0), 1, x.size(2), x.size(3), device=x.device)
40
  ruido_feat = self.ruido_proj(ruido)
41
 
42
  # Concatena ruído aos features da imagem
43
- x = torch.cat([x, ruido_feat], dim=1)
44
 
45
  x = self.super(x)
46
 
47
- return x
 
 
 
 
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