Install Tensorflow on Raspberry pi

From
Revision as of 22:26, 26 September 2020 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Information is taken from https://github.com/EdjeElectronics/TensorFlow-Object-Detection-on-the-Raspberry-Pi

Contents

[edit] Update the Raspberry Pi

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

[edit] Install TensorFlow

sudo pip3 install setuptools --upgrade
sudo apt-get install libatlas-base-dev
sudo pip3 install tensorflow
sudo pip3 install pillow lxml jupyter matplotlib cython
sudo apt-get install python-tk

[edit] Install OpenCV

sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install qt4-dev-tools libatlas-base-dev
sudo pip3 install opencv-python==3.4.6.27

[edit] Compile and Install Protobuf

sudo apt-get install protobuf-compiler
protoc --version

[edit] Set up TensorFlow Directory Structure and PYTHONPATH Variable

mkdir tensorflow1
cd tensorflow1
git clone --depth 1 https://github.com/tensorflow/models.git
sudo vi ~/.bashrc

Add:

export PYTHONPATH=$PYTHONPATH:/home/pi/tensorflow1/models/research:/home/pi/tensorflow1/models/research/slim

Save and exit the session.

After login:

cd /home/pi/tensorflow1/models/research
protoc object_detection/protos/*.proto --python_out=.
cd /home/pi/tensorflow1/models/research/object_detection

Download the SSDLite-MobileNet model and unpack it:

wget http://download.tensorflow.org/models/object_detection/ssdlite_mobilenet_v2_coco_2018_05_09.tar.gz 
tar -xzvf ssdlite_mobilenet_v2_coco_2018_05_09.tar.gz
wget https://raw.githubusercontent.com/EdjeElectronics/TensorFlow-Object-Detection-on-the-Raspberry-Pi/master/Object_detection_picamera.py
python3 Object_detection_picamera.py

[edit] Use a model you trained yourself

Here's a guide that shows you how to train your own model.

By adding the frozen inference graph into the object_detection directory and changing the model path in the script.

  • Copy object_detection\inference_graph directory to object_detection directory in Raspberry Pi.
  • Copy object_detection\training\lablemap.pbtxt to object_detection\data\ directory in Raspberry Pi.

Then, open the Object_detection_picamera.py script in a text editor.

  • Go to the line where MODEL_NAME is set and change the string to match the name of the new model folder.
  • Then, on the line where PATH_TO_LABELS is set, change the name of the labelmap file to match the new label map.
  • Change the NUM_CLASSES variable to the number of classes your model can identify.
Personal tools
MediaWiki Appliance - Powered by TurnKey Linux