Variable一般的初始化方法,默认是不求梯度的

import torch
from torch.autograd import Variable
x_tensor = torch.randn(2,3)

#将tensor转换成Variable
x = Variable(x_tensor) 
print(x.requires_grad) #False
x = Variable(x_tensor,requires_grad=True) #Varibale 默认时不要求梯度的,如果要求梯度,需要说明
print(x)

 

 

 

相关文章:

  • 2022-12-23
  • 2021-09-06
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2021-11-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案