Skip to content

Instantly share code, notes, and snippets.

@25b3nk
Last active March 22, 2019 12:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 25b3nk/019079c730ec1c8d69ccd2888933b7a9 to your computer and use it in GitHub Desktop.
Save 25b3nk/019079c730ec1c8d69ccd2888933b7a9 to your computer and use it in GitHub Desktop.
Installing PyTorch on Raspberry Pi 3B+

First of all we will upgrade and update the packages

sudo apt update && sudo apt upgrade
sudo apt install vim

Add extra SWAP memory: If you don’t want to get ‘Memory exhausted’ or ‘Cannot Allocate Memory’, increase you swap memory.

sudo dd if=/dev/zero of=/swap1 bs=1M count=2048
sudo mkswap /swap1

Open fstab file to add the swap

sudo vim /etc/fstab

Add the following line at the end

/swap1 swap swap

Then Reboot

sudo reboot now

Install pre-requisites

sudo apt install libopenblas-dev libblas-dev m4 cmake cython python3-dev python3-yaml python3-setuptools

Pytorch developers call for python3 but I installed in python2

Create a folder and clone PyTorch

mkdir ~/libraries/pytorch/
cd ~/libraries/pytorch/
git clone https://github.com/pytorch/pytorch
cd pytorch
git checkout -b v1.0.0 v1.0.0
git submodule update --init

Export environment variables

export NO_CUDA=1
export NO_DISTRIBUTED=1
export NO_MKLDNN=1 
export NO_NNPACK=1   # Not compulsory
export NO_QNNPACK=1  # Not compulsory

Build the library

sudo pip install -U setuptools
sudo pip install -r requirements.txt
sudo -E MAX_JOBS=1 python setup.py install  # To install in the host machine
sudo -E MAX_JOBS=1 python setup.py bdist_wheel  # To get the .whl file, which one can use to install using pip on any other similar machines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment