From e86a146ea3e8e8485dd7acec49afe2549d7e2875 Mon Sep 17 00:00:00 2001 From: khemendra kumar Date: Tue, 1 Dec 2020 21:13:26 +0530 Subject: [PATCH] ROBO usecase: Obj Detection service base framework Signed-off-by: khemendra kumar Change-Id: Id1ecb8d32ae2992b881e70cba635baa39ed1763b --- .../ROBO/aPaaS/Obj_Detection_service/.gitignore | 3 + .../ROBO/aPaaS/Obj_Detection_service/config.py | 40 +++++++ .../ROBO/aPaaS/Obj_Detection_service/config.pyc | Bin 0 -> 971 bytes .../aPaaS/Obj_Detection_service/configs/start.sh | 75 ++++++++++++++ .../Obj_Detection_service/detection/__init__.py | 0 .../Obj_Detection_service/detection/__init__.pyc | Bin 0 -> 193 bytes .../detection/obj_detection_service.py | 115 +++++++++++++++++++++ .../detection/obj_detection_service.pyc | Bin 0 -> 10293 bytes .../aPaaS/Obj_Detection_service/requirements.txt | 21 ++++ .../ROBO/aPaaS/Obj_Detection_service/run.py | 25 +++++ example-apps/ROBO/aPaaS/README.md | 6 ++ 11 files changed, 285 insertions(+) create mode 100644 example-apps/ROBO/aPaaS/Obj_Detection_service/.gitignore create mode 100644 example-apps/ROBO/aPaaS/Obj_Detection_service/config.py create mode 100644 example-apps/ROBO/aPaaS/Obj_Detection_service/config.pyc create mode 100644 example-apps/ROBO/aPaaS/Obj_Detection_service/configs/start.sh create mode 100644 example-apps/ROBO/aPaaS/Obj_Detection_service/detection/__init__.py create mode 100644 example-apps/ROBO/aPaaS/Obj_Detection_service/detection/__init__.pyc create mode 100644 example-apps/ROBO/aPaaS/Obj_Detection_service/detection/obj_detection_service.py create mode 100644 example-apps/ROBO/aPaaS/Obj_Detection_service/detection/obj_detection_service.pyc create mode 100644 example-apps/ROBO/aPaaS/Obj_Detection_service/requirements.txt create mode 100644 example-apps/ROBO/aPaaS/Obj_Detection_service/run.py create mode 100644 example-apps/ROBO/aPaaS/README.md diff --git a/example-apps/ROBO/aPaaS/Obj_Detection_service/.gitignore b/example-apps/ROBO/aPaaS/Obj_Detection_service/.gitignore new file mode 100644 index 0000000..329ec83 --- /dev/null +++ b/example-apps/ROBO/aPaaS/Obj_Detection_service/.gitignore @@ -0,0 +1,3 @@ +venv +__pycache__ +.idea diff --git a/example-apps/ROBO/aPaaS/Obj_Detection_service/config.py b/example-apps/ROBO/aPaaS/Obj_Detection_service/config.py new file mode 100644 index 0000000..31e91be --- /dev/null +++ b/example-apps/ROBO/aPaaS/Obj_Detection_service/config.py @@ -0,0 +1,40 @@ +# +# Copyright 2020 Huawei Technologies Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os + +# [Server Configurations] +server_port = 9998 +server_address = os.environ.get('LISTEN_IP') + +# [SSL Configurations] +ssl_enabled = False +ssl_protocol = "TLSv1.2" +ssl_ciphers = ["TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"] +ssl_certfilepath = "/usr/app/ssl/server_tls.crt" +ssl_keyfilepath = "/usr/app/ssl/server_tls.key" +ssl_cacertpath = "/usr/app/ssl/ca.crt" +ssl_server_name = os.environ.get('SERVER_NAME', "ealtedge") + +# [Service Configurations] +api_gateway = os.environ.get("API_GATEWAY", "apigw.mep.org") +obj_det = os.environ.get("OBJ_DETECTION", "objdetection") + +# [Constants] +recognition_url = "http://" + api_gateway + "/" + obj_det diff --git a/example-apps/ROBO/aPaaS/Obj_Detection_service/config.pyc b/example-apps/ROBO/aPaaS/Obj_Detection_service/config.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6df092dca0939106122a376180a41051a703b54c GIT binary patch literal 971 zcmaJ<&2AGh5T5)rZPO%eL6wj=BYGhwp+FA^u}zmIh%`|)B4VY=a@Njf)6IHiyRCBO z$ekD9!FUKB0LGg%DjZ^aXJ@{d`DXl6_+2gk`1O+puo^}Df519dO0BgYa zGqCyqJOF-}f#}VFcl-$ZiT>cYjB3xZzg@H&&A0WJI2(E!t>I_ywoz}IXG@*Bt@E}^ z2cAPmonf0gu16cqQ+mv;~We;GxKzPQODh zoS{2%zUnGESsI0R^|?svQiaAMy|YjB+#R~DVW)R#Du~GOj0+hHV2l?+CrI0 z6pNIZsj=lPh=;Jova&Xi+0ZP^z6+7uMoK28fI9Aeox18UVe@5EcmyC=83@7kJB> zus&lR(JCOl@r<6|pD4BcM1dfIOeRrSPZ!y(y_-vZ6N~qUSWQ1cQ7M%2r9vrZXC;%R J+)?2u_ZP$n{Hp)} literal 0 HcmV?d00001 diff --git a/example-apps/ROBO/aPaaS/Obj_Detection_service/configs/start.sh b/example-apps/ROBO/aPaaS/Obj_Detection_service/configs/start.sh new file mode 100644 index 0000000..ec14d8d --- /dev/null +++ b/example-apps/ROBO/aPaaS/Obj_Detection_service/configs/start.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# Copyright 2020 Huawei Technologies Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Validates if ip is valid +validate_ip() +{ + + +} + +validate_name() { + +} + +# validates whether file exist +validate_file_exists() { + +} + +validate_ip "$LISTEN_IP" +valid_listen_ip="$?" +if [ ! "$valid_listen_ip" -eq "0" ]; then + echo "invalid ip address for listen ip" + exit 1 +fi + +if [ ! -z "$SERVER_NAME" ]; then + validate_name "$SERVER_NAME" + valid_name="$?" + if [ ! "$valid_name" -eq "0" ]; then + echo "invalid ssl server name" + exit 1 + fi +fi + +# ssl parameters validation +validate_file_exists "/usr/app/ssl/server_tls.crt" +valid_ssl_server_cert="$?" +if [ ! "$valid_ssl_server_cert" -eq "0" ]; then + echo "invalid ssl server certificate" + exit 1 +fi + +# ssl parameters validation +validate_file_exists "/usr/app/ssl/server_tls.key" +valid_ssl_server_key="$?" +if [ ! "$valid_ssl_server_key" -eq "0" ]; then + echo "invalid ssl server key" + exit 1 +fi + +# ssl parameters validation +validate_file_exists "/usr/app/ssl/ca.crt" +valid_ssl_ca_crt="$?" +if [ ! "$valid_ssl_ca_crt" -eq "0" ]; then + echo "invalid ssl ca cert" + exit 1 +fi + +echo "Running Monitoring Service" +umask 0027 +cd /usr/app || exit +python run.py diff --git a/example-apps/ROBO/aPaaS/Obj_Detection_service/detection/__init__.py b/example-apps/ROBO/aPaaS/Obj_Detection_service/detection/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/example-apps/ROBO/aPaaS/Obj_Detection_service/detection/__init__.pyc b/example-apps/ROBO/aPaaS/Obj_Detection_service/detection/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4a779cf6b02eac2a15d92dc5891df77092773bc8 GIT binary patch literal 193 zcmZ9Gy9&ZU5JgwC5W#;)nMMb}Qp8uvXh;gnVY3-<^V+aG3i+6Pr9a>Xv~l2`3#Yj= zeJ>ZmFrX6OoA^HXxS2;GL>7+b8hVI7xY9d#n1;X_!yAZuyc=7=v9eOP2IA<9rv%cd z4z`dIOI@#I*Ex`hlo>dy;FgzoAtuGzwCKpbv?3^e1`u_t8FAh9Joj_E#uU$*_Ty9R FBR-hGFu4E# literal 0 HcmV?d00001 diff --git a/example-apps/ROBO/aPaaS/Obj_Detection_service/detection/obj_detection_service.py b/example-apps/ROBO/aPaaS/Obj_Detection_service/detection/obj_detection_service.py new file mode 100644 index 0000000..b087e95 --- /dev/null +++ b/example-apps/ROBO/aPaaS/Obj_Detection_service/detection/obj_detection_service.py @@ -0,0 +1,115 @@ +# +# Copyright 2020 Huawei Technologies Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import config +from flask_sslify import SSLify +from flask import Flask, Response +from flask_cors import CORS + + +class model_info(): + def __init__(self, model_name): + self.model = 'model_info/MobileNetSSD_deploy.caffemodel' + self.model_name = model_name + self.prototxt = 'model_info/MobileNetSSD_deploy.prototxt' + self.confidenceLevel = 80 + + def get_model(self): + return self.model + + def get_prototxt(self): + return self.prototxt + + def get_model_name(self): + return self.model_name + + def set_confidence_level(self, confidenceLevel): + self.confidenceLevel = confidenceLevel + + def get_confidence_level(self): + return self.confidenceLevel + + def update_model(self, model, prototxt, model_name): + self.prototxt = prototxt + self.model = model + self.model_name = model_name + + +# Labels of Network. +classNames = {0: 'background', + 1: 'aeroplane', 2: 'bicycle', 3: 'bird', 4: 'boat', + 5: 'bottle', 6: 'bus', 7: 'car', 8: 'cat', 9: 'chair', + 10: 'cow', 11: 'diningtable', 12: 'dog', 13: 'horse', + 14: 'motorbike', 15: 'person', 16: 'pottedplant', + 17: 'sheep', 18: 'sofa', 19: 'train', 20: 'tvmonitor'} + +app = Flask(__name__) +CORS(app) +sslify = SSLify(app) +app.config['JSON_AS_ASCII'] = False +app.config['UPLOAD_PATH'] = '/usr/app/images/' +app.config['supports_credentials'] = True +app.config['CORS_SUPPORTS_CREDENTIALS'] = True +app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 +ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg']) +count = 0 +listOfMsgs = [] + + +def allowed_file(filename): + return '.' in filename and filename.rsplit('.', 1)[1].lower()\ + in ALLOWED_EXTENSIONS + + +@app.route('/mep/v1/obj_detection/uploadModel', methods=['POST']) +def uploadModel(): + """ + upload model + :return: html file + """ + + return Response("success") + + +@app.route('/mep/v1/obj_detection/confidencelevel', methods=['POST']) +def setConfidenceLevel(): + """ + Trigger the video_feed() function on opening "0.0.0.0:5000/video_feed" URL + :return: + """ + + return Response("success") + + +@app.route('/mep/v1/obj_detection/detect', methods=['GET']) +def Obj_Detection(): + """ + Trigger the Obj detection on input frame/image + Input: frame/image + :return: imposed frame, count, Obj type, time taken by detection + """ + return Response("success") + + +def start_server(handler): + app.logger.addHandler(handler) + if config.ssl_enabled: + context = (config.ssl_certfilepath, config.ssl_keyfilepath) + app.run(host=config.server_address, debug=True, ssl_context=context, + threaded=True, port=config.server_port) + else: + app.run(host=config.server_address, debug=True, threaded=True, + port=config.server_port) diff --git a/example-apps/ROBO/aPaaS/Obj_Detection_service/detection/obj_detection_service.pyc b/example-apps/ROBO/aPaaS/Obj_Detection_service/detection/obj_detection_service.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4f69f837a90d6e2bc12151fe5a12305e4b0fb97c GIT binary patch literal 10293 zcmds7-ESP%bw9HtmmlJXD2k$}4{IdX$-1Vrl4HAx;@YA~N@7Bh#4HUt>o|kq&fVpZ zvpcJqSxHREHjUDvPXSu=C3)yWk^iDV(1!wfZ_)R>_PGW6(jxu+&fQ&7QVcsy4H4z; z-nr-Ab3e|9rT6TIkgW zq&nEE4@q^XS1(Gn*sBjqby({KiASV4D%DYOxW<6QW70e&)lUhZ4Sp$AW~{@wg#j8IPM1-jesKvtmw(IVaD+%Q-RA zV&+(P%xJe(JuhaS^`DJN9o}lD?a;kbo!avrEtAnpf_<@8UN_a;a4n{fQqB0a)z1Bnc=y`;t9>VKA zgk?oo>CJGrhX799)3x59T2)Hlg`P#f!QXnxK{YR;s8rUX`hIDMFpIl!knQEesHNsn z$7H$IceA7gw0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