Skip to content

Instantly share code, notes, and snippets.

@jvanlier
Last active September 8, 2022 04:45
Show Gist options
  • Save jvanlier/e6152870efb301a5f5933b26a72e17da to your computer and use it in GitHub Desktop.
Save jvanlier/e6152870efb301a5f5933b26a72e17da to your computer and use it in GitHub Desktop.
fast.ai for vision on Raspbery pi 4 (Raspbian)

By default, PyTorch team doesn't release packages for ARM architecture. Luckily, someone is supplying unofficial builds (hats off to this person!).

Fast.ai also has a problem: it depends on spaCy, which also doesn't want to build on ARM by default. I'm not going to do NLP, so will install fast.ai without spaCy.

PyTorch

I initially tried using ARM builds from here:

https://github.com/nmilosev/pytorch-arm-builds

However, I couldn't get these to work on a Raspberry Pi 4.

Somebody else built more recent versions that do actually work on a Pi 4:

https://github.com/sungjuGit/Pytorch-and-Vision-for-Raspberry-Pi-4B

There are some system level dependencies for PyTorch and numpy that can be installed as follows on Raspbian:

$ sudo apt install libopenblas-dev libblas-dev m4 cmake cython python3-dev python3-yaml python3-setuptools python3-wheel python3-pillow python3-numpy libatlas-base-dev

I am running system python3 in a fresh virtualenv, Python version is 3.7.3.

In the virtualenv, run:

$ pip install https://github.com/sungjuGit/PyTorch-and-Vision-for-Raspberry-Pi-4B/raw/master/torch-1.4.0a0%2Bf43194e-cp37-cp37m-linux_armv7l.whl
$ pip install https://github.com/sungjuGit/PyTorch-and-Vision-for-Raspberry-Pi-4B/raw/master/torchvision-0.5.0a0%2B9cdc814-cp37-cp37m-linux_armv7l.whl

This will also pull in numpy and pillow.

fast.ai

The fastai library seems to have a nonstandard way of specifying dependency groups, which requires a git clone of the entire repo. See here: https://docs.fast.ai/install.html

To sum up, they expect you to first install fastai without deps:

$ pip install --no-deps fastai

And then you're supposed to run, from within the repo:

 $ pip install $(python setup.py -q deps --dep-groups=core,vision)

For the current latest version, 1.0.61, this expression works out to:

$ git checkout 1.0.61
$ echo $(python setup.py -q deps --dep-groups=core,vision)
Pillow beautifulsoup4 bottleneck dataclasses;python_version<'3.7' fastprogress>=0.2.1 matplotlib numexpr numpy>=1.15 nvidia-ml-py3 packaging pandas pynvx>=1.0.0;platform_system=="Darwin" pyyaml requests scipy torch>=1.0.0 torchvision

Why not just use the default options in setup.py for dependency groups? Oh well. Let's see if we can make this work.

Removing the pynvx package that refers to a MacOS (Darwin) build, dataclasses (since I'm running 3.7+ anyway) and what's already installed by Pytorch, this can be simplified to:

$ pip install --no-deps fastai
$ pip install beautifulsoup4 bottleneck 'fastprogress>=0.2.1' matplotlib numexpr nvidia-ml-py3 packaging pandas pyyaml requests scipy

It seems like pynvx isn't needed on a Pi to run inference on CPU.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment