Embedded System/Raspberrypi

[RPi4] install pytorch and pytorchvision

전두선 2020. 6. 27. 15:26

Procedure for Installing PyTorch and PyTorch Vision on Raspberry Pi 4B

 

1. First, update the Raspbian OS (on the terminal):

$ sudo apt-get update
$ sudo apt-get dist-upgrade

 

2. Install dependencies (on the terminal):

$ sudo apt install libopenblas-dev libblas-dev m4 cmake cython python3-dev python3-yaml python3-setuptools
$ sudo apt-get install libavutil-dev libavcodec-dev libavformat-dev libswscale-dev

 

3. You can install PyTorch and PyTorch Vision using the pre-compiled Python wheel files:

$ git clone https://github.com/sungjuGit/PyTorch-and-Vision-for-Raspberry-Pi-4B.git
$ cd PyTorch-and-Vision-for-Raspberry-Pi-4B
$ sudo pip3 install torch-1.4.0a0+f43194e-cp37-cp37m-linux_armv7l.whl
$ sudo pip3 install torchvision-0.5.0a0+9cdc814-cp37-cp37m-linux_armv7l.whl

 

4. Check the installation by running a simple test and confirming that Python outputs a tensor (5x3 matrix) with random number elements:

python3
(in the python shell)>>> from __future__ import print_function
(in the python shell)>>> import torch
(in the python shell)>>> a = torch.rand(5,3)
(in the python shell)>>> print (a)