Commit d9916612 authored by Yuvaraj Subramanian's avatar Yuvaraj Subramanian

Cans YOLOV5

parent 74a3b394
# Default ignored files
/shelf/
/workspace.xml
<component name="ProjectDictionaryState">
<dictionary name="Akshay G">
<words>
<w>idxs</w>
</words>
</dictionary>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.7 (SRF-Cylinders) (2)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PackageRequirementsSettings">
<option name="removeUnused" value="true" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="3">
<item index="0" class="java.lang.String" itemvalue="pyaml" />
<item index="1" class="java.lang.String" itemvalue="flask_cors" />
<item index="2" class="java.lang.String" itemvalue="numpy" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N801" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyUnreachableCodeInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="app.flask_cors" />
<option value="requests" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (SRF-Cylinders) (2)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/edge_app_v1.0.iml" filepath="$PROJECT_DIR$/.idea/edge_app_v1.0.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
FROM nvcr.io/nvidia/pytorch:20.03-py3
#FROM flare-detection-pytorch:v2.0
RUN rm -rf /var/lib/apt/lists/* && rm -rf /root/.cache/pip/
RUN apt-get update
RUN pip uninstall torch torchvision -y
RUN apt-get install -y libsm6 libxext6 libxrender-dev ffmpeg
RUN pip install numpy==1.18.5
RUN pip install msgpack==0.5.6
RUN pip install minio requests cachetools pymongo~=3.10.1 wincertstore==0.2 opencv-contrib-python==4.2.0.34 certifi==2020.6.20 imutils Cython pillow PyYAML scipy yolov5processor==0.0.3
ADD . /app
WORKDIR /app
RUN pip install edge_engine-1.0.0a0-py3-none-any.whl
CMD ["bash","app.sh"]
\ No newline at end of file
#import os
#os.environ["config"] = '{"MONGO_URI": "mongodb://svc-ilens:svc2345@192.168.3.220:21017","MONGO_DATABASE": "ilens_wps", "MONGO_DB": "ilens_wps", ' \
# '"MONGO_COLLECTION": "janusDeployment", "MONGO_KEY": "deploymentId", "MONGO_VALUE": "6d971066", "MONGO_COLL": "serviceConfiguration" }'
from edge_engine.edge_processor import ExecutePipeline
from edge_engine.edge_processor import Pubs
from scripts import SRF_Cans
from edge_engine.common.config import EDGE_CONFIG
if __name__ == '__main__':
pubs = Pubs()
mod = SRF_Cans(config=EDGE_CONFIG, model_config=EDGE_CONFIG["modelConfig"], pubs=pubs, device_id=EDGE_CONFIG['deviceId'])
ex = ExecutePipeline(mod)
ex.run_model()
source /opt/intel/openvino/bin/setupvars.sh
python3 app.py
\ No newline at end of file
pymongo~=3.10.1
# opencv-python~=4.2.0.34
# requests~=2.23.0
cachetools~=4.1.0
wincertstore==0.2
opencv-contrib-python==4.2.0.34
matplotlib
imutils==0.5.3
certifi==2020.6.20
from.face_model import SRF_Cans
import os
import sys
import json
from pymongo import MongoClient
MAIN_OS_VARIABLE = json.loads(os.environ.get('config'))
if MAIN_OS_VARIABLE is None:
sys.stderr.write("Configuration not found...")
sys.stderr.write("Exiting....")
sys.exit(1)
MONGO_URI = MAIN_OS_VARIABLE.get('MONGO_URI')
MONGO_SERVICE_DB = MAIN_OS_VARIABLE.get('MONGO_DB')
MONGO_SERVICE_COLL = MAIN_OS_VARIABLE.get('MONGO_COLL')
PASS_KEY = MAIN_OS_VARIABLE.get('PASS_KEY')
MONGO_DB_OBJ = MongoClient(MONGO_URI)[MONGO_SERVICE_DB]
HOST_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'hostConfig'}).get('config')
APP_MONGO_COLLECTION = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'appMongoConfig'}).get('config')
DEPLOYMENT_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'deploymentMongoConfig'}).get('config')
MINIO_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'minioConfig'}).get('config')
UI_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'uiConfiguration'}).get('config')
REGISTRY_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'registryConfig'}).get('config')
JANUS_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'janusConfig'}).get('config')
MODEL_SERVER_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'modelServerConfig'}).get('config')
MODEL_TRAINER_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'modelTrainerConfig'}).get('config')
MS_SERVER_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'msServerConfig'}).get('config')
THERMAL_CAM_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'thermalCamera'}).get('config')
class ModelConstants:
sink_layer = {'cls': 'cls_branch_concat_1/concat', 'bbox': 'loc_branch_concat_1/concat'}
model_detector_pth = "./data/model/face_mask_detection.xml"
id2class = {0: 'Mask', 1: 'No Mask'}
id2bool = {0: True, 1: False}
exec_net_device_name = 'CPU'
fallback_initial_temperature = 98.3
net_precision = 'FP32'
\ No newline at end of file
This diff is collapsed.
# from.facenet_lite import FaceNetLite
from edge_engine.common.logsetup import logger
from pymongo import MongoClient
from scripts.common.config import MONGO_DB_OBJ, APP_MONGO_COLLECTION
class AlarmUtils:
def __init__(self):
self.attendance_alarm_configuration_collection = MONGO_DB_OBJ[
APP_MONGO_COLLECTION.get('alarmConfigurationCollection')]
self.attendance_tag_collection = MONGO_DB_OBJ[APP_MONGO_COLLECTION.get('tagConfiguration')]
self.attendance_alarm_priority_collection = MONGO_DB_OBJ[APP_MONGO_COLLECTION.get('alarmPriorityCollection')]
def get_alarms(self):
alarms = [each for each in self.attendance_alarm_configuration_collection.find({}, {'_id': 0})]
return alarms
def get_priority_name(self, priority):
data = self.attendance_alarm_priority_collection.find_one({'id': priority}, {'_id': 0})
priority_name = data.get('priority_name')
return priority_name
def build_condition_string(self, rule):
condition = rule['condition']
tag_name = self.attendance_tag_collection.find_one({'tag_id': rule['leftHandSide']['tag']}, {'Tag Name': 1})[
'Tag Name']
condition_value = rule['rightHandSide']['customValue']
condition_name = f"{tag_name} {condition} {condition_value}"
return condition_name, tag_name
def build_message(self, each_alarm, tag_value):
alarmTemplate = each_alarm['alarmTemplate']
alarmTemplate = alarmTemplate.replace('[Tag Name]',
self.build_condition_string(each_alarm['ruleSets'][0]['rules'][0])[1])
alarmTemplate = alarmTemplate.replace('[Tag Value]', str(tag_value))
return alarmTemplate
def process_data(self, tag_value, av_alarms):
# add mongo query to fetch alarms
if av_alarms:
event_decision = {
"Safe": False,
"Risky": False,
"Message": self.build_message(av_alarms[0], tag_value)
}
for each_alarm in av_alarms:
try:
event_decision = self.process_alarm(alarm_record=each_alarm, tag_value=tag_value,
event_decision=event_decision)
except Exception as e:
raise Exception(str(e))
else:
event_decision = {
"Safe": False,
"Risky": False,
"Message": ""
}
logger.debug(" no alarms found")
return event_decision
def process_alarm(self, alarm_record, tag_value, event_decision):
try:
try:
rule_set_operation = "and" if alarm_record["ruleSetAndOrOperationData"][
"isAnd"] else "or"
rule_set_outputs = []
for each_rule_set in alarm_record["ruleSets"]:
try:
rule_operation = "and" if each_rule_set["ruleAndOrOperationData"][
"isAnd"] else "or"
rule_output = []
for each_rule in each_rule_set["rules"]:
try:
primary_output = self.alarm_rule_parser(each_rule, tag_value)
if primary_output is not None:
rule_output.append(primary_output)
except Exception as e:
logger.exception("Exception in parsing rule:" + str(e))
temp_output = self.aggregate_result(rule_operation, rule_output)
if temp_output is not None:
rule_set_outputs.append(temp_output)
except Exception as e:
logger.exception("Exception during parsing of individual rule set:" + str(e))
final_output = self.aggregate_result(rule_set_operation, rule_set_outputs)
# print("alarm condition output:", final_output)
logger.debug(
"{} {} {} {}".format(self.build_condition_string(alarm_record['ruleSets'][0]['rules'][0])[0],
tag_value,
self.get_priority_name(alarm_record['priority']),
final_output))
if self.get_priority_name(alarm_record['priority']) == 'Safe' and final_output == True:
event_decision['Safe'] = True
elif self.get_priority_name(alarm_record['priority']) == 'Risky' and final_output == True:
event_decision['Risky'] = True
# if final output is True, condition satisfied, if not condition not satisfied
return event_decision
except Exception as e:
logger.exception("Exception during alarm rule parsing:" + str(e))
except Exception as e:
logger.exception("Exception during alarm rule parsing:" + str(e))
# logger.debug("EXIT: Alarm Parser")
def get_tag_value(self, tag_value):
try:
return tag_value
except Exception as e:
logger.exception(" Unable to fetch tag value:" + str(e))
def alarm_rule_parser(self, rule, tag_value):
try:
left_side_value = self.get_tag_value(tag_value)
right_opr = str(rule["rightHandSide"][rule["rightHandSide"]["compareOption"]])
final_opr = ""
final_opr += str(left_side_value) + " "
final_opr += rule["condition"] + " "
final_opr += str(right_opr) + " "
rule_result = eval(final_opr)
return rule_result
except Exception as e:
logger.exception("Exception in parsing rule in alarms:" + str(e))
return None
def aggregate_result(self, condition, output):
try:
final_response = ""
if len(output) == 0:
logger.debug("empty array found inside aggregate result")
return None
# logger.debug("OUTPUT:" + str(output))
for i in range(0, len(output)):
final_response += str(output[i]) + " "
if i <= len(output) - 2:
final_response += condition + " "
final_response = eval(final_response)
# logger.debug("Result: " + str(final_response))
return final_response
except Exception as e:
logger.exception("Exception in parsing:" + str(e))
return None
import traceback
from datetime import datetime
from uuid import uuid1
from pymongo import MongoClient
from scripts.common.config import MONGO_DB_OBJ, APP_MONGO_COLLECTION
from edge_engine.common.logsetup import logger
class MongoLogger:
def __init__(self):
self.attendance_event_collection = MONGO_DB_OBJ[APP_MONGO_COLLECTION.get('eventLogCollection')]
self.camera_configuration = MONGO_DB_OBJ[APP_MONGO_COLLECTION.get('cameraConfigurationCollection')]
self.camera_mapping_json = self.get_all_cameras()
def get_all_cameras(self):
camera_mapping_json = self.camera_configuration.find({'decommissioned': False},
{"_id": 0})
camera_json = {}
for each in camera_mapping_json:
camera_json[each['cameraId']] = each['cameraName']
return camera_json
def insert_attendance_event_to_mongo(self, data):
try:
input_data = {
"eventId": str(uuid1()).split('-')[0],
"cameraId": data['deviceId'],
"cameraName": self.camera_mapping_json.get(data['deviceId'], "Thermal Camera"),
"timestamp": datetime.now().strftime("%b %d %Y %H:%M:%S"),
"frame": data['frame'],
"eventtype": "Intrusion Detection",
"bg_color": data["bg_color"],
"font_color": data["font_color"],
"intrusion_message": data["message"],
"alert_sound": data["alert_sound"],
"logged_activity": data["activity"]}
logger.info("Pushing to Mongo..")
input_data["timestamp"] = datetime.now()
self.attendance_event_collection.insert(input_data)
except Exception as e:
logger.info(e)
logger.error(traceback.format_exc())
from cachetools import cached, TTLCache
import time
TTL = 1
class NotificationFilter(object):
def __init__(self, ttl_value=3):
"""init function
"""
global TTL
TTL = ttl_value
self.TTL = ttl_value
self.face_id_cache = {}
def _update_cache(self, name):
"""updates the cache with a name
Args:
name (str): Name of the person
"""
self.face_id_cache[name] = time.time()
def send_notification(self, name):
"""Returns a boolean if the notification center has to be notified
or not
Args:
name (str): name of person identified
Returns:
notify (bool): True if notification to be sent False if the
notification is not to be sent
"""
self._clean_up_cache()
if name is None:
notify = False
else:
is_present = self.face_id_cache.get(name, -1)
if is_present == -1:
notify = True
self._update_cache(name)
else:
notify = False
return notify
@cached(cache=TTLCache(maxsize=1024, ttl=TTL))
def _clean_up_cache(self):
"""Cleans up the cached name at regular interval
"""
key_to_delete = []
for key, value in self.face_id_cache.items():
if time.time() - value >= self.TTL:
key_to_delete.append(key)
for key in key_to_delete:
del self.face_id_cache[key]
if __name__ == "__main__":
obj = NotificationFilter()
print(obj.send_notification("Litesh"))
print(obj.send_notification("Litesh"))
time.sleep(3)
print(obj.send_notification("Litesh"))
time.sleep(1)
print(obj.send_notification("Litesh"))
import logging as log
class YoloParams:
# ------------------------------------------- Extracting layer parameters ------------------------------------------
# Magic numbers are copied from yolo samples
def __init__(self, param, side):
self.num = 3 if 'num' not in param else int(param['num'])
self.coords = 4 if 'coords' not in param else int(param['coords'])
self.classes = 80 if 'classes' not in param else int(param['classes'])
self.side = side
self.anchors = [10.0, 13.0, 16.0, 30.0, 33.0, 23.0, 30.0, 61.0, 62.0, 45.0, 59.0, 119.0, 116.0, 90.0, 156.0,
198.0,
373.0, 326.0] if 'anchors' not in param else [float(a) for a in param['anchors'].split(',')]
self.isYoloV3 = False
if param.get('mask'):
mask = [int(idx) for idx in param['mask'].split(',')]
self.num = len(mask)
maskedAnchors = []
for idx in mask:
maskedAnchors += [self.anchors[idx * 2], self.anchors[idx * 2 + 1]]
self.anchors = maskedAnchors
self.isYoloV3 = True # Weak way to determine but the only one.
def log_params(self):
params_to_print = {'classes': self.classes, 'num': self.num, 'coords': self.coords, 'anchors': self.anchors}
[log.info(" {:8}: {}".format(param_name, param)) for param_name, param in params_to_print.items()]
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment