Pi / openCV / Tensorflow again

Cat detector code updated for Raspian Buster. I used lite. A few things have changed since the last time. The code is here.

Download Raspian

I got Raspbian Buster Lite (from https://www.raspberrypi.org/downloads/raspbian/ )

Burn it onto a SD card.

touch /boot/ssh
Add the wifi
nano /boot/wpa_supplicant.conf

The file should containing something like:

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
   ssid="foo"
   psk="bar"
}

then eject the card and put it in the pi.

ssh into it from your laptop

pi@raspberrypi.local
password: raspberry
sudo nano /etc/hosts
sudo nano /etc/hostname

Reboot

sudo reboot

Set up a virtualenv for python

ssh in again, then:

sudo apt update
sudo apt-get install python3-pip
sudo pip3 install virtualenv -p
python3 env
source env/bin/activate
(env) pi@birdbot:~ $ python --version

Enable the camera

sudo raspi-config # and enable camera under 'interfacing'; reboot

Install Tensorflow

Increase the swap size:

sudo nano /etc/dphys-swapfile

The default value in Raspbian is:

CONF_SWAPSIZE=100

We will need to change this to:

CONF_SWAPSIZE=1024

Restart the service that manages the swapfile own Raspbian:

sudo /etc/init.d/dphys-swapfile restart

Install tensorflow dependencies

sudo apt-get install libatlas-base-dev
sudo apt-get install git
pip install --upgrade tensorflow

(this takes a few minutes)

Test that tensorflow installed ok:

python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"

You may see an error about hadoop –

HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory.

See also tensorflow/tensorflow#36141 and tensorflow/tensorflow#36141. That doesn’t seem to matter.

You could try some user built tensorflow binaries – I tried this one, which seemed to corrupt my SD card, but not tried this one. Tensorflow 2 would be better to learn (the apis all changed between 1.4 and 2).

Install OpenCV

sudo apt-get install libjasper-dev
sudo apt-get install libqtgui4
sudo apt install libqt4-test

pip install opencv-contrib-python==3.4.3.18 #(see this)

test

python -c 'import cv2; print(cv2.__version__)'

Install camera dependencies

sudo apt-get install imutils picamera

Install speaking dependencies

sudo apt-get install espeak-ng

Finally:

git clone https://github.com/libbymiller/cat_loving_robot
cd cat_loving_robot
python classify_image.py

If you want to add the servos and so on for cat detecting and running towards cats, there’s more info in github.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s