Cheat Sheet

(under construction)

Pytorch Cheat Sheet

See also : numpy cheat sheet

Numpy <-> Torch Tensor

Tensors are similar to NumPy’s ndarrays, with the addition being that Tensors can also be used on a GPU to accelerate computing.

Converting a Torch Tensor to a NumPy Array

a = torch.ones(5)
print(a)
b = a.numpy()
print(b)

Converting NumPy Array to Torch Tensor

See how changing the np array changed the Torch Tensor automatically

Datasets

There are several options for dataset

  • load data into a numpy array, then convert this array into a torch.*Tensor

  • For images, packages such as Pillow, OpenCV are useful

  • (Recommend) For vision, we have created a package called torchvision

    • data loaders for common datasets such as Imagenet, CIFAR10, MNIST, etc.

Using GPU

Visualizing Loss Curve

Evaluation

Model function

make it a function

Train function

Test function

Plot output image function

Last updated

Was this helpful?