Tips¶
There are multiple ways to convert a Tensor to a numpy array in PyTorch.
First,
you can call the method Tensor.numpy
.
my_tensor.numpy()
Second,
you can use the function numpy.array
.
import numpy as np
np.array(my_tensor)
It is suggested that you use the function numpy.array
to convert a Tensor to a numpy array.
The reason is that numpy.array
is more generic.
You can also use it to convert other objects (e.g., PIL.Image)
to numpy arrays
while those objects might not have a method named numpy
Difference Between forward and __call__ Methods of a Module in PyTorch
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
- The
Module.__call__
method register all hooks and call the methodModule.forward
. In short, when you train the model you should use the methodforward
, while when you test the …
Pad a Sequence in Python
Tensor Transformations in TorchVision
Comments¶
Transformations in
torchvision.transforms
work on images, tensors (representing images) and possibly on numpy arrays (representing images). However, a transformation (e.g.,ToTensor
) might work differently on different input types. So you'd be clear about what exactly a transformation function does. A good practice is to always convert your non-tensor input data to tensors using the transformationToTensor
Popular and Useful Modules and Functions in PyTorch
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Functions
Train PyTorch Distributedly Using Apache Ray
Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Training a Model Implemented in PyTorch
https://github.com/ray-project/ray/tree/master/python/ray/util/sgd/pytorch/examples
Distributed PyTorch Using Apache Ray
RaySGD: Distributed Training Wrappers