Why Use Variable() In Inference?
I am learning PyTorch for an image classification task, and I ran into code where someone used a PyTorch Variable() in their function for prediction: def predict_image(image):
Solution 1:
You can safely omit it. Variables are a legacy component of PyTorch, now deprecated, that used to be required for autograd:
Variable(deprecated)WARNING
The
VariableAPI has been deprecated: Variables are no longer necessary to use autograd with tensors. Autograd automatically supports Tensors withrequires_gradset toTrue. Below please find a quick guide on what has changed:
Variable(tensor)andVariable(tensor, requires_grad)still work as expected, but they return Tensors instead of Variables.
Post a Comment for "Why Use Variable() In Inference?"