Skip main navigation

New offer! Get 30% off one whole year of Unlimited learning. Subscribe for just £249.99 £174.99. New subscribers only. T&Cs apply

Find out more

Introduction to PyTorch

An article giving a brief introduction to using PyTorch, in particular within Colab
A screenshot containing PyTorch code
© The University of Nottingham

In the previous video we mentioned we will be using the Python deep learning library PyTorch on this course.

In this article, we will give a brief introduction to PyTorch, and the specific way we will be using it during this course.

What is PyTorch?

PyTorch is an open source deep learning library package mainly developed by Facebook’s AI research group. Despite the name it can be used by both the Python and C++ programming languages, though on this course we only be using Python.

What can it do?

In brief, PyTorch gives you all the tools you need to quickly create, train, and evaluate neural network models, in particular the convolutional neural networks used for deep learning and discussed in following weeks. As we go through the course we will introduce all the PyTorch code you need step by step, starting with manipulation of the basic building blocks of neural networks, tensors and layers, leading up to the implementation of a deep learning image classifier, and beyond.

Installing PyTorch (or not!), and Colab

The most important thing to note in this section is the following:

You do not need to install PyTorch on your local machine to complete this course.

There are two main reasons why we don’t necessarily recommend this:

  1. Though its usually straightforward to install PyTorch itself using a package manager such as pip or conda, to really make the most of it you will need to make use of GPU acceleration and install an additional component called CUDA (see the article on GPU acceleration for more information). Unfortunately this requires your machine to have a certain kind of graphics card from NVIDIA, which many devices do not have (particularly laptops). Even if you have the right type of graphics card, CUDA can be tricky to install and configure. However, if you still want to try and install PyTorch and/or CUDA on your local machine, please follow the links at the bottom of the article.
  2. Now the good news. It is possible to run deep learning projects using PyTorch via an internet browser window using a service provided by Google called Colab. If you have already completed the previous course Machine Learning for Image Data, you should already be familiar with Colab. In brief, it allows you to write Python code (including use of PyTorch) in a notebook in a browser window, and execute it on a remote server and display the results. If you use Colab in conjunction with Google Drive, you can upload data and results to and from your local machine to the Colab servers.

For the duration of this course we will be using Colab, and the following practical article links to a quick introduction to using PyTorch within Colab. The only thing you will need other than a browser with internet connection is a free Google account. If you use any other Google product such as Gmail or Drive, you should already have an account and be able to use the same login credentials. Otherwise you will need to create an account using the onscreen instructions.

Other deep learning libraries

While we only be using PyTorch on this course, the most common other deep learning library you will encounter is called TensorFlow, which is developed by Google. TensorFlow is also open source, and can also be used with both Python and C++. Though TensorFlow is a popular choice for commercial applications, the flexibility of PyTorch lends itself well to research, and so is a common choice in this context.

This article is from the free online

Deep Learning for Bioscientists

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now