Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import torch
- import torch.nn as nn
- from torch.autograd import Variable
- affine = nn.Linear(10, 10)
- # A linear mapping to a random vector... just for quick demo purposes
- x = Variable(torch.randn(100, 10))
- y = Variable(torch.randn(100, 10))
- weird_loss = torch.mean(torch.exp(affine.weight))
- mse_loss = nn.MSELoss()
- pred_loss = mse_loss(affine(x), y)
- net_loss = pred_loss + weird_loss
- net_loss.backward()
- # should work just fine!
Add Comment
Please, Sign In to add comment