RPi i TensorFlow. Object detection and classification
Contingut
Referència
Portable Computer Vision: TensorFlow 2.0 on a Raspberry Pi:
- https://towardsdatascience.com/portable-computer-vision-tensorflow-2-0-on-a-raspberry-pi-part-1-of-2-84e318798ce9
- https://github.com/leigh-johnson/rpi-vision
Instal·lació (NO)
sudo apt-get update sudo apt-get upgrade sudo apt-get install git python3-dev python3-pip \ crossbuild-essential-armhf libatlas-base-dev \ libhdf5-dev libhdf5-serial-dev \ libopenjp2-7-dev libtiff5 build-essential cmake pkg-config
Hi ha un error: és libtiff5 i no ibtiff5.
Treballarem amb entorns virtuals:
sudo pip3 install -U virtualenv git clone git@github.com:leigh-johnson/rpi-vision.git
A mi la comanda git clone no m'ha funcionat (problemes de permisos), o sigui que m'he descarregat directametn el zip i l'he enviat a la RPi:
$ scp rpi-vision-master.zip pi@192.168.1.60:/home/pi
cd rpi-vision virtualenv -p $(which python3) .venv $ ~/rpi-vision-master $ source .venv/bin/activate (.venv) pi@raspberrypi:PS1="E $ " E $ pip install -e .
Però em dóna un error:
E $ pip install -e . Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Obtaining file:///home/pi/rpi-vision-master ERROR: tensorflow-2.0.0b1-cp35-cp35m-linux_armv7l.whl is not a supported wheel on this platform.
Triga moltíssim, i crec que no cal:
pip install --upgrade tensorflow
La solució està en entrar en el setup.py, i comentar les línies:
#if 'arm' in platform.machine():
i les dues següents, de manera que no peti quan compili contra el arm. Més amunt posa que
# tensorflow 2.0 wheel has not been released for Raspbian yet
Però en canvi el tutorial ho fan amb una RPi3 (i es diu d'utilitzar Raspbian).
E $ pip install -e . Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Obtaining file:///home/pi/rpi-vision-master Collecting picamera==1.13.0 Downloading https://www.piwheels.org/simple/picamera/picamera-1.13-py3-none-any.whl (154 kB) |████████████████████████████████| 154 kB 818 kB/s Collecting Pillow==6.0.0 Downloading https://www.piwheels.org/simple/pillow/Pillow-6.0.0-cp37-cp37m-linux_armv7l.whl (1.2 MB) |████████████████████████████████| 1.2 MB 805 kB/s Installing collected packages: picamera, Pillow, rpi-vision Running setup.py develop for rpi-vision Successfully installed Pillow-6.0.0 picamera-1.13 rpi-vision
Instal·lació (TBD)
En el portàtil:
$ cd rpi-vision-master/ $ pip install virtualenv $ virtualenv -p $(which python3) .venv $ source .venv/bin/activate $ PS1="E $ " $ sudo apt install sshpass (ho necessito d'aquí a un minut per connectar-me per SSH a la RPi) E $ pip install -e .
Ara sí que funciona sense problemes, perquè estic en el portàtil.
fitxer .env/my-inventory.ini
tee -a .env/my-inventory.ini <<EOF [rpi_vision] 192.168.1.60 [rpi_vision:vars] ansible_connection=ssh ansible_user=pi ansible_user=raspberry ansible_python=/usr/bin/python3 EOF
fitxer .env/my-vars.json:
tee -a .env/my-vars.json <<EOF { "RPI_HOSTNAME": "192.168.1.60", "VERSION": "release-v1.0.0" } EOF
fatal: [192.168.1.60]: FAILED! => {"msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"} sudo apt install sshpass
Finalment ara sí: Recordem, ho executo des del portàtil (entorn virtual), i es desplega sobre la rpi.
E $ make rpi-install changed: [192.168.1.60] TASK [Clone rpi-vision] *************************************************************************************************************** changed: [192.168.1.60] TASK [Clone rpi-fbcp] ***************************************************************************************************************** changed: [192.168.1.60] TASK [Clone TFT drivers] ************************************************************************************************************** changed: [192.168.1.60] TASK [Copy TFT driver install script to /usr/local/bin] ******************************************************************************* changed: [192.168.1.60] TASK [file] *************************************************************************************************************************** changed: [192.168.1.60] TASK [Build fbcp (frame buffer copy for Raspberry Pi)] ******************************************************************************** changed: [192.168.1.60] TASK [Copy fbcp to /usr/local/bin] **************************************************************************************************** changed: [192.168.1.60] TASK [Install TFT drivers] ************************************************************************************************************ changed: [192.168.1.60] TASK [Waiting for TFT driver installation to finish (Pi Rebooting)] ******************************************************************* ok: [192.168.1.60] TASK [Create .tft_screen_installed] *************************************************************************************************** changed: [192.168.1.60] TASK [Create virtual environment] ***************************************************************************************************** fatal: [192.168.1.60]: FAILED! => {"changed": true, "cmd": "virtualenv -p $(which python3.6) .venv", "delta": "0:00:01.775208", "end": "2020-02-11 11:11:44.427335", "msg": "non-zero return code", "rc": 1, "start": "2020-02-11 11:11:42.652127", "stderr": "", "stderr_lines": [], "stdout": "RuntimeError: failed to find interpreter for Builtin discover of python_spec='.venv'", "stdout_lines": ["RuntimeError: failed to find interpreter for Builtin discover of python_spec='.venv'"]}
El problema està en què en la RPi tinc la versió de Python:
$ which python3.6 $ which python3.7 /usr/bin/python3.7
protesta perquè no tinc la 3.6. En algun lloc es fa referència a la v3.6, i hauria de posar 3.7.
Ara ho veig, en el protàtil tinc la 3.6, i espera que hi hagi la mateixa versió en el portàtil i en la RPi:
$ python3 --version Python 3.6.9
L'error en la RPi està en crear l'entorn virtual:
$ virtualenv -p $(which python3.6) .venv RuntimeError: failed to query /usr/bin/python3.6 with code 1 err: 'Traceback (most recent call last):\n File "/usr/local/lib/python3.7/dist-packages/virtualenv/discovery/py_info.py", line 16, in <module>\n from distutils.command.install import SCHEME_KEYS\nModuleNotFoundError: No module named \'distutils.command\'\n'
Problemes amb versions de Python (TBD)
$ ls /usr/bin/python* /usr/bin/python /usr/bin/python3 /usr/bin/python3.6m /usr/bin/python3.7m /usr/bin/python3m-config /usr/bin/python2 /usr/bin/python3.6 /usr/bin/python3.6m-config /usr/bin/python3-config /usr/bin/pythontex /usr/bin/python2.7 /usr/bin/python3.6-config /usr/bin/python3.7 /usr/bin/python3m /usr/bin/pythontex3 --- $ python --version Python 2.7.15+ joan@joanHP:~/rpi-vision-master$ python3 --version Python 3.6.9 --- alias python3='/usr/bin/python3.7' $ python3 --version Python 3.7.5 i aquesta comanda també la poso al fitxer .bashrc alias python3='/usr/bin/python3.7' i el tema és que hi ha un enllaç simbòlic: $ ls -la /usr/bin/python3 lrwxrwxrwx 1 root root 9 d’oct 15 17:47 /usr/bin/python3 -> python3.6 ha d'apuntar a python3.7 ln -sf /usr/bin/python3.7 /usr/bin/python3 i ara ja tenim: $ ls -la /usr/bin/python3 lrwxrwxrwx 1 root root 18 de fe 11 13:14 /usr/bin/python3 -> /usr/bin/python3.7
Però sobretot, el que importa és la versió que tinc de python3-env:
$ sudo apt-get remove python3.6-venv $ sudo apt-get install python3.7-venv
creat per Joan Quintana Compte, febrer 2020