更新 concurrency/IntelligentRecognitionProcess.py
This commit is contained in:
parent
9f6c1eb8db
commit
57de938d7c
|
|
@ -94,7 +94,6 @@ class IntelligentRecognitionProcess(Process):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
|
|
@ -245,8 +244,7 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
||||||
# 启动心跳线程
|
# 启动心跳线程
|
||||||
hb_thread = self.start_heartbeat(fb_queue, hb_queue, request_id, analyse_type, context)
|
hb_thread = self.start_heartbeat(fb_queue, hb_queue, request_id, analyse_type, context)
|
||||||
|
|
||||||
|
# print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) #7.0,
|
||||||
#print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) #7.0,
|
|
||||||
# 加载算法模型
|
# 加载算法模型
|
||||||
model_array = get_model(msg, context, analyse_type)
|
model_array = get_model(msg, context, analyse_type)
|
||||||
#print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) #9.5
|
#print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) #9.5
|
||||||
|
|
@ -301,20 +299,31 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
||||||
task_status[0] = 1
|
task_status[0] = 1
|
||||||
for i, model in enumerate(model_array):
|
for i, model in enumerate(model_array):
|
||||||
model_conf, code = model
|
model_conf, code = model
|
||||||
model_param = model_conf[1]
|
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code) or \
|
||||||
# (modeType, model_param, allowedList, names, rainbows)
|
ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
|
||||||
MODEL_CONFIG[code][2](frame_list[0].shape[1], frame_list[0].shape[0],
|
if draw_config.get(code) is None:
|
||||||
model_conf)
|
draw_config[code] = {}
|
||||||
if draw_config.get("font_config") is None:
|
draw_config["font_config"] = model_conf[4]
|
||||||
draw_config["font_config"] = model_param['font_config']
|
draw_config[code]["allowedList"] = 0
|
||||||
if draw_config.get(code) is None:
|
draw_config[code]["label_arrays"] = [None]
|
||||||
draw_config[code] = {}
|
draw_config[code]["rainbows"] = model_conf[4]
|
||||||
draw_config[code]["allowedList"] = model_conf[2]
|
else:
|
||||||
draw_config[code]["rainbows"] = model_conf[4]
|
model_param = model_conf[1]
|
||||||
draw_config[code]["label_arrays"] = model_param['label_arraylist']
|
# (modeType, model_param, allowedList, names, rainbows)
|
||||||
if "label_dict" in model_param:
|
MODEL_CONFIG[code][2](frame_list[0].shape[1], frame_list[0].shape[0],
|
||||||
draw_config[code]["label_dict"] = model_param['label_dict']
|
model_conf)
|
||||||
#print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno)
|
if draw_config.get("font_config") is None:
|
||||||
|
draw_config["font_config"] = model_param['font_config']
|
||||||
|
if draw_config.get(code) is None:
|
||||||
|
draw_config[code] = {}
|
||||||
|
draw_config[code]["allowedList"] = model_conf[2]
|
||||||
|
draw_config[code]["rainbows"] = model_conf[4]
|
||||||
|
draw_config[code]["label_arrays"] = model_param['label_arraylist']
|
||||||
|
if "label_dict" in model_param:
|
||||||
|
draw_config[code]["label_dict"] = model_param['label_dict']
|
||||||
|
|
||||||
|
|
||||||
|
# print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno)
|
||||||
# 多线程并发处理, 经过测试两个线程最优
|
# 多线程并发处理, 经过测试两个线程最优
|
||||||
det_array = []
|
det_array = []
|
||||||
for i, frame in enumerate(frame_list):
|
for i, frame in enumerate(frame_list):
|
||||||
|
|
@ -616,19 +625,31 @@ class OfflineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
||||||
task_status[0] = 1
|
task_status[0] = 1
|
||||||
for i, model in enumerate(model_array):
|
for i, model in enumerate(model_array):
|
||||||
model_conf, code = model
|
model_conf, code = model
|
||||||
model_param = model_conf[1]
|
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code) or \
|
||||||
# (modeType, model_param, allowedList, names, rainbows)
|
ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code):
|
||||||
MODEL_CONFIG[code][2](frame_list[0].shape[1], frame_list[0].shape[0],
|
if draw_config.get(code) is None:
|
||||||
model_conf)
|
draw_config[code] = {}
|
||||||
if draw_config.get("font_config") is None:
|
draw_config["font_config"] = model_conf[4]
|
||||||
draw_config["font_config"] = model_param['font_config']
|
draw_config[code]["allowedList"] = 0
|
||||||
if draw_config.get(code) is None:
|
draw_config[code]["label_arrays"] = [None]
|
||||||
draw_config[code] = {}
|
draw_config[code]["rainbows"] = model_conf[4]
|
||||||
draw_config[code]["allowedList"] = model_conf[2]
|
|
||||||
draw_config[code]["rainbows"] = model_conf[4]
|
else:
|
||||||
draw_config[code]["label_arrays"] = model_param['label_arraylist']
|
model_param = model_conf[1]
|
||||||
if "label_dict" in model_param:
|
# (modeType, model_param, allowedList, names, rainbows)
|
||||||
draw_config[code]["label_dict"] = model_param['label_dict']
|
MODEL_CONFIG[code][2](frame_list[0].shape[1], frame_list[0].shape[0],
|
||||||
|
model_conf)
|
||||||
|
if draw_config.get("font_config") is None:
|
||||||
|
draw_config["font_config"] = model_param['font_config']
|
||||||
|
if draw_config.get(code) is None:
|
||||||
|
draw_config[code] = {}
|
||||||
|
draw_config[code]["allowedList"] = model_conf[2]
|
||||||
|
draw_config[code]["rainbows"] = model_conf[4]
|
||||||
|
draw_config[code]["label_arrays"] = model_param['label_arraylist']
|
||||||
|
if "label_dict" in model_param:
|
||||||
|
draw_config[code]["label_dict"] = model_param['label_dict']
|
||||||
|
|
||||||
|
|
||||||
det_array = []
|
det_array = []
|
||||||
for i, frame in enumerate(frame_list):
|
for i, frame in enumerate(frame_list):
|
||||||
det_result = t.submit(self.obj_det, self, model_array, frame, task_status,
|
det_result = t.submit(self.obj_det, self, model_array, frame, task_status,
|
||||||
|
|
@ -922,6 +943,63 @@ class PhotosIntelligentRecognitionProcess(Process):
|
||||||
logger.error("模型分析异常: {}, requestId: {}", format_exc(), request_id)
|
logger.error("模型分析异常: {}, requestId: {}", format_exc(), request_id)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
#自研究车牌模型
|
||||||
|
def carplate_rec(self, imageUrl, mod, image_queue, request_id):
|
||||||
|
try:
|
||||||
|
# model_conf: modeType, allowedList, detpar, ocrmodel, rainbows
|
||||||
|
model_conf, code = mod
|
||||||
|
modeType, device, modelList, detpar, rainbows = model_conf
|
||||||
|
image = url2Array(imageUrl)
|
||||||
|
dets = {code: {}}
|
||||||
|
# param = [image, new_device, model, par, img_type, request_id]
|
||||||
|
# model_conf, frame, device, requestId
|
||||||
|
dataBack = MODEL_CONFIG[code][3]([[modeType, device, modelList, detpar], image, request_id])[0][2]
|
||||||
|
dets[code][0] = dataBack
|
||||||
|
if not dataBack:
|
||||||
|
logger.info("车牌识别为空")
|
||||||
|
|
||||||
|
# for ai_result in dataBack:
|
||||||
|
# label, box = ai_result
|
||||||
|
# color = rainbows
|
||||||
|
|
||||||
|
if len(dataBack) > 0:
|
||||||
|
put_queue(image_queue, (1, (dets, imageUrl, image, rainbows, "")), timeout=2, is_ex=False)
|
||||||
|
|
||||||
|
except ServiceException as s:
|
||||||
|
raise s
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("模型分析异常: {}, requestId: {}", format_exc(), request_id)
|
||||||
|
raise e
|
||||||
|
|
||||||
|
#密集人群计数
|
||||||
|
def denscrowdcount_rec(self, imageUrl, mod, image_queue, request_id):
|
||||||
|
try:
|
||||||
|
# model_conf: modeType, allowedList, detpar, ocrmodel, rainbows
|
||||||
|
model_conf, code = mod
|
||||||
|
modeType, device, model, postPar, rainbows = model_conf
|
||||||
|
image = url2Array(imageUrl)
|
||||||
|
dets = {code: {}}
|
||||||
|
# param = [image, new_device, model, par, img_type, request_id]
|
||||||
|
# model_conf, frame, device, requestId
|
||||||
|
dataBack = MODEL_CONFIG[code][3]([[modeType, device, model, postPar], image, request_id])[0][2]
|
||||||
|
logger.info("当前人数:{}", dataBack[0][0])
|
||||||
|
dets[code][0] = dataBack
|
||||||
|
if not dataBack:
|
||||||
|
logger.info("当前页面无人")
|
||||||
|
|
||||||
|
# for ai_result in dataBack:
|
||||||
|
# label, box = ai_result
|
||||||
|
# color = rainbows
|
||||||
|
|
||||||
|
if len(dataBack) > 0:
|
||||||
|
put_queue(image_queue, (1, (dets, imageUrl, image, rainbows, '')), timeout=2, is_ex=False)
|
||||||
|
|
||||||
|
except ServiceException as s:
|
||||||
|
raise s
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("模型分析异常: {}, requestId: {}", format_exc(), request_id)
|
||||||
|
raise e
|
||||||
|
|
||||||
'''
|
'''
|
||||||
# 防疫模型
|
# 防疫模型
|
||||||
'''
|
'''
|
||||||
|
|
@ -936,6 +1014,26 @@ class PhotosIntelligentRecognitionProcess(Process):
|
||||||
for r in obj_list:
|
for r in obj_list:
|
||||||
r.result(60)
|
r.result(60)
|
||||||
|
|
||||||
|
# 自研车牌识别模型:
|
||||||
|
def carpalteRec(self, imageUrls, model, image_queue, request_id):
|
||||||
|
with ThreadPoolExecutor(max_workers=2) as t:
|
||||||
|
obj_list = []
|
||||||
|
for imageUrl in imageUrls:
|
||||||
|
obj = t.submit(self.carplate_rec, imageUrl, model, image_queue, request_id)
|
||||||
|
obj_list.append(obj)
|
||||||
|
for r in obj_list:
|
||||||
|
r.result(60)
|
||||||
|
|
||||||
|
# 密集人群计数:CITY_DENSECROWDCOUNT_MODEL
|
||||||
|
def denscrowdcountRec(self, imageUrls, model, image_queue, request_id):
|
||||||
|
with ThreadPoolExecutor(max_workers=2) as t:
|
||||||
|
obj_list = []
|
||||||
|
for imageUrl in imageUrls:
|
||||||
|
obj = t.submit(self.denscrowdcount_rec, imageUrl, model, image_queue, request_id)
|
||||||
|
obj_list.append(obj)
|
||||||
|
for r in obj_list:
|
||||||
|
r.result(60)
|
||||||
|
|
||||||
def image_recognition(self, imageUrl, mod, image_queue, logo, request_id):
|
def image_recognition(self, imageUrl, mod, image_queue, logo, request_id):
|
||||||
try:
|
try:
|
||||||
model_conf, code = mod
|
model_conf, code = mod
|
||||||
|
|
@ -1168,6 +1266,14 @@ class PhotosIntelligentRecognitionProcess(Process):
|
||||||
elif model[1] == ModelType.PLATE_MODEL.value[1]:
|
elif model[1] == ModelType.PLATE_MODEL.value[1]:
|
||||||
result = t.submit(self.epidemicPrevention, imageUrls, model, base_dir, env, request_id)
|
result = t.submit(self.epidemicPrevention, imageUrls, model, base_dir, env, request_id)
|
||||||
task_list.append(result)
|
task_list.append(result)
|
||||||
|
# 自研车牌模型
|
||||||
|
elif model[1] == ModelType.CITY_CARPLATE_MODEL.value[1]:
|
||||||
|
result = t.submit(self.carpalteRec, imageUrls, model, image_queue, request_id)
|
||||||
|
task_list.append(result)
|
||||||
|
# 人群计数模型
|
||||||
|
elif model[1] == ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1]:
|
||||||
|
result = t.submit(self.denscrowdcountRec, imageUrls, model, image_queue, request_id)
|
||||||
|
task_list.append(result)
|
||||||
else:
|
else:
|
||||||
result = t.submit(self.publicIdentification, imageUrls, model, image_queue, logo, request_id)
|
result = t.submit(self.publicIdentification, imageUrls, model, image_queue, logo, request_id)
|
||||||
task_list.append(result)
|
task_list.append(result)
|
||||||
|
|
@ -1380,9 +1486,6 @@ class ScreenRecordingProcess(Process):
|
||||||
clear_queue(self._hb_queue)
|
clear_queue(self._hb_queue)
|
||||||
clear_queue(self._pull_queue)
|
clear_queue(self._pull_queue)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def upload_video(self,base_dir, env, request_id, orFilePath):
|
def upload_video(self,base_dir, env, request_id, orFilePath):
|
||||||
if self._storage_source==1:
|
if self._storage_source==1:
|
||||||
minioSdk = MinioSdk(base_dir, env, request_id )
|
minioSdk = MinioSdk(base_dir, env, request_id )
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue