yoloserv/sbin/ctl.sh

230 lines
6.5 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
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 CORE=$PWD/../core
export UKDI=$PWD/../ukdi
export YOLO=$PWD/../yoloserv
cat<<EOF
UKDIHOST=$UKDIHOST
UKDIPORT=$UKDIPORT
CORE=$CORE
UKDI=$UKDI
EOF
}
f_read_ukdi
PORT=8099
ZZZ=5
# Determina all the possible libs based on whats in UKDI_yolo_devices
PYP_OPENVINO="modules"
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"
PYP_DEEPFACE="modules"
PYP_YOLOV5="modules/yolov5-face_Jan1"
# 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
"para_facematch") 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"
;;
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
case $1 in
"updates") apt update
apt upgrade
apt install libopencv-dev python3-opencv
python3 -m pip install --upgrade pip
;;
"regula") f_apt_regula
;;
"yolov5") f_apt_yolov5
;;
"yolov8") f_apt_yolov8
;;
"para_facematch") f_apt_openvino
f_apt_paravision
;;
"openvino") f_apt_openvino
;;
"deepface") pip3 install deepface
;;
"facerec") f_apt_facerec
;;
"intox") f_apt_yolov5
f_apt_intox
;;
*) echo "Error. Second parameter must be updates|regula|yolov5|paravision|freeface|paraface|palm|intox"
;;
esac
}
function f_apt_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
. /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
# Open source Face_Recognition
pip3 install deepface
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(){
wget http://localhost:$PORT/process/
}
function f_start(){
echo PPPPPPPPPPPp
echo $PYTHONPATH
echo $$ > var/yoloserv.pid
while [ -e var/yoloserv.pid ]
do
python3 src/yoloserv.py $PORT $UKDI_yolo_indir $UKDI_yolo_outdir $WEIGHTS
sleep $ZZZ
done
}
function f_stop(){
rm var/yoloserv.pid
wget http://localhost:$PORT/shutdown
}
echo "Running $0 with option $1 at $DIR"
case $1 in
"apt") f_apt $2
;;
"start") f_start
;;
"restart") f_stop
f_start
;;
"reload") f_reload
;;
"stop") f_stop
;;
*) echo "Error. $1 is not a $0 command."
;;
esac
cd $HERE