yoloserv/sbin/ctl.sh

270 lines
9.3 KiB
Bash
Executable File

#!/bin/bash
#
# DISPENSION CONFIDENTIAL
#
# [2020] - [2021] Dispension Industries Limited.
# Portions Copyright © 2014-2020 Atlantean Technical Solutions Limited
# with full licensing rights granted to Dispension & Successors.
#
# All Rights Reserved.
#
# NOTICE: All information contained herein is, and remains
# the property of Dispension Industries Limited.
# The intellectual and technical concepts contained
# herein are proprietary to Dispension Industries Limited
# and its suppliers and may be covered by U.S. and Foreign Patents,
# patents in process, and are protected by trade secret or copyright law.
# Dissemination of this information or reproduction of this material
# is strictly forbidden unless prior written permission is obtained
# from Dispension Industries Limited.
#
# OK just so were clear, this is a pretty complicated lib. This is due
# to all the various tools we are obliged to use due to various tech
# we've been asked to implement, some of which is proprietary, most
# of which is experimental and ALL of which is huge.
# See doc for more details.
#
# sudo pip3 install openvino opencv-python yolov5 yolov8
. awesome_venv/bin/activate
HERE=$PWD
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd $DIR/..
# Read in UKDI and determine basic PATHs etc
function f_read_ukdi(){
cat /etc/ukdi.json |\
tr -d '"'| sed 's/,$//'|\
awk '{ if (NF>1){print "export UKDI_"$1"=\""$2"\"" } }' |\
sed 's/://' > var/gen.ukdi
chmod +x var/gen.ukdi
. var/gen.ukdi
export ZZZ=5
export UKDIHOST=`echo $UKDI_ukdi|tr '/:,' ' '| awk '{print $2}'`
export UKDIPORT=`echo $UKDI_ukdi|tr '/:,' ' '| awk '{print $3}'`
export YOLOHOST=`echo $UKDI_yolo|tr '/:,' ' '| awk '{print $2}'`
export YOLOPORT=`echo $UKDI_yolo|tr '/:,' ' '| awk '{print $3}'`
export CORE=$PWD/../core
export UKDI=$PWD/../ukdi
export YOLO=$PWD/../yoloserv
cat<<EOF
UKDIHOST=$UKDIHOST
UKDIPORT=$UKDIPORT
YOLOHOST=$YOLOHOST
YOLOPORT=$YOLOPORT
CORE=$CORE
UKDI=$UKDI
EOF
}
f_read_ukdi
ZZZ=5
mkdir -p $UKDI_yolo_indir
mkdir -p $UKDI_yolo_outdir
# Determina all the possible libs based on whats in UKDI_yolo_devices
PYP_OPENVINO="modules/para_models/gen6-balanced/venv_balanced/lib/python3.10/site-packages"
LIB_OPENVINO="modules/openvino/inference_engine/lib/intel64/:\
modules/openvino/inference_engine:\
modules/openvino/python3.10/dist-packages/openvino/libs:\
modules/openvino/python3.10/dist-packages/openvino/inference_engine"
PYP_PARAVISION="modules/para_models/gen6-balanced/venv_balanced/lib/python3.10/site-packages"
PYP_DEEPFACE="modules"
PYP_YOLOV5="modules/yolov5-face_Jan1"
LIB_SEEK="modules/seek/Seekware_SDK_3.6.0.0/lib/x86_64-linux-gnu/"
# WHich libs are loaded depends on the YOLO device list
LLP="."
PYP="."
echo "UKDI_yolo_devices = $UKDI_yolo_devices"
for i in `echo $UKDI_yolo_devices| tr ',' ' '`
do
case $i in
"paravision") LLP="$LLP:$LIB_OPENVINO"
PYP="$PYP:$PYP_OPENVINO:$PYP_PARAVISION"
;;
"yolov5") LLP="$LLP:$LIB_OPENVINO"
PYP="$PYP:$PYP_YOLOV5"
;;
"deepface") LLP="$LLP:$LIB_DEEPFACE"
PYP="$PYP:$PYP_DEEPFACE"
;;
"seek") LLP="$LLP:$LIB_SEEK"
PYP="$PYP:src"
;;
"face_recognition") LLP="$LLP:$LIB_DEEPFACE"
PYP="$PYP:$PYP_DEEPFACE"
;;
"regula") ;;
"traffic") ;;
"camera") ;;
"camera_stream") ;;
*) echo "yoloserv does not implement backend $i. Edit /etc/ukdi.json::yolo_devices and try again."
exit 1
esac
done
echo "PYTHONPATH = $PYP"
export LD_LIBRARY_PATH="$LLP"
export PYTHONPATH="$PYP"
export WEIGHTS="$DIR/../modules/yolov5-face_Jan1/runs/train/exp/weights/yolov5m6_face.pt"
# # # #### ##### ## # #
# ## # # # # # # #
# # # # #### # # # # #
# # # # # # ###### # #
# # ## # # # # # # #
# # # #### # # # ###### ######
# Install all the components.
# There are many of them and they are all different.
# Some are proprietary, so check your licensing (ask Matt)
function f_apt(){
apt update
apt upgrade
apt install libopencv-dev python3-opencv
pip3 install --upgrade pip
pip3 install yolov5
pip3 install yolov8
pip3 install deepface
apt install libopencv-dev python3-opencv
pip3 install deepface
#REGULA..
apt install pcscd libccid
wget -O downloads/regula.deb https://downloads.regulaforensics.com/repo/ubuntu/pool/stable/r/regula-reader/regula-reader_6.7.198393.16246_amd64.deb
wget -O downloads/drivers.deb https://downloads.regulaforensics.com/repo/ubuntu/pool/stable/r/regula-drivers/regula-drivers_2.1.1.12_amd64.deb
dpkg --install downloads/regula.deb
sudo pip3 install openvino
# bypass paravision
# . /usr/local/lib/python3.10/dist-packages/
# ROOTURL="http://824f668f-5c6e-4ffe-8b5b-edb4d0301982:985c5412-5e0d-4d66-8d28-ed32dbb900a3@paravision.mycloudrepo.io"
# pip3 install cmake --upgrade
# pip3 install --no-cache-dir\
# --extra-index-url $ROOTURL/repositories/python-sdk\
# --extra-index-url $ROOTURL/repositories/python-recognition\
# "paravision-recognition" "paravision-models-gen5-balanced-openvino-2022-3" "openvino==2022.3"\
# --trusted-host paravision.mycloudrepo.io
# . /usr/local/lib/python3.10/dist-packages/
# ROOTURL="http://2a76e3b5-733a-4c93-98fb-339927b0f90c:453a6a2d-2935-430b-a22f-9b2880ca381@paravision.mycloudrepo.io"
# pip3 install cmake --upgrade
# pip3 install --no-cache-dir\
# --extra-index-url $ROOTURL/repositories/python-sdk\
# --extra-index-url $ROOTURL/repositories/python-recognition\
# "paravision-recognition" "paravision-models-gen6-balanced-openvino-2022-3" "openvino==2022.3"\
# --trusted-host paravision.mycloudrepo.io
wget -O downloads/facerec.zip https://github.com/ageitgey/face_recognition/archive/refs/heads/master.zip
cd downloads
unzip facerec.zip
cd $HERE
}
function f_apt_intox(){
make -f sbin/Makefile
}
#### #### # # ##### ##### #### #
# # # # ## # # # # # # #
# # # # # # # # # # # #
# # # # # # # ##### # # #
# # # # # ## # # # # # #
#### #### # # # # # #### ######
function f_test(){
mkdir -p $UKDI_yolo_indir
cp testimg/* $UKDI_yolo_indir
case $1 in
"1")
echo "five friends"
wget -q -O foo "http://localhost:$YOLOPORT/svc_init" && cat foo && echo
wget -q -O foo "http://localhost:$YOLOPORT/svc_load_img/ff/fivepeople.jpg" && cat foo && echo
wget -q -O foo "http://localhost:$YOLOPORT/svc_faces/ff" && cat foo && echo
wget -q -O foo "http://localhost:$YOLOPORT/svc_ideal/ff/ff_rect/ff_crop" && cat foo && echo
;;
"2")
echo "iron maiden"
wget -q -O foo "http://localhost:$YOLOPORT/svc_init" && cat foo && echo
wget -q -O foo "http://localhost:$YOLOPORT/svc_load_img/im/ironmaiden.jpg" && cat foo && echo
wget -q -O foo "http://localhost:$YOLOPORT/svc_faces/im" && cat foo && echo
wget -q -O foo "http://localhost:$YOLOPORT/svc_load_img/bd/brucedickinson.jpeg" && cat foo && echo
wget -q -O foo "http://localhost:$YOLOPORT/svc_ideal/im/im_rect/im_crop" && cat foo && echo
echo "find bruce dickinson"
wget -q -O foo "http://localhost:$YOLOPORT/svc_company/im/bd" && cat foo && echo
;;
"3")
echo "footballers"
wget -q -O foo "http://localhost:$YOLOPORT/svc_load_img/r1/ronaldo.jpg" && cat foo && echo
wget -q -O foo "http://localhost:$YOLOPORT/svc_load_imgs/m1/messi1.jpg/m2/messi2.jpg" && cat foo && echo
echo "getting faces from messi1, messi2 and ronaldo - should find one each"
wget -q -O foo "http://localhost:$YOLOPORT/svc_faces/m1" && cat foo && echo
wget -q -O foo "http://localhost:$YOLOPORT/svc_faces/m2" && cat foo && echo
wget -q -O foo "http://localhost:$YOLOPORT/svc_faces/r1" && cat foo && echo
echo "comparing messi1 vs messi2, then messi1 vs ronaldo, then messi2 vs ronaldo"
wget -q -O foo "http://localhost:$YOLOPORT/svc_compare/m1/m2" && cat foo && echo
wget -q -O foo "http://localhost:$YOLOPORT/svc_compare/m1/r1" && cat foo && echo
wget -q -O foo "http://localhost:$YOLOPORT/svc_compare/m2/r1" && cat foo && echo
;;
"4")
echo "all in one service test"
wget -q -O foo "http://localhost:$YOLOPORT/svc_facematch/m1/messi1.jpg/m2/messi2.jpg" && cat foo && echo
;;
esac
}
function f_start(){
echo PPPPPPPPPPPp
echo $PYTHONPATH
echo $$ > var/yoloserv.pid
while [ -e var/yoloserv.pid ]
do
python3 src/yoloserv.py $YOLOPORT $UKDI_yolo_indir $UKDI_yolo_outdir $WEIGHTS
sleep $ZZZ
done
}
function f_stop(){
rm var/yoloserv.pid
wget http://localhost:$YOLOPORT/shutdown
}
echo "Running $0 with option $1 at $DIR"
case $1 in
"apt") f_apt
;;
"start") f_start
;;
"restart") f_stop
f_start
;;
"reload") f_reload
;;
"stop") f_stop
;;
"test") f_test $2
;;
*) echo "Error. $1 is not a $0 command."
;;
esac
cd $HERE