MCPcopy Create free account
hub / github.com/OUCMachineLearning/OUCML / VAE

Class VAE

One_Day_One_GAN/day15/vae.py:40–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38
39
40class VAE(nn.Module):
41 def __init__(self):
42 super(VAE, self).__init__()
43
44 self.fc1 = nn.Linear(784, 400)
45 self.fc21 = nn.Linear(400, 20)
46 self.fc22 = nn.Linear(400, 20)
47 self.fc3 = nn.Linear(20, 400)
48 self.fc4 = nn.Linear(400, 784)
49
50 def encode(self, x):
51 h1 = F.relu(self.fc1(x))
52 return self.fc21(h1), self.fc22(h1)
53
54 def reparametrize(self, mu, logvar):
55 std = logvar.mul(0.5).exp_()
56 if torch.cuda.is_available():
57 eps = torch.cuda.FloatTensor(std.size()).normal_()
58 else:
59 eps = torch.FloatTensor(std.size()).normal_()
60 eps = Variable(eps)
61 return eps.mul(std).add_(mu)
62
63 def decode(self, z):
64 h3 = F.relu(self.fc3(z))
65 return F.sigmoid(self.fc4(h3))
66
67 def forward(self, x):
68 mu, logvar = self.encode(x)
69 z = self.reparametrize(mu, logvar)
70 return self.decode(z), mu, logvar
71
72
73model = VAE()

Callers 1

vae.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected