Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vae: Fix UserWarning #220

Merged
merged 3 commits into from
Sep 22, 2017
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
12 changes: 4 additions & 8 deletions vae/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

parser = argparse.ArgumentParser(description='PyTorch MNIST Example')
parser.add_argument('--batch-size', type=int, default=128, metavar='N',
help='input batch size for training (default: 64)')
help='input batch size for training (default: 128)')
parser.add_argument('--epochs', type=int, default=10, metavar='N',
help='number of epochs to train (default: 2)')
help='number of epochs to train (default: 10)')
parser.add_argument('--no-cuda', action='store_true', default=False,
help='enables CUDA training')
parser.add_argument('--seed', type=int, default=1, metavar='S',
Expand Down Expand Up @@ -56,11 +56,7 @@ def encode(self, x):

def reparametrize(self, mu, logvar):
std = logvar.mul(0.5).exp_()
if args.cuda:
eps = torch.cuda.FloatTensor(std.size()).normal_()
else:
eps = torch.FloatTensor(std.size()).normal_()
eps = Variable(eps)
eps = Variable(std.data.new(std.size()).normal_())
return eps.mul(std).add_(mu)

def decode(self, z):
Expand All @@ -82,7 +78,7 @@ def forward(self, x):


def loss_function(recon_x, x, mu, logvar):
BCE = reconstruction_function(recon_x, x)
BCE = reconstruction_function(recon_x, x.view(-1, 784))

# see Appendix B from VAE paper:
# Kingma and Welling. Auto-Encoding Variational Bayes. ICLR, 2014
Expand Down