rafavidal1709 commited on
Commit
31a4a28
·
verified ·
1 Parent(s): 2a67b4c

Upload 2 files

Browse files
Files changed (2) hide show
  1. Gerador.py +53 -0
  2. config(1).json +7 -0
Gerador.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Gerador.py
2
+
3
+ import torch
4
+ import torch.nn as nn
5
+ import torch.nn.functional as F
6
+
7
+ class Gerador(nn.Module):
8
+ def __init__(self):
9
+ super(Gerador, self).__init__()
10
+
11
+ self.encoder = nn.Sequential(
12
+ nn.Conv2d(12, 64, 5, padding=2),
13
+ nn.ReLU(),
14
+
15
+ nn.Conv2d(64, 64, 3, padding=1),
16
+ nn.ReLU()
17
+ )
18
+
19
+ # Projeção do ruído para o mesmo tamanho espacial
20
+ self.ruido_proj = nn.Conv2d(1, 64, kernel_size=1) # 1 canal de ruído -> 64
21
+
22
+ self.super = nn.Sequential(
23
+ nn.ConvTranspose2d(128, 128, kernel_size=7, stride=7),
24
+ nn.BatchNorm2d(128),
25
+ nn.LeakyReLU(0.2),
26
+
27
+ nn.Conv2d(128, 64, kernel_size=5, padding=2),
28
+ nn.BatchNorm2d(64),
29
+ nn.LeakyReLU(0.2),
30
+
31
+ nn.Conv2d(64, 3, kernel_size=3, padding=1), # Saída em 3 canais: RGB
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
config(1).json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ ```json
2
+ {
3
+ "input_channels": 12,
4
+ "output_channels": 3,
5
+ "upscale_factor": 7,
6
+ "activation": "tanh"
7
+ }