-
Notifications
You must be signed in to change notification settings - Fork 1
/
model2.py
70 lines (59 loc) · 1.68 KB
/
model2.py
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
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
import torch
import torch.nn as nn
from utils.nn import OneHotEncoder, Maxout
# model parameters
keep_prob = 0.5
nz = 100
class Generator(nn.Module):
def __init__(self):
super(Generator, self).__init__()
self.L1z = nn.Sequential(
nn.Linear(nz, 200), # layer 1 applied to z
nn.BatchNorm1d(200),
nn.ReLU()
)
self.L1y = nn.Sequential(
OneHotEncoder(10),
nn.Linear(10, 1000), # layer 1 applied to y, the additional info (condition)
nn.BatchNorm1d(1000),
nn.ReLU()
)
self.L2 = nn.Sequential(
nn.Dropout(p=0.5),
nn.Linear(1200, 784),
nn.Sigmoid()
)
self.ohencoder = OneHotEncoder(10)
def forward(self, z, y):
z1 = self.L1z(z)
y1 = self.L1y(y)
x = torch.cat([z1, y1], dim=1) # cat z1 and y1
x = self.L2(x)
return x
class Discriminator(nn.Module):
def __init__(self):
super(Discriminator, self).__init__()
self.L1x = nn.Sequential(
Maxout(784, 240, 5),
)
self.L1y = nn.Sequential(
OneHotEncoder(10),
Maxout(10, 50, 5),
)
self.L2 = nn.Sequential(
nn.Dropout(p=0.5),
Maxout(290, 240, 4),
)
self.L3 = nn.Sequential(
nn.Dropout(p=0.5),
nn.Linear(240, 1),
nn.Sigmoid()
)
def forward(self, x, y):
x1 = self.L1x(x) # should be L1x, that's a mistake.
y1 = self.L1y(y)
x = torch.cat([x1, y1], dim=1)
x = self.L2(x)
x = self.L3(x)
return x