Installing and using PyTorch 1.x
Like most Python packages, PyTorch is very simple to install. There are two main ways of doing so. The first is to simply install it using pip
in the command line. Simply type the following command:
pip install torch torchvision
While this installation method is quick, it is recommended to install using Anaconda instead, as this includes all the required dependencies and binaries for PyTorch to run. Furthermore, Anaconda will be required later to enable training models on a GPU using CUDA. PyTorch can be installed through Anaconda by entering the following in the command line:
conda install torch torchvision -c pytorch
To check that PyTorch is working correctly, we can open a Jupyter Notebook and run a few simple commands:
- To define a Tensor in PyTorch, we can do the following:
import torch x = torch.tensor([1.,2.]) print(x)
This results in the following output:
This shows that tensors within PyTorch...