Classificació de gestos emprant la placa IoT-02

De binefa.com
Salta a la navegació Salta a la cerca

Instal·lació d'eines d'aprenentatge automàtic (machine learning) i tensorflow emprant Python

Si no teniu instal·lat Anaconda, feu-hi la instal·lació.

En cas de tenir actiu conda, desactiveu-ho:

conda deactivate

Feu un entorn per a treballar amb tensorflow:

conda create -n ml tensorflow
conda activate ml
pip install everywhereml

per a sortir de l'entorn conda:

conda deactivate

Captació de les dades

Connecteu la placa MPU-6050 a la Placa IoT-02. Pugeu el codi IoT-02_mpu6050_dataForwarder.ino

Canvieu el port de comunicacions (a Linux /dev/ttyUSB0) d'aquest tros del codi collector02.py per adaptar-lo al vostre port sèrie (per exemple COM3 a Windows):

   imu_collector = SerialCollector(
       port='/dev/ttyUSB0', 
       baud=115200, 
       start_of_frame='IMU:', 
       feature_names=['ax', 'ay', 'az', 'gx', 'gy', 'gz']
   )
   imu_dataset = imu_collector.collect_many_classes(
       dataset_name='ContinuousMotion', 
       duration=30
   )

Activeu l'entorn 'ml' (machine learning / aprenentatge automàtic) del conda:

conda activate ml

Us ha de sortir (ml) a l'esquerra del terminal. Executeu el programa collector02.py (amb la modificació del nom del port de comunicacions al vostre sistema operatiu. Per defecte hi ha /dev/ttyUSB0):

(ml) $ python collector02.py 
This is an interactive data capturing procedure.
Keep in mind that as soon as you will enter a class name, the capturing will start, so be ready!
Which class are you going to capture? (leave empty to exit) quiet
31it [00:30,  1.01it/s]                                                                                 
Captured 1805 samples
Is this class ok? (y|n) y
Which class are you going to capture? (leave empty to exit) amunt-avall
31it [00:30,  1.03it/s]                                                                                 
Captured 1771 samples
Is this class ok? (y|n) y
Which class are you going to capture? (leave empty to exit) esquerra-dreta
31it [00:30,  1.03it/s]                                                                                 
Captured 1777 samples
Is this class ok? (y|n) y
Which class are you going to capture? (leave empty to exit) cercle
31it [00:30,  1.02it/s]                                                                                 
Captured 1794 samples
Is this class ok? (y|n) y
Which class are you going to capture? (leave empty to exit) 
Are you sure you want to exit? (y|n) y

i genera l'arxiu imu.csv (exemple d'arxiu imu.csv generat).

Principi de l'arxiu imu.csv:

(ml) $ head imu.csv 
ax,ay,az,gx,gy,gz,target,target_name
0.1,0.08,9.71,-0.01,-0.05,-0.07,0.0,quiet
0.14,-0.07,9.64,-0.0,-0.06,-0.06,0.0,quiet
0.12,-0.1,9.6,-0.02,-0.05,-0.06,0.0,quiet
0.11,-0.04,9.65,-0.02,-0.05,-0.06,0.0,quiet
0.09,0.0,9.7,-0.01,-0.05,-0.06,0.0,quiet
0.12,-0.02,9.66,-0.02,-0.05,-0.05,0.0,quiet 
0.14,-0.02,9.69,-0.01,-0.06,-0.06,0.0,quiet
0.1,-0.02,9.64,-0.01,-0.06,-0.06,0.0,quiet
0.09,-0.04,9.64,-0.02,-0.05,-0.05,0.0,quiet

Final de l'arxiu imu.csv:

(ml) $ tail imu.csv
0.05,1.05,9.84,0.02,-0.24,0.66,3.0,cercle
0.01,1.3,10.63,0.08,-0.21,0.7,3.0,cercle
-0.06,1.5,10.86,0.05,0.03,0.67,3.0,cercle
-0.08,1.65,10.44,0.06,0.29,0.61,3.0,cercle
0.05,1.58,9.56,-0.02,0.45,0.56,3.0,cercle
0.1,0.84,8.74,-0.07,0.36,0.46,3.0,cercle
0.49,0.77,8.32,-0.01,0.05,0.53,3.0,cercle
-0.1,0.92,9.93,0.09,-0.26,0.43,3.0,cercle
-0.03,1.17,10.75,0.26,-0.29,0.46,3.0,cercle
0.13,1.34,10.8,0.27,-0.09,0.38,3.0,cercle

Si l'arxiu imu.csv ja existeix es visualitza el resum de les dades enregistrades al tornar a executar collector02.py:

(ml) $ python collector02.py 
                ax           ay           az           gx           gy           gz       target
count  7147.000000  7147.000000  7147.000000  7147.000000  7147.000000  7147.000000  7147.000000
mean      0.126964    -0.001574     9.631492    -0.016372    -0.059793    -0.079418     1.498111
std       1.517042     0.885516     1.053995     0.248000     0.157644     0.412540     1.121298
min      -7.180000    -2.770000     4.330000    -1.230000    -0.990000    -1.490000     0.000000
25%      -0.590000    -0.640000     9.480000    -0.100000    -0.110000    -0.250000     0.000000
50%       0.140000     0.040000     9.650000    -0.020000    -0.050000    -0.120000     1.000000
75%       0.480000     0.490000     9.810000     0.060000    -0.010000     0.120000     3.000000
max       6.070000     3.390000    14.180000     1.190000     0.690000     1.240000     3.000000

Instal·lació de l'edge-impulse-data-forwarder

Aquesta eina serveix per a publicar dades des de la placa fins al servidor d'Edge Impulse

curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
npm install -g edge-impulse-cli --force

Un cop instal·lat, es pot executar des del terminal:

edge-impulse-data-forwarder

Bibliografia

Gesture Classification by Eloquent Arduino

Gesture Classification with Esp32 and TinyML by João Vitor Yukio Bordin Yamashita