File: run-openvino-classifier.sh

package info (click to toggle)
berrynet 3.10.2-2
  • links: PTS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,572 kB
  • sloc: python: 6,286; javascript: 2,373; xml: 1,094; sh: 738; makefile: 33
file content (89 lines) | stat: -rw-r--r-- 2,418 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
#
# Copyright 2019 DT42
#
# This file is part of BerryNet.
#
# BerryNet is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BerryNet is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BerryNet.  If not, see <http://www.gnu.org/licenses/>.

# Example: Run OpenVINO classifier on general x86 notebook.
#
#   For more details, please refer to Medium XXX.

set -e

SCRIPT_NAME=$0
COMMAND=$1


usage() {
    echo -e "Usage:\n\t$ bash $SCRIPT_NAME start|stop"
    exit 1
}

kill_script() {
    local script_name=$1
    local process_id=$(ps aux | grep $script_name | grep Sl | awk '{print $2}')
    echo "Terminate $script_name (pid $process_id)"
    kill -9 $process_id
}

example_start() {
    # Run Freeboard
    echo -n "Run Dashboard..."
    pushd /usr/lib/berrynet/dashboard > /dev/null
    nodejs server.js >> /tmp/berrynet-example.log &
    popd > /dev/null
    echo "done"

    # Run OpenVINO classifier
    echo -n "Run OpenVINO classifier..."
    MODELPKG_DIRPATH="/usr/share/dlmodels/mobilenet-1.0-224-openvino-1"

    source /opt/intel/computer_vision_sdk_2018.5.445/bin/setupvars.sh
    sleep 1
    python3 /usr/lib/python3/dist-packages/berrynet/service/openvino_service.py \
        --model $MODELPKG_DIRPATH/mobilenet_v1_1.0_224_frozen.xml \
        --label $MODELPKG_DIRPATH/imagenet_slim_labels.txt \
        --service_name ovclassifier \
        --num_top_predictions 3 \
        --debug >> /tmp/berrynet-example.log 2>&1 &
    echo "done"

    # Run camera client
    echo -n "Run Camera..."
    sleep 1
    python3 /usr/lib/python3/dist-packages/berrynet/client/camera.py \
        --fps 5 >> /tmp/berrynet-example.log 2>&1 &
    echo "done"
}

example_stop() {
    kill_script "camera.py"
    kill_script "openvino_service.py"
    kill_script "server.js"
}

main() {
    local cmd=$1
    if [ "$cmd" == "start" ]; then
        example_start
    elif [ "$cmd" == "stop" ]; then
        example_stop
    else
        usage
    fi
}

main $COMMAND