Skip to content

Instantly share code, notes, and snippets.

@gchhablani
Created May 17, 2020 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gchhablani/70f24486b007b3799efcc55d1655182b to your computer and use it in GitHub Desktop.
Save gchhablani/70f24486b007b3799efcc55d1655182b to your computer and use it in GitHub Desktop.
vae = VAE()
vae.to(device)
criterion = nn.MSELoss()
optimizer = optim.Adamax(vae.parameters(),lr = 1e-4)
l = None
for epoch in range(100):
for i, data in enumerate(loader,0):
inputs,classes = data
inputs,classes = Variable(inputs.resize_(batch_size,784)).to(device),Variable(classes).to(device)
optimizer.zero_grad()
out = vae(inputs)
ll = latent_loss(vae.z_mean,vae.z_sigma)
loss = criterion(out,inputs)+ll
loss.backward()
optimizer.step()
l = loss.item()
print(epoch,l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment