torch.autograd.Variable is Autograd core classes, which encapsulates the Tensor, implement and integrate the relevant back-propagation (in order to reverse the spread of seeking after tensor becomes variable gradient? using variable .backward () to reverse the spread after , var.grad stored in the gradient var)
x = Variable(tensor, requires_grad = True)
Varibale contains three attributes:
- data: storing Tensor, it is the data body
- grad: Save the gradient data, the ability is not the Tensor Variable, consistent with the shape data
- grad_fn: Function object point, for calculating a gradient of a backpropagation
usage:
-
import torch
-
from torch.autograd import Variable
-
x = Variable(torch.one( 2,2), requires_grad = True)
-
Print (the X-) # In fact, the query is x.data, a tenso