Repository navigation
Expand file tree
/
Copy pathmodels.py
More file actions
62 lines (45 loc) · 1.8 KB
/
Copy pathmodels.py
File metadata and controls
62 lines (45 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import torch
import torch.nn as nn
class Discriminator(torch.nn.Module):
def __init__(self, input_channels=3):
super(Discriminator, self).__init__()
self.model = nn.Sequential(
nn.Conv2d(3, 128, 4, 2, 1, bias=False),
nn.LeakyReLU(0.2, inplace=True),
nn.Conv2d(128, 256, 4, 2, 1, bias=False),
nn.BatchNorm2d(256),
nn.LeakyReLU(0.2, inplace=True),
nn.Conv2d(256, 512, 4, 2, 1, bias=False),
nn.BatchNorm2d(512),
nn.LeakyReLU(0.2, inplace=True),
nn.Conv2d(512, 1024, 4, 2, 1, bias=False),
nn.BatchNorm2d(1024),
nn.LeakyReLU(0.2, inplace=True),
nn.Conv2d(1024, 1, 4, 1, 0, bias=False),
)
def forward(self, x):
x=self.model(x)
return x
class Generator(torch.nn.Module):
def __init__(self, noise_dim, output_channels=3):
super(Generator, self).__init__()
self.noise_dim = noise_dim
self.model = nn.Sequential(
nn.ConvTranspose2d( self.noise_dim, 1024, 4, 1, 0, bias=False),
nn.BatchNorm2d(1024),
nn.ReLU(True),
nn.ConvTranspose2d(1024, 512, 4, 2, 1, bias=False),
nn.BatchNorm2d(512),
nn.ReLU(True),
nn.ConvTranspose2d(512, 256, 4, 2, 1, bias=False),
nn.BatchNorm2d(256),
nn.ReLU(True),
nn.ConvTranspose2d( 256, 128, 4, 2, 1, bias=False),
nn.BatchNorm2d(128),
nn.ReLU(True),
nn.ConvTranspose2d( 128, output_channels, 4, 2, 1, bias=False),
nn.Tanh()
)
def forward(self, x):
x=self.model(x)
return x