This installation is tested on the following Raspberry Pi SBCs:
- Raspberry Pi 4B
- Raspberry Pi 5
6.6.51-1+rpt3 (2024-10-08) aarch64 GNU/Linux)
with the following Coral TPUs:
- Coral USB Accelerator
- Coral Dual Edge TPU (installed on a Pineboards Hat AI!)
on a fresh installation of Debian 12 Bookworm. It does not require manual recompiling any of the libraries or modules.
sudo apt update
sudo apt full-upgrade
Install pyenv following the instructions on https://github.com/pyenv/pyenv:
curl https://pyenv.run | bash
Add the following to the .bashrc
and restart shell:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
exec $SHELL
pyenv
builds from source. Install Python build dependencies for installing different versions following the instructions on https://github.com/pyenv/pyenv/wiki#suggested-build-environment:
sudo apt update
sudo apt install build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
Check the possible python versions and install the latest compatible version:
pyenv install --list
pyenv install -v 3.9.20
If you want to enable optimizations run the following instead of above install command
CONFIGURE_OPTS="--enable-optimizations" pyenv install -v 3.9.20
Check the available installed versions and set the global python version to the installed version:
pyenv versions
pyenv global 3.9.20
Install pipenv and set the environment variable such that the virtual environment is always created inside the project folder (second step is not a necessity):
pip install pipenv
echo "export PIPENV_VENV_IN_PROJECT=1" >> ~/.bashrc
Below follows from: https://coral.ai/docs/accelerator/get-started/
Install libedgetpu1-std library:
echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt update
sudo apt install libedgetpu1-std
Install following additional packages
sudo apt-get install cmake devscripts debhelper dkms dh-dkms
Clone and build gasket-driver from source:
git clone https://github.com/google/gasket-driver.git
cd gasket-driver
debuild -us -uc -tc -b
cd ..
sudo dpkg -i gasket-dkms_*.deb
Create apex
group and add the user to it
sudo sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"
sudo groupadd apex
sudo adduser $USER apex
Move to the directory, where you would like to have your project and create a virtual environment:
cd ~/Documents
mkdir coral && cd coral
python -m venv .venv
Activate the virtual environment. This can be done either using pipenv shell
or simply sourcing the activate script source .venv/bin/activate
.
Install the pycoral module from private url using pip:
pip install numpy==1.26.4
pip install --extra-index-url https://google-coral.github.io/py-repo/ pycoral~=2.0
Now plug in the Coral USB Accelerator or if it was plugged in, remove it and plug in again. It should be ready to go.
If you want to run Dual Edge TPU add the following in your /boot/firmware/config.txt
.
[all]
# Enable the PCIe External connector.
dtparam=pciex1
kernel=kernel8.img
# Enable Pineboards Hat Ai
dtoverlay=pineboards-hat-ai
Then reboot with
sudo reboot now
Create and run the following python script in the previously created virtual environment:
from pycoral.utils.edgetpu import list_edge_tpus
if __name__ == '__main__':
for edge_tpu in list_edge_tpus():
print(edge_tpu)
Assuming you are still in the coral
directory created above, pull the repository and change into the directory:
git clone --recurse-submodules https://github.com/google-coral/pycoral
cd pycoral
Get the dependencies of the examples:
bash examples/install_requirements.sh
Run the image classifier example on https://coral.ai/docs/accelerator/get-started/#3-run-a-model-on-the-edge-tpu:
python3 examples/classify_image.py \
--model test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
--labels test_data/inat_bird_labels.txt \
--input test_data/parrot.jpg
When running
pip install --extra-index-url https://google-coral.github.io/py-repo/ pycoral~=2.0
the latest version of Numpy is installed which is 2.x. This is incompatible as Numpy 1.x is required. So, make sure to install, e.g., Numpy 1.26.4 which seems to be the latest 1.x Numpy release.