Skip to content

Instantly share code, notes, and snippets.

@AFAgarap
Last active January 14, 2020 12:59
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 AFAgarap/6b1d67dc7ecb34032e1ae2f7100fef65 to your computer and use it in GitHub Desktop.
Save AFAgarap/6b1d67dc7ecb34032e1ae2f7100fef65 to your computer and use it in GitHub Desktop.
Object instantiation for training an autoencoder written in PyTorch.
# use gpu if available
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# create a model from `AE` autoencoder class
# load it to the specified device, either gpu or cpu
model = AE(input_shape=784).to(device)
# create an optimizer object
# Adam optimizer with learning rate 1e-3
optimizer = optim.Adam(model.parameters(), lr=1e-3)
# mean-squared error loss
criterion = nn.MSELoss()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment