ROBO usecase: Obj Detection service base framework 46/3946/1
authorkhemendra kumar <khemendra.kumar@huawei.com>
Tue, 1 Dec 2020 15:43:26 +0000 (21:13 +0530)
committerkhemendra kumar <khemendra.kumar@huawei.com>
Tue, 1 Dec 2020 15:43:26 +0000 (21:13 +0530)
Signed-off-by: khemendra kumar <khemendra.kumar@huawei.com>
Change-Id: Id1ecb8d32ae2992b881e70cba635baa39ed1763b

example-apps/ROBO/aPaaS/Obj_Detection_service/.gitignore [new file with mode: 0644]
example-apps/ROBO/aPaaS/Obj_Detection_service/config.py [new file with mode: 0644]
example-apps/ROBO/aPaaS/Obj_Detection_service/config.pyc [new file with mode: 0644]
example-apps/ROBO/aPaaS/Obj_Detection_service/configs/start.sh [new file with mode: 0644]
example-apps/ROBO/aPaaS/Obj_Detection_service/detection/__init__.py [new file with mode: 0644]
example-apps/ROBO/aPaaS/Obj_Detection_service/detection/__init__.pyc [new file with mode: 0644]
example-apps/ROBO/aPaaS/Obj_Detection_service/detection/obj_detection_service.py [new file with mode: 0644]
example-apps/ROBO/aPaaS/Obj_Detection_service/detection/obj_detection_service.pyc [new file with mode: 0644]
example-apps/ROBO/aPaaS/Obj_Detection_service/requirements.txt [new file with mode: 0644]
example-apps/ROBO/aPaaS/Obj_Detection_service/run.py [new file with mode: 0644]
example-apps/ROBO/aPaaS/README.md [new file with mode: 0644]

diff --git a/example-apps/ROBO/aPaaS/Obj_Detection_service/.gitignore b/example-apps/ROBO/aPaaS/Obj_Detection_service/.gitignore
new file mode 100644 (file)
index 0000000..329ec83
--- /dev/null
@@ -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 (file)
index 0000000..31e91be
--- /dev/null
@@ -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 (file)
index 0000000..6df092d
Binary files /dev/null and b/example-apps/ROBO/aPaaS/Obj_Detection_service/config.pyc differ
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 (file)
index 0000000..ec14d8d
--- /dev/null
@@ -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 (file)
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 (file)
index 0000000..4a779cf
Binary files /dev/null and b/example-apps/ROBO/aPaaS/Obj_Detection_service/detection/__init__.pyc differ
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 (file)
index 0000000..b087e95
--- /dev/null
@@ -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 (file)
index 0000000..4f69f83
Binary files /dev/null and b/example-apps/ROBO/aPaaS/Obj_Detection_service/detection/obj_detection_service.pyc differ
diff --git a/example-apps/ROBO/aPaaS/Obj_Detection_service/requirements.txt b/example-apps/ROBO/aPaaS/Obj_Detection_service/requirements.txt
new file mode 100644 (file)
index 0000000..9e7cae3
--- /dev/null
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+
+flask
+requests
+flask_sslify
+opencv-python
+flask_cors
diff --git a/example-apps/ROBO/aPaaS/Obj_Detection_service/run.py b/example-apps/ROBO/aPaaS/Obj_Detection_service/run.py
new file mode 100644 (file)
index 0000000..1f14088
--- /dev/null
@@ -0,0 +1,25 @@
+#
+# 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 logging
+from logging.handlers import RotatingFileHandler
+from detection.obj_detection_service import start_server
+
+if __name__ == '__main__':
+    handler = RotatingFileHandler('/usr/app/log/obj_detection.log',
+                                  maxBytes=10000000, backupCount=10)
+    handler.setLevel(logging.INFO)
+    start_server(handler)
diff --git a/example-apps/ROBO/aPaaS/README.md b/example-apps/ROBO/aPaaS/README.md
new file mode 100644 (file)
index 0000000..c8d9838
--- /dev/null
@@ -0,0 +1,6 @@
+# example-apps aPaaS for obj-detection
+
+#### 介绍
+aPaaS based on EdgeGallery
+
+