Elementor #1688

Coral USB Accelerator configuration on Raspberry-Pi 4

 
This post goes through the steps of configuring Coral USB accelerator on Raspberry Pi 4

Following are the steps:

Step 1. Installing Coral EdgeTPU Runtime and Python API

In this step, we will use your aptitude package manager to install Google Coral’s Debian/Raspbian-compatible package.

First, let’s add the package repository:

$ 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-get update

Now we can install the EdgeTPU runtime library and then EdgeTPU Python API

$ sudo apt-get install libedgetpu1-std
$ sudo apt-get install python3-edgetpu

 

Step 2: Reboot the device

sudo reboot now

 

Step 3: Setting up Coral Python Virtual Environment

We will use python virtual environment to setup a env called “coral”. 

If pip is not installed, it can be installed using below commands

$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
$ sudo python3 get-pip.py
$ sudo python3 get-pip.py

Installing virtualenv and virtualenvwrapper

$ sudo pip install virtualenv virtualenvwrapper
 
Setting the python3 and virtualenv paths in bashrc
Open bashrc using nano command
$ nano ~/.bashrc
add below lines at the end of the file, and save and exit using Ctrl+W and Ctrl+X
 
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_ENV_BIN_DIR=bin
 
Reload bashrc using source command to reload the scrip and apply the changes made
$ source ~/.bashrc

Final step of creating Python virtual environment, name of virtual env is “coral”.

$ mkvirtualenv coral -p python3

 

Step 4: Symbolic linking of EdgeTPU runtime libraries to virtual environment

 

Let us first find the location of EdgeTPU runtime libraries using below command.

$ dpkg -L python3-edgetpu
/.
/usr
/usr/lib
/usr/lib/python3
/usr/lib/python3/dist-packages
/usr/lib/python3/dist-packages/edgetpu
/usr/lib/python3/dist-packages/edgetpu/__init__.py
/usr/lib/python3/dist-packages/edgetpu/basic

Creating symbolic link by referring to the site-packages path above of edgetpu

$ cd ~/.virtualenvs/coral/lib/python3.7/site-packages
$ ln -s /usr/lib/python3/dist-packages/edgetpu/ edgetpu
$ cd ~

Step 5: Testing Coral EdgeTPU Installation

Activate the virtual env using below command and import edgetpu library and find version

$ workon coral
$ python
$ (coral) >> import edgetpu
$ (coral) >> edgetpu.__version__
'2.13.0'

Congratulations!!! Coral Edge TPU is successfully installed on the Raspberry Pi-4

Leave a Reply