Skip to content

Instantly share code, notes, and snippets.

@tomoto
Last active January 2, 2019 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomoto/85d88a5b2b91fc581ee3675e18e379ca to your computer and use it in GitHub Desktop.
Save tomoto/85d88a5b2b91fc581ee3675e18e379ca to your computer and use it in GitHub Desktop.
NCS2 experiment on Raspberry Pi
#!/usr/bin/perl
$| = 1;
my($data);
sub emit_if_complete {
my($d) = @_;
if ($d->{'g'} && $d->{'e'}) {
print qq/{"g":"$d->{'g'}","e":"$d->{'e'}"}\n/;
}
}
while (<>) {
if (/^\[0,1\]/) {
# reset
$data = {};
}
if (!$data->{'g'} && /Predicted gender, age = ([FM]),(\d+)/) {
$data->{'g'} = $1;
&emit_if_complete($data)
}
if (!$data->{'e'} && /Predicted emotion = (\w+)/) {
$data->{'e'} = $1;
&emit_if_complete($data);
}
}
device=MYRIAD
fpmode=FP16
bin/interactive_face_detection_demo \
-d ${device} -m intel_models/face-detection-retail-0004/${fpmode}/face-detection-retail-0004.xml \
-d_ag ${device} -m_ag intel_models/age-gender-recognition-retail-0013/${fpmode}/age-gender-recognition-retail-0013.xml \
-d_em ${device} -m_em intel_models/emotions-recognition-retail-0003/${fpmode}/emotions-recognition-retail-0003.xml \
-d_hp ${device} -m_hp intel_models/head-pose-estimation-adas-0001/${fpmode}/head-pose-estimation-adas-0001.xml \
$*
./face.sh -r $* | tee >(./extract_emotion_and_gender.pl | sudo ./show_emotion_and_gender.py)
./bin/object_detection_demo_ssd_async -d MYRIAD -m mobilenet-ssd/FP16/mobilenet-ssd.xml $*
model=$1
url_base=https://download.01.org/openvinotoolkit/2018_R4/open_model_zoo
out_base=intel_models
cmd="wget --no-check-certificate"
function get_files {
fpmode=$1
p=$model/$fpmode
mkdir -p $out_base/$p
$cmd $url_base/$p/$model.bin -O $out_base/$p/$model.bin
$cmd $url_base/$p/$model.xml -O $out_base/$p/$model.xml
}
get_files FP16
# get_files FP32
#!/usr/bin/env python
import unicornhat as unicorn
import time
import json
import sys
import os
unicorn.set_layout(unicorn.AUTO)
unicorn.rotation(270)
unicorn.brightness(0.4)
width,height=unicorn.get_shape()
faces = {
'neutral': [
"00000000",
"01000010",
"01000010",
"00000000",
"00000000",
"01111110",
"00000000",
"00000000",
],
'happy': [
"00000000",
"01000010",
"10100101",
"00000000",
"01000010",
"00100100",
"00011000",
"00000000",
],
'sad': [
"00000000",
"01100110",
"10000001",
"00000000",
"00011000",
"00100100",
"01000010",
"00000000",
],
'surprise': [
"01000010",
"10100101",
"01000010",
"00000000",
"00011000",
"00100100",
"00100100",
"00011000",
],
'anger': [
"00000000",
"11000011",
"00100100",
"00000000",
"00011000",
"00100100",
"01000010",
"00000000",
],
};
def show_matrix(matrix, r, g, b):
for y, row in enumerate(matrix):
for x, p in enumerate(row):
if p == '1':
unicorn.set_pixel(x, y, r, g, b)
else:
unicorn.set_pixel(x, y, 0, 0, 0)
unicorn.show()
def process(data):
f = faces[data['e']]
if data['g'] == 'F':
r, g, b = 255, 0, 200
else :
r, g, b = 0, 200, 255
show_matrix(f, r, g, b)
while True:
line = sys.stdin.readline()
data = json.loads(line)
process(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment