Pytorch-Is it possible to forward a tensor through a model (only Variable works)?

In Pytorch 0.4, I can forward a tensor through a model which is the same as Variable.

import torch
print(torch.__version__)

Maybe in Pytorch version < 0.4, it is not possible to forward a tensor through am model.

Ref to:

https://discuss.pytorch.org/t/what-is-the-difference-between-tensors-and-variables-in-pytorch/4914/3

The Variable class is a wrapper over torch Tensors (nd arrays in torch) that supports nearly all operations defined on tensors. PyTorch requires that the input tensor to be forward propagated has to be wrapped in a Variable. This facilitates automatic back propagation by simply calling the method backward() in the Variable class.

猜你喜欢

转载自www.cnblogs.com/quinn-yann/p/9245978.html