Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions vae/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def encode(self, x):

def reparameterize(self, mu, logvar):
if self.training:
std = logvar.mul(0.5).exp_()
eps = Variable(std.data.new(std.size()).normal_())
return eps.mul(std).add_(mu)
std = logvar.mul(0.5).exp_()
eps = Variable(std.data.new(std.size()).normal_())
return eps.mul(std).add_(mu)
else:
return mu
return mu

def decode(self, z):
h3 = self.relu(self.fc3(z))
Expand Down Expand Up @@ -129,10 +129,10 @@ def test(epoch):
recon_batch, mu, logvar = model(data)
test_loss += loss_function(recon_batch, data, mu, logvar).data[0]
if i == 0:
n = min(data.size(0), 8)
comparison = torch.cat([data[:n],
n = min(data.size(0), 8)
comparison = torch.cat([data[:n],
recon_batch.view(args.batch_size, 1, 28, 28)[:n]])
save_image(comparison.data.cpu(),
save_image(comparison.data.cpu(),
'results/reconstruction_' + str(epoch) + '.png', nrow=n)

test_loss /= len(test_loader.dataset)
Expand All @@ -144,7 +144,7 @@ def test(epoch):
test(epoch)
sample = Variable(torch.randn(64, 20))
if args.cuda:
sample = sample.cuda()
sample = sample.cuda()
sample = model.decode(sample).cpu()
save_image(sample.data.view(64, 1, 28, 28),
'results/sample_' + str(epoch) + '.png')