1)新增M027:建筑物下行人检测及计数 2)密集人群计数模型及自研车牌模型优化 3)分类模型支持pt模型加载(巴中水利)
This commit is contained in:
parent
12a4b296e1
commit
d369031085
|
|
@ -8,16 +8,18 @@ from loguru import logger
|
||||||
import cv2
|
import cv2
|
||||||
from entity.FeedBack import message_feedback
|
from entity.FeedBack import message_feedback
|
||||||
from enums.ExceptionEnum import ExceptionType
|
from enums.ExceptionEnum import ExceptionType
|
||||||
|
from enums.ModelTypeEnum import ModelType
|
||||||
from exception.CustomerException import ServiceException
|
from exception.CustomerException import ServiceException
|
||||||
from util.AliyunSdk import AliyunOssSdk
|
from util.AliyunSdk import AliyunOssSdk
|
||||||
from util.MinioSdk import MinioSdk
|
from util.MinioSdk import MinioSdk
|
||||||
from util import TimeUtils
|
from util import TimeUtils
|
||||||
from enums.AnalysisStatusEnum import AnalysisStatus
|
from enums.AnalysisStatusEnum import AnalysisStatus
|
||||||
from util.PlotsUtils import draw_painting_joint
|
from util.PlotsUtils import draw_painting_joint, draw_name_ocr, draw_name_crowd
|
||||||
from util.QueUtil import put_queue, get_no_block_queue, clear_queue
|
from util.QueUtil import put_queue, get_no_block_queue, clear_queue
|
||||||
import io
|
import io
|
||||||
from util.LocationUtils import locate_byMqtt
|
from util.LocationUtils import locate_byMqtt
|
||||||
|
|
||||||
|
|
||||||
class FileUpload(Thread):
|
class FileUpload(Thread):
|
||||||
__slots__ = ('_fb_queue', '_context', '_image_queue', '_analyse_type', '_msg', '_mqtt_list')
|
__slots__ = ('_fb_queue', '_context', '_image_queue', '_analyse_type', '_msg', '_mqtt_list')
|
||||||
|
|
||||||
|
|
@ -30,8 +32,6 @@ class FileUpload(Thread):
|
||||||
# self._algStatus = True # 默认关闭
|
# self._algStatus = True # 默认关闭
|
||||||
self._algSwitch = self._context['service']['algSwitch']
|
self._algSwitch = self._context['service']['algSwitch']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 0521:
|
# 0521:
|
||||||
default_enabled = str(self._msg.get("defaultEnabled", "True")).lower() == "true"
|
default_enabled = str(self._msg.get("defaultEnabled", "True")).lower() == "true"
|
||||||
if default_enabled:
|
if default_enabled:
|
||||||
|
|
@ -46,14 +46,6 @@ class FileUpload(Thread):
|
||||||
print("---line46 :FileUploadThread.py---", self._algSwitch)
|
print("---line46 :FileUploadThread.py---", self._algSwitch)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 如果任务是在线、离线处理,则用此类
|
# 如果任务是在线、离线处理,则用此类
|
||||||
class ImageFileUpload(FileUpload):
|
class ImageFileUpload(FileUpload):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
@ -74,7 +66,6 @@ class ImageFileUpload(FileUpload):
|
||||||
'''
|
'''
|
||||||
print('*' * 100, ' mqtt_list:', len(self._mqtt_list))
|
print('*' * 100, ' mqtt_list:', len(self._mqtt_list))
|
||||||
|
|
||||||
|
|
||||||
model_info = []
|
model_info = []
|
||||||
# 更加模型编码解析数据
|
# 更加模型编码解析数据
|
||||||
for code, det_list in det_xywh.items():
|
for code, det_list in det_xywh.items():
|
||||||
|
|
@ -83,7 +74,16 @@ class ImageFileUpload(FileUpload):
|
||||||
if len(target_list) > 0:
|
if len(target_list) > 0:
|
||||||
aFrame = frame.copy()
|
aFrame = frame.copy()
|
||||||
for target in target_list:
|
for target in target_list:
|
||||||
draw_painting_joint(target[1], aFrame, target[3], target[2], target[4], font_config, target[5])
|
# 自研车牌模型判断
|
||||||
|
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
|
||||||
|
draw_name_ocr(target[1], aFrame, target[4])
|
||||||
|
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code) or\
|
||||||
|
ModelType.CITY_UNDERBUILDCOUNT_MODEL.value[1] == str(code):
|
||||||
|
draw_name_crowd(target[1], aFrame, target[4])
|
||||||
|
else:
|
||||||
|
draw_painting_joint(target[1], aFrame, target[3], target[2], target[4], font_config,
|
||||||
|
target[5])
|
||||||
|
|
||||||
igH, igW = aFrame.shape[0:2]
|
igH, igW = aFrame.shape[0:2]
|
||||||
if len(self._mqtt_list) >= 1:
|
if len(self._mqtt_list) >= 1:
|
||||||
# camParas = self._mqtt_list[0]['data']
|
# camParas = self._mqtt_list[0]['data']
|
||||||
|
|
@ -91,7 +91,8 @@ class ImageFileUpload(FileUpload):
|
||||||
gps = locate_byMqtt(target[1], igW, igH, camParas, outFormat='wgs84')
|
gps = locate_byMqtt(target[1], igW, igH, camParas, outFormat='wgs84')
|
||||||
else:
|
else:
|
||||||
gps = [None, None]
|
gps = [None, None]
|
||||||
model_info.append({"modelCode": str(code), "detectTargetCode": str(cls), "aFrame": aFrame,'gps':gps})
|
model_info.append(
|
||||||
|
{"modelCode": str(code), "detectTargetCode": str(cls), "aFrame": aFrame, 'gps': gps})
|
||||||
if len(model_info) > 0:
|
if len(model_info) > 0:
|
||||||
image_result = {
|
image_result = {
|
||||||
"or_frame": frame,
|
"or_frame": frame,
|
||||||
|
|
@ -110,8 +111,10 @@ class ImageFileUpload(FileUpload):
|
||||||
image_queue, fb_queue, analyse_type = self._image_queue, self._fb_queue, self._analyse_type
|
image_queue, fb_queue, analyse_type = self._image_queue, self._fb_queue, self._analyse_type
|
||||||
service_timeout = int(service["timeout"])
|
service_timeout = int(service["timeout"])
|
||||||
frame_step = int(service["filter"]["frame_step"]) + 120
|
frame_step = int(service["filter"]["frame_step"]) + 120
|
||||||
if msg['taskType']==0: self._algStatus = False
|
if msg['taskType'] == 0:
|
||||||
else: self._algStatus = True
|
self._algStatus = False
|
||||||
|
else:
|
||||||
|
self._algStatus = True
|
||||||
try:
|
try:
|
||||||
with ThreadPoolExecutor(max_workers=2) as t:
|
with ThreadPoolExecutor(max_workers=2) as t:
|
||||||
# 初始化oss客户端
|
# 初始化oss客户端
|
||||||
|
|
@ -136,8 +139,10 @@ class ImageFileUpload(FileUpload):
|
||||||
if 'stop' == image_msg[1]:
|
if 'stop' == image_msg[1]:
|
||||||
logger.info("开始停止图片上传线程, requestId:{}", request_id)
|
logger.info("开始停止图片上传线程, requestId:{}", request_id)
|
||||||
break
|
break
|
||||||
if 'algStart' == image_msg[1]: self._algStatus = True; logger.info("图片上传线程,执行算法开启命令, requestId:{}", request_id)
|
if 'algStart' == image_msg[1]: self._algStatus = True; logger.info(
|
||||||
if 'algStop' == image_msg[1]: self._algStatus = False; logger.info("图片上传线程,执行算法关闭命令, requestId:{}", request_id)
|
"图片上传线程,执行算法开启命令, requestId:{}", request_id)
|
||||||
|
if 'algStop' == image_msg[1]: self._algStatus = False; logger.info(
|
||||||
|
"图片上传线程,执行算法关闭命令, requestId:{}", request_id)
|
||||||
|
|
||||||
if image_msg[0] == 1:
|
if image_msg[0] == 1:
|
||||||
image_result = self.handle_image(image_msg[1], frame_step)
|
image_result = self.handle_image(image_msg[1], frame_step)
|
||||||
|
|
@ -230,6 +235,7 @@ class ImageTypeImageFileUpload(Thread):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._fb_queue, self._context, self._msg, self._image_queue, self._analyse_type = args
|
self._fb_queue, self._context, self._msg, self._image_queue, self._analyse_type = args
|
||||||
self._storage_source = self._context['service']['storage_source']
|
self._storage_source = self._context['service']['storage_source']
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def handle_image(det_xywh, copy_frame, font_config):
|
def handle_image(det_xywh, copy_frame, font_config):
|
||||||
"""
|
"""
|
||||||
|
|
@ -249,12 +255,21 @@ class ImageTypeImageFileUpload(Thread):
|
||||||
if target_list is not None and len(target_list) > 0:
|
if target_list is not None and len(target_list) > 0:
|
||||||
aiFrame = copy_frame.copy()
|
aiFrame = copy_frame.copy()
|
||||||
for target in target_list:
|
for target in target_list:
|
||||||
|
# 自研车牌模型判断
|
||||||
|
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
|
||||||
|
draw_name_ocr(target, aiFrame, font_config[cls])
|
||||||
|
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code) or \
|
||||||
|
ModelType.CITY_UNDERBUILDCOUNT_MODEL.value[1] == str(code):
|
||||||
|
draw_name_crowd(target, aiFrame, font_config[cls])
|
||||||
|
else:
|
||||||
draw_painting_joint(target[1], aiFrame, target[3], target[2], target[4], font_config)
|
draw_painting_joint(target[1], aiFrame, target[3], target[2], target[4], font_config)
|
||||||
|
|
||||||
model_info.append({
|
model_info.append({
|
||||||
"modelCode": str(code),
|
"modelCode": str(code),
|
||||||
"detectTargetCode": str(cls),
|
"detectTargetCode": str(cls),
|
||||||
"frame": aiFrame
|
"frame": aiFrame
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(model_info) > 0:
|
if len(model_info) > 0:
|
||||||
image_result = {
|
image_result = {
|
||||||
"or_frame": copy_frame,
|
"or_frame": copy_frame,
|
||||||
|
|
@ -363,7 +378,6 @@ class ImageTypeImageFileUpload(Thread):
|
||||||
for thread_result in task:
|
for thread_result in task:
|
||||||
remote_url_list.append(thread_result.result())
|
remote_url_list.append(thread_result.result())
|
||||||
|
|
||||||
|
|
||||||
# 以下代码是为了获取图像上传后,返回的全路径地址
|
# 以下代码是为了获取图像上传后,返回的全路径地址
|
||||||
if det_xywh is None:
|
if det_xywh is None:
|
||||||
msg_list.append(message_feedback(request_id,
|
msg_list.append(message_feedback(request_id,
|
||||||
|
|
@ -394,13 +408,10 @@ class ImageTypeImageFileUpload(Thread):
|
||||||
image_url,
|
image_url,
|
||||||
remote_url_list[ii],
|
remote_url_list[ii],
|
||||||
model_info_list[ii].get('modelCode'),
|
model_info_list[ii].get('modelCode'),
|
||||||
model_info_list[ii].get('detectTargetCode'),
|
model_info_list[ii].get(
|
||||||
|
'detectTargetCode'),
|
||||||
analyse_results=result))
|
analyse_results=result))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for msg in msg_list:
|
for msg in msg_list:
|
||||||
put_queue(fb_queue, msg, timeout=2, is_ex=False)
|
put_queue(fb_queue, msg, timeout=2, is_ex=False)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,6 @@ class IntelligentRecognitionProcess(Process):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
|
|
@ -113,7 +111,6 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
||||||
pullProcess.start()
|
pullProcess.start()
|
||||||
return pullProcess
|
return pullProcess
|
||||||
|
|
||||||
|
|
||||||
def upload_video(self,base_dir, env, request_id, orFilePath, aiFilePath):
|
def upload_video(self,base_dir, env, request_id, orFilePath, aiFilePath):
|
||||||
if self._storage_source==1:
|
if self._storage_source==1:
|
||||||
minioSdk = MinioSdk(base_dir, env, request_id)
|
minioSdk = MinioSdk(base_dir, env, request_id)
|
||||||
|
|
@ -124,8 +121,6 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
||||||
upload_video_thread_or = Common(aliyunVodSdk.get_play_url, orFilePath, "or_online_%s" % request_id)
|
upload_video_thread_or = Common(aliyunVodSdk.get_play_url, orFilePath, "or_online_%s" % request_id)
|
||||||
upload_video_thread_ai = Common(aliyunVodSdk.get_play_url, aiFilePath, "ai_online_%s" % request_id)
|
upload_video_thread_ai = Common(aliyunVodSdk.get_play_url, aiFilePath, "ai_online_%s" % request_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
upload_video_thread_or.setDaemon(True)
|
upload_video_thread_or.setDaemon(True)
|
||||||
upload_video_thread_ai.setDaemon(True)
|
upload_video_thread_ai.setDaemon(True)
|
||||||
upload_video_thread_or.start()
|
upload_video_thread_or.start()
|
||||||
|
|
@ -245,7 +240,6 @@ 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)
|
||||||
|
|
@ -301,6 +295,16 @@ 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
|
||||||
|
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code) or \
|
||||||
|
ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code) or\
|
||||||
|
ModelType.CITY_UNDERBUILDCOUNT_MODEL.value[1] == str(code):
|
||||||
|
if draw_config.get(code) is None:
|
||||||
|
draw_config[code] = {}
|
||||||
|
draw_config["font_config"] = model_conf[4]
|
||||||
|
draw_config[code]["allowedList"] = 0
|
||||||
|
draw_config[code]["label_arrays"] = [None]
|
||||||
|
draw_config[code]["rainbows"] = model_conf[4]
|
||||||
|
else:
|
||||||
model_param = model_conf[1]
|
model_param = model_conf[1]
|
||||||
# (modeType, model_param, allowedList, names, rainbows)
|
# (modeType, model_param, allowedList, names, rainbows)
|
||||||
MODEL_CONFIG[code][2](frame_list[0].shape[1], frame_list[0].shape[0],
|
MODEL_CONFIG[code][2](frame_list[0].shape[1], frame_list[0].shape[0],
|
||||||
|
|
@ -314,6 +318,8 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
||||||
draw_config[code]["label_arrays"] = model_param['label_arraylist']
|
draw_config[code]["label_arrays"] = model_param['label_arraylist']
|
||||||
if "label_dict" in model_param:
|
if "label_dict" in model_param:
|
||||||
draw_config[code]["label_dict"] = model_param['label_dict']
|
draw_config[code]["label_dict"] = model_param['label_dict']
|
||||||
|
|
||||||
|
|
||||||
# print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno)
|
# print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno)
|
||||||
# 多线程并发处理, 经过测试两个线程最优
|
# 多线程并发处理, 经过测试两个线程最优
|
||||||
det_array = []
|
det_array = []
|
||||||
|
|
@ -616,6 +622,17 @@ 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
|
||||||
|
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code) or \
|
||||||
|
ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code) or\
|
||||||
|
ModelType.CITY_UNDERBUILDCOUNT_MODEL.value[1] == str(code):
|
||||||
|
if draw_config.get(code) is None:
|
||||||
|
draw_config[code] = {}
|
||||||
|
draw_config["font_config"] = model_conf[4]
|
||||||
|
draw_config[code]["allowedList"] = 0
|
||||||
|
draw_config[code]["label_arrays"] = [None]
|
||||||
|
draw_config[code]["rainbows"] = model_conf[4]
|
||||||
|
|
||||||
|
else:
|
||||||
model_param = model_conf[1]
|
model_param = model_conf[1]
|
||||||
# (modeType, model_param, allowedList, names, rainbows)
|
# (modeType, model_param, allowedList, names, rainbows)
|
||||||
MODEL_CONFIG[code][2](frame_list[0].shape[1], frame_list[0].shape[0],
|
MODEL_CONFIG[code][2](frame_list[0].shape[1], frame_list[0].shape[0],
|
||||||
|
|
@ -629,6 +646,8 @@ class OfflineIntelligentRecognitionProcess(IntelligentRecognitionProcess):
|
||||||
draw_config[code]["label_arrays"] = model_param['label_arraylist']
|
draw_config[code]["label_arrays"] = model_param['label_arraylist']
|
||||||
if "label_dict" in model_param:
|
if "label_dict" in model_param:
|
||||||
draw_config[code]["label_dict"] = model_param['label_dict']
|
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 +941,62 @@ 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]
|
||||||
|
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 +1011,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 +1263,15 @@ 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] or \
|
||||||
|
model[1] == ModelType.CITY_UNDERBUILDCOUNT_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 +1484,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)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ from util.Cv2Utils import video_conjuncing, write_or_video, write_ai_video, push
|
||||||
from util.ImageUtils import url2Array, add_water_pic
|
from util.ImageUtils import url2Array, add_water_pic
|
||||||
from util.LogUtils import init_log
|
from util.LogUtils import init_log
|
||||||
|
|
||||||
from util.PlotsUtils import draw_painting_joint, filterBox, xywh2xyxy2, draw_name_joint
|
from util.PlotsUtils import draw_painting_joint, filterBox, xywh2xyxy2, xy2xyxy, draw_name_joint, plot_one_box_auto, draw_name_ocr,draw_name_crowd
|
||||||
|
|
||||||
from util.QueUtil import get_no_block_queue, put_queue, clear_queue
|
from util.QueUtil import get_no_block_queue, put_queue, clear_queue
|
||||||
|
|
||||||
|
|
@ -50,15 +50,8 @@ class PushStreamProcess(Process):
|
||||||
# 这里放非默认逻辑的代码
|
# 这里放非默认逻辑的代码
|
||||||
self._algSwitch = False
|
self._algSwitch = False
|
||||||
|
|
||||||
|
|
||||||
print("---line53 :PushVideoStreamProcess.py---",self._algSwitch)
|
print("---line53 :PushVideoStreamProcess.py---",self._algSwitch)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def build_logo_url(self):
|
def build_logo_url(self):
|
||||||
logo = None
|
logo = None
|
||||||
if self._context["video"]["video_add_water"]:
|
if self._context["video"]["video_add_water"]:
|
||||||
|
|
@ -155,6 +148,23 @@ class OnPushStreamProcess(PushStreamProcess):
|
||||||
font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"]
|
font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"]
|
||||||
rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"]
|
rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"]
|
||||||
for qs in det_result:
|
for qs in det_result:
|
||||||
|
# 自研车牌模型处理
|
||||||
|
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
|
||||||
|
cls = 0
|
||||||
|
box = xy2xyxy(qs[1])
|
||||||
|
score = None
|
||||||
|
color = rainbows[cls]
|
||||||
|
label_array = None
|
||||||
|
rr = t.submit(draw_name_ocr, qs, copy_frame, color)
|
||||||
|
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code) or\
|
||||||
|
ModelType.CITY_UNDERBUILDCOUNT_MODEL.value[1] == str(code):
|
||||||
|
cls = 0
|
||||||
|
box = [(0, 0), (0, 0), (0, 0), (0, 0)]
|
||||||
|
score = None
|
||||||
|
color = rainbows[cls]
|
||||||
|
label_array = None
|
||||||
|
rr = t.submit(draw_name_crowd, qs, copy_frame, color)
|
||||||
|
else:
|
||||||
try: # 应对NaN情况
|
try: # 应对NaN情况
|
||||||
box, score, cls = xywh2xyxy2(qs)
|
box, score, cls = xywh2xyxy2(qs)
|
||||||
except:
|
except:
|
||||||
|
|
@ -163,9 +173,13 @@ class OnPushStreamProcess(PushStreamProcess):
|
||||||
continue
|
continue
|
||||||
label_array, color = label_arrays[cls], rainbows[cls]
|
label_array, color = label_arrays[cls], rainbows[cls]
|
||||||
if ModelType.CHANNEL2_MODEL.value[1] == str(code) and cls == 2:
|
if ModelType.CHANNEL2_MODEL.value[1] == str(code) and cls == 2:
|
||||||
rr = t.submit(draw_name_joint, box, copy_frame, draw_config[code]["label_dict"], score, color, font_config, qs[6])
|
rr = t.submit(draw_name_joint, box, copy_frame,
|
||||||
|
draw_config[code]["label_dict"], score, color,
|
||||||
|
font_config, qs[6])
|
||||||
else:
|
else:
|
||||||
rr = t.submit(draw_painting_joint, box, copy_frame, label_array, score, color, font_config)
|
rr = t.submit(draw_painting_joint, box, copy_frame, label_array,
|
||||||
|
score, color, font_config)
|
||||||
|
|
||||||
thread_p.append(rr)
|
thread_p.append(rr)
|
||||||
if det_xywh.get(code) is None:
|
if det_xywh.get(code) is None:
|
||||||
det_xywh[code] = {}
|
det_xywh[code] = {}
|
||||||
|
|
@ -246,6 +260,10 @@ class OnPushStreamProcess(PushStreamProcess):
|
||||||
is_new = False
|
is_new = False
|
||||||
if q[11] == 1:
|
if q[11] == 1:
|
||||||
is_new = True
|
is_new = True
|
||||||
|
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code) or \
|
||||||
|
ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code) or\
|
||||||
|
ModelType.CITY_UNDERBUILDCOUNT_MODEL.value[1] == str(code):
|
||||||
|
box = qs
|
||||||
if cd is None:
|
if cd is None:
|
||||||
det_xywh2[code][cls] = [[cls, box, score, label_array, color, is_new]]
|
det_xywh2[code][cls] = [[cls, box, score, label_array, color, is_new]]
|
||||||
else:
|
else:
|
||||||
|
|
@ -370,8 +388,27 @@ class OffPushStreamProcess(PushStreamProcess):
|
||||||
font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"]
|
font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"]
|
||||||
rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"]
|
rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"]
|
||||||
for qs in det_result:
|
for qs in det_result:
|
||||||
box, score, cls = xywh2xyxy2(qs)
|
# 自研车牌模型处理
|
||||||
|
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code):
|
||||||
|
cls = 0
|
||||||
|
box = xy2xyxy(qs[1])
|
||||||
|
score = None
|
||||||
|
color = rainbows[cls]
|
||||||
|
label_array = None
|
||||||
|
label_arrays = [None]
|
||||||
|
rr = t.submit(draw_name_ocr, qs, copy_frame, color)
|
||||||
|
|
||||||
|
elif ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code) or\
|
||||||
|
ModelType.CITY_UNDERBUILDCOUNT_MODEL.value[1] == str(code):
|
||||||
|
cls = 0
|
||||||
|
box = [(0,0),(0,0),(0,0),(0,0)]
|
||||||
|
score = None
|
||||||
|
color = rainbows[cls]
|
||||||
|
label_array = None
|
||||||
|
rr = t.submit(draw_name_crowd, qs, copy_frame, color)
|
||||||
|
|
||||||
|
else:
|
||||||
|
box, score, cls = xywh2xyxy2(qs)
|
||||||
if cls not in allowedList or score < frame_score:
|
if cls not in allowedList or score < frame_score:
|
||||||
continue
|
continue
|
||||||
label_array, color = label_arrays[cls], rainbows[cls]
|
label_array, color = label_arrays[cls], rainbows[cls]
|
||||||
|
|
@ -379,6 +416,7 @@ class OffPushStreamProcess(PushStreamProcess):
|
||||||
rr = t.submit(draw_name_joint, box, copy_frame, draw_config[code]["label_dict"], score, color, font_config, qs[6])
|
rr = t.submit(draw_name_joint, box, copy_frame, draw_config[code]["label_dict"], score, color, font_config, qs[6])
|
||||||
else:
|
else:
|
||||||
rr = t.submit(draw_painting_joint, box, copy_frame, label_array, score, color, font_config)
|
rr = t.submit(draw_painting_joint, box, copy_frame, label_array, score, color, font_config)
|
||||||
|
|
||||||
thread_p.append(rr)
|
thread_p.append(rr)
|
||||||
|
|
||||||
if det_xywh.get(code) is None:
|
if det_xywh.get(code) is None:
|
||||||
|
|
@ -416,7 +454,6 @@ class OffPushStreamProcess(PushStreamProcess):
|
||||||
push_stream_result = t.submit(push_video_stream, frame_merge, push_p, push_url,
|
push_stream_result = t.submit(push_video_stream, frame_merge, push_p, push_url,
|
||||||
p_push_status, request_id)
|
p_push_status, request_id)
|
||||||
|
|
||||||
|
|
||||||
if qs_np is not None:
|
if qs_np is not None:
|
||||||
if len(qs_np.shape) == 1:
|
if len(qs_np.shape) == 1:
|
||||||
qs_np = qs_np[np.newaxis,...]
|
qs_np = qs_np[np.newaxis,...]
|
||||||
|
|
@ -459,6 +496,11 @@ class OffPushStreamProcess(PushStreamProcess):
|
||||||
is_new = False
|
is_new = False
|
||||||
if q[11] == 1:
|
if q[11] == 1:
|
||||||
is_new = True
|
is_new = True
|
||||||
|
|
||||||
|
if ModelType.CITY_CARPLATE_MODEL.value[1] == str(code) or \
|
||||||
|
ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1] == str(code) or\
|
||||||
|
ModelType.CITY_UNDERBUILDCOUNT_MODEL.value[1] == str(code):
|
||||||
|
box = qs
|
||||||
if cd is None:
|
if cd is None:
|
||||||
det_xywh2[code][cls] = [[cls, box, score, label_array, color, is_new]]
|
det_xywh2[code][cls] = [[cls, box, score, label_array, color, is_new]]
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -9,15 +9,14 @@ from DMPRUtils.jointUtil import dmpr_yolo
|
||||||
from segutils.segmodel import SegModel
|
from segutils.segmodel import SegModel
|
||||||
from utilsK.queRiver import riverDetSegMixProcess
|
from utilsK.queRiver import riverDetSegMixProcess
|
||||||
from utilsK.crowdGather import gather_post_process
|
from utilsK.crowdGather import gather_post_process
|
||||||
from segutils.trafficUtils import tracfficAccidentMixFunction
|
from segutils.trafficUtils import tracfficAccidentMixFunction,mixTraffic_postprocess
|
||||||
from utilsK.drownUtils import mixDrowing_water_postprocess
|
from utilsK.drownUtils import mixDrowing_water_postprocess
|
||||||
from utilsK.noParkingUtils import mixNoParking_road_postprocess
|
from utilsK.noParkingUtils import mixNoParking_road_postprocess
|
||||||
from utilsK.illParkingUtils import illParking_postprocess
|
from utilsK.illParkingUtils import illParking_postprocess
|
||||||
from utilsK.spillUtils import mixSpillage_postprocess
|
|
||||||
from utilsK.cthcUtils import mixCthc_postprocess
|
|
||||||
from utilsK.pannelpostUtils import pannel_post_process
|
from utilsK.pannelpostUtils import pannel_post_process
|
||||||
from stdc import stdcModel
|
from stdc import stdcModel
|
||||||
from yolov5 import yolov5Model
|
from yolov5 import yolov5Model
|
||||||
|
from p2pNet import p2NnetModel
|
||||||
from DMPRUtils.jointUtil import dmpr_yolo_stdc
|
from DMPRUtils.jointUtil import dmpr_yolo_stdc
|
||||||
from AI import default_mix
|
from AI import default_mix
|
||||||
from ocr import ocrModel
|
from ocr import ocrModel
|
||||||
|
|
@ -121,7 +120,6 @@ class ModelType(Enum):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TRAFFIC_FARM_MODEL = ("3", "003", "交通模型", 'highWay2', lambda device, gpuName: {
|
TRAFFIC_FARM_MODEL = ("3", "003", "交通模型", 'highWay2', lambda device, gpuName: {
|
||||||
'device': str(device),
|
'device': str(device),
|
||||||
'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水", "影子",
|
'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水", "影子",
|
||||||
|
|
@ -131,8 +129,7 @@ class ModelType(Enum):
|
||||||
'seg_nclass': 3,
|
'seg_nclass': 3,
|
||||||
'segRegionCnt': 2,
|
'segRegionCnt': 2,
|
||||||
'segPar': {
|
'segPar': {
|
||||||
#'modelSize': (640, 360),
|
'modelSize': (640, 360),
|
||||||
'modelSize': (1920, 1080),
|
|
||||||
'mean': (0.485, 0.456, 0.406),
|
'mean': (0.485, 0.456, 0.406),
|
||||||
'std': (0.229, 0.224, 0.225),
|
'std': (0.229, 0.224, 0.225),
|
||||||
'predResize': True,
|
'predResize': True,
|
||||||
|
|
@ -141,8 +138,7 @@ class ModelType(Enum):
|
||||||
'mixFunction': {
|
'mixFunction': {
|
||||||
'function': tracfficAccidentMixFunction,
|
'function': tracfficAccidentMixFunction,
|
||||||
'pars': {
|
'pars': {
|
||||||
#'modelSize': (640, 360),
|
'modelSize': (640, 360),
|
||||||
'modelSize': (1920,1080),
|
|
||||||
'RoadArea': 16000,
|
'RoadArea': 16000,
|
||||||
'roadVehicleAngle': 15,
|
'roadVehicleAngle': 15,
|
||||||
'speedRoadVehicleAngleMax': 75,
|
'speedRoadVehicleAngleMax': 75,
|
||||||
|
|
@ -361,30 +357,27 @@ class ModelType(Enum):
|
||||||
"classes": 5,
|
"classes": 5,
|
||||||
"rainbows": COLOR
|
"rainbows": COLOR
|
||||||
},
|
},
|
||||||
# "../weights/pth/AIlib2/%s/yolov5.pt" % modeType.value[3]
|
|
||||||
'Detweights': "../weights/trt/AIlib2/river2/yolov5_%s_fp16.engine" % gpuName,
|
'Detweights': "../weights/trt/AIlib2/river2/yolov5_%s_fp16.engine" % gpuName,
|
||||||
# '../weights/pth/AIlib2/%s/stdc_360X640.pth' % modeType.value[3]
|
|
||||||
'Segweights': '../weights/trt/AIlib2/river2/stdc_360X640_%s_fp16.engine' % gpuName
|
'Segweights': '../weights/trt/AIlib2/river2/stdc_360X640_%s_fp16.engine' % gpuName
|
||||||
})
|
})
|
||||||
|
|
||||||
CITY_MANGEMENT_MODEL = ("16", "016", "城管模型", 'cityMangement2', lambda device, gpuName: {
|
CITY_MANGEMENT_MODEL = ("16", "016", "城管模型", 'cityMangement2', lambda device, gpuName: {
|
||||||
'labelnames': [ "车辆", "垃圾", "商贩", "违停","占道经营","裸土","未覆盖裸土" ],
|
'labelnames': [ "车辆", "垃圾", "商贩", "违停","占道经营","裸土","未覆盖裸土","违建" ],
|
||||||
'postProcess':{
|
'postProcess':{
|
||||||
'function':dmpr_yolo_stdc,
|
'function':dmpr_yolo_stdc,
|
||||||
'pars':{
|
'pars':{
|
||||||
'carCls':0 ,'illCls':6,'scaleRatio':0.5,'border':80,
|
'carCls':0 ,'illCls':7,'scaleRatio':0.5,'border':80,
|
||||||
#车辆","垃圾","商贩","裸土","占道经营","违停"--->
|
#"车辆","垃圾","商贩","裸土","占道经营","未覆盖裸土","违建"
|
||||||
#"车辆","垃圾","商贩","违停","占道经营","裸土"
|
# key:实际训练index value:展示index
|
||||||
'classReindex':{ 0:0,1:1,2:2,3:6,4:4,5:5,6:3}
|
'classReindex':{ 0:0,1:1,2:2,7:3,4:4,3:5,5:6,6:7}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'models':[
|
'models':[
|
||||||
{
|
{
|
||||||
'weight':'../weights/pth/AIlib2/cityMangement3/yolov5.pt',
|
'weight':'../weights/trt/AIlib2/cityMangement3/yolov5_%s_fp16.engine'%(gpuName),
|
||||||
#'weight':'../weights/trt/AIlib2/cityMangement3/yolov5_%s_fp16.engine'%(gpuName),
|
|
||||||
'name':'yolov5',
|
'name':'yolov5',
|
||||||
'model':yolov5Model,
|
'model':yolov5Model,
|
||||||
'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.25,'iou_thres':0.45,'allowedList':[0,1,2,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.4,"2":0.5,"3":0.5 } }
|
'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.25,'iou_thres':0.45,'allowedList':[0,1,2,3,4,5,6,7],'segRegionCnt':1, 'trtFlag_det':True,'trtFlag_seg':True, "score_byClass":{"0":0.8,"1":0.4,"2":0.5,"3":0.5 } }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'weight':'../weights/pth/AIlib2/cityMangement3/dmpr.pth',
|
'weight':'../weights/pth/AIlib2/cityMangement3/dmpr.pth',
|
||||||
|
|
@ -396,9 +389,9 @@ class ModelType(Enum):
|
||||||
'name':'dmpr'
|
'name':'dmpr'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'weight':'../weights/pth/AIlib2/cityMangement3/stdc_360X640.pth',
|
'weight':'../weights/trt/AIlib2/cityMangement3/stdc_360X640_%s_fp16.engine'%(gpuName),
|
||||||
'par':{
|
'par':{
|
||||||
'modelSize':(640,360),'mean':(0.485, 0.456, 0.406),'std' :(0.229, 0.224, 0.225),'predResize':True,'numpy':False, 'RGB_convert_first':True,'seg_nclass':2},###分割模型预处理参数
|
'modelSize':(640,360),'mean':(0.485, 0.456, 0.406),'std' :(0.229, 0.224, 0.225),'predResize':True,'numpy':False, 'RGB_convert_first':True,'seg_nclass':3},###分割模型预处理参数
|
||||||
'model':stdcModel,
|
'model':stdcModel,
|
||||||
'name':'stdc'
|
'name':'stdc'
|
||||||
}
|
}
|
||||||
|
|
@ -407,10 +400,10 @@ class ModelType(Enum):
|
||||||
"name": "post_process",
|
"name": "post_process",
|
||||||
"conf_thres": 0.25,
|
"conf_thres": 0.25,
|
||||||
"iou_thres": 0.45,
|
"iou_thres": 0.45,
|
||||||
"classes": 6,
|
"classes": 8,
|
||||||
"rainbows": COLOR
|
"rainbows": COLOR
|
||||||
},
|
},
|
||||||
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6,7,8,9] ],###控制哪些检测类别显示、输出
|
||||||
'segRegionCnt':2,###分割模型结果需要保留的等值线数目
|
'segRegionCnt':2,###分割模型结果需要保留的等值线数目
|
||||||
"pixScale": 1.2,
|
"pixScale": 1.2,
|
||||||
})
|
})
|
||||||
|
|
@ -443,9 +436,7 @@ class ModelType(Enum):
|
||||||
"classes": 9,
|
"classes": 9,
|
||||||
"rainbows": COLOR
|
"rainbows": COLOR
|
||||||
},
|
},
|
||||||
# "../weights/pth/AIlib2/%s/yolov5.pt" % modeType.value[3]
|
|
||||||
'Detweights': "../weights/trt/AIlib2/drowning/yolov5_%s_fp16.engine" % gpuName,
|
'Detweights': "../weights/trt/AIlib2/drowning/yolov5_%s_fp16.engine" % gpuName,
|
||||||
# '../weights/pth/AIlib2/%s/stdc_360X640.pth' % modeType.value[3]
|
|
||||||
'Segweights': '../weights/trt/AIlib2/drowning/stdc_360X640_%s_fp16.engine' % gpuName
|
'Segweights': '../weights/trt/AIlib2/drowning/stdc_360X640_%s_fp16.engine' % gpuName
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -514,7 +505,7 @@ class ModelType(Enum):
|
||||||
|
|
||||||
CITYROAD_MODEL = ("20", "020", "城市公路模型", 'cityRoad', lambda device, gpuName: {
|
CITYROAD_MODEL = ("20", "020", "城市公路模型", 'cityRoad', lambda device, gpuName: {
|
||||||
'device': device,
|
'device': device,
|
||||||
'labelnames': ["护栏", "交通标志", "非交通标志", "施工", "施工"],
|
'labelnames': ["护栏", "交通标志", "非交通标志", "施工锥桶", "施工水马"],
|
||||||
'trtFlag_seg': False,
|
'trtFlag_seg': False,
|
||||||
'trtFlag_det': True,
|
'trtFlag_det': True,
|
||||||
'slopeIndex': [],
|
'slopeIndex': [],
|
||||||
|
|
@ -574,14 +565,12 @@ class ModelType(Enum):
|
||||||
}},
|
}},
|
||||||
'models':[
|
'models':[
|
||||||
{
|
{
|
||||||
#'weight':'../weights/pth/AIlib2/channel2/yolov5.pt',
|
|
||||||
'weight':'../weights/trt/AIlib2/channel2/yolov5_%s_fp16.engine'%(gpuName),
|
'weight':'../weights/trt/AIlib2/channel2/yolov5_%s_fp16.engine'%(gpuName),
|
||||||
'name':'yolov5',
|
'name':'yolov5',
|
||||||
'model':yolov5Model,
|
'model':yolov5Model,
|
||||||
'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.1,'iou_thres':0.45,'allowedList':list(range(20)),'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.7,"1":0.7,"2":0.8,"3":0.6} }
|
'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.1,'iou_thres':0.45,'allowedList':list(range(20)),'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.7,"1":0.7,"2":0.8,"3":0.6} }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
# 'weight' : '../weights/trt/AIlib2/ocr2/crnn_ch_4090_fp16_192X32.engine',
|
|
||||||
'weight' : '../weights/pth/AIlib2/ocr2/crnn_ch.pth',
|
'weight' : '../weights/pth/AIlib2/ocr2/crnn_ch.pth',
|
||||||
'name':'ocr',
|
'name':'ocr',
|
||||||
'model':ocrModel,
|
'model':ocrModel,
|
||||||
|
|
@ -640,14 +629,10 @@ class ModelType(Enum):
|
||||||
"classes": 5,
|
"classes": 5,
|
||||||
"rainbows": COLOR
|
"rainbows": COLOR
|
||||||
},
|
},
|
||||||
# "../weights/pth/AIlib2/%s/yolov5.pt" % modeType.value[3]
|
|
||||||
'Detweights': "../weights/trt/AIlib2/riverT/yolov5_%s_fp16.engine" % gpuName,
|
'Detweights': "../weights/trt/AIlib2/riverT/yolov5_%s_fp16.engine" % gpuName,
|
||||||
# '../weights/pth/AIlib2/%s/stdc_360X640.pth' % modeType.value[3]
|
|
||||||
'Segweights': '../weights/trt/AIlib2/riverT/stdc_360X640_%s_fp16.engine' % gpuName
|
'Segweights': '../weights/trt/AIlib2/riverT/stdc_360X640_%s_fp16.engine' % gpuName
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FORESTCROWD_FARM_MODEL = ("26", "026", "森林人群模型", 'forestCrowd', lambda device, gpuName: {
|
FORESTCROWD_FARM_MODEL = ("26", "026", "森林人群模型", 'forestCrowd', lambda device, gpuName: {
|
||||||
'labelnames': ["林斑", "病死树", "行人", "火焰", "烟雾","人群"],
|
'labelnames': ["林斑", "病死树", "行人", "火焰", "烟雾","人群"],
|
||||||
'postProcess':{'function':gather_post_process,'pars':{'pedestrianId':2,'crowdThreshold':4,'gatherId':5,'distancePersonScale':2.0}},
|
'postProcess':{'function':gather_post_process,'pars':{'pedestrianId':2,'crowdThreshold':4,'gatherId':5,'distancePersonScale':2.0}},
|
||||||
|
|
@ -678,7 +663,8 @@ class ModelType(Enum):
|
||||||
})
|
})
|
||||||
TRAFFICFORDSJ_FARM_MODEL = ("27", "027", "交通模型-大数据局", 'highWay2T', lambda device, gpuName: {
|
TRAFFICFORDSJ_FARM_MODEL = ("27", "027", "交通模型-大数据局", 'highWay2T', lambda device, gpuName: {
|
||||||
'device': str(device),
|
'device': str(device),
|
||||||
'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水", "影子", "事故", "桥梁外观","设施破损缺失","龙门架","防抛网","标识牌损坏","护栏损坏","钢筋裸露" ],
|
'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水", "影子",
|
||||||
|
"事故", "桥梁外观","设施破损缺失","龙门架","防抛网","标识牌损坏","护栏损坏","钢筋裸露" ],
|
||||||
'trtFlag_seg': True,
|
'trtFlag_seg': True,
|
||||||
'trtFlag_det': True,
|
'trtFlag_det': True,
|
||||||
'seg_nclass': 3,
|
'seg_nclass': 3,
|
||||||
|
|
@ -694,12 +680,13 @@ class ModelType(Enum):
|
||||||
'function': tracfficAccidentMixFunction,
|
'function': tracfficAccidentMixFunction,
|
||||||
'pars': {
|
'pars': {
|
||||||
'modelSize': (640, 360),
|
'modelSize': (640, 360),
|
||||||
#'modelSize': (1920,1080),
|
|
||||||
'RoadArea': 16000,
|
'RoadArea': 16000,
|
||||||
'roadVehicleAngle': 15,
|
'roadVehicleAngle': 15,
|
||||||
'speedRoadVehicleAngleMax': 75,
|
'speedRoadVehicleAngleMax': 75,
|
||||||
'roundness': 1.0,
|
'roundness': 1.0,
|
||||||
'cls': 10,
|
'cls': 10,
|
||||||
|
'CarId':1,
|
||||||
|
'CthcId':1,
|
||||||
'vehicleFactor': 0.1,
|
'vehicleFactor': 0.1,
|
||||||
'confThres': 0.25,
|
'confThres': 0.25,
|
||||||
'roadIou': 0.6,
|
'roadIou': 0.6,
|
||||||
|
|
@ -785,26 +772,24 @@ class ModelType(Enum):
|
||||||
'labelnames': ["抛洒物","车辆"],
|
'labelnames': ["抛洒物","车辆"],
|
||||||
'trtFlag_seg': True,
|
'trtFlag_seg': True,
|
||||||
'trtFlag_det': True,
|
'trtFlag_det': True,
|
||||||
'seg_nclass': 2,
|
'seg_nclass': 3,
|
||||||
'segRegionCnt': 2,
|
'segRegionCnt': 2,
|
||||||
'segPar': {
|
'segPar': {
|
||||||
#'modelSize': (640, 360),
|
'modelSize': (640, 360),
|
||||||
'modelSize': (1920, 1080),
|
|
||||||
'mean': (0.485, 0.456, 0.406),
|
'mean': (0.485, 0.456, 0.406),
|
||||||
'std': (0.229, 0.224, 0.225),
|
'std': (0.229, 0.224, 0.225),
|
||||||
'predResize': True,
|
'predResize': True,
|
||||||
'numpy': False,
|
'numpy': False,
|
||||||
'RGB_convert_first': True,
|
'RGB_convert_first': True,
|
||||||
'mixFunction': {
|
'mixFunction': {
|
||||||
'function': mixSpillage_postprocess,
|
'function': mixTraffic_postprocess,
|
||||||
'pars': {
|
'pars': {
|
||||||
#'modelSize': (640, 360),
|
'modelSize': (640, 360),
|
||||||
'modelSize': (1920,1080),
|
|
||||||
'RoadArea': 16000,
|
'RoadArea': 16000,
|
||||||
'roadVehicleAngle': 15,
|
'roadVehicleAngle': 15,
|
||||||
'speedRoadVehicleAngleMax': 75,
|
'speedRoadVehicleAngleMax': 75,
|
||||||
'roundness': 1.0,
|
'roundness': 1.0,
|
||||||
'cls': 1,
|
'cls': 0,
|
||||||
'vehicleFactor': 0.1,
|
'vehicleFactor': 0.1,
|
||||||
'confThres': 0.25,
|
'confThres': 0.25,
|
||||||
'roadIou': 0.6,
|
'roadIou': 0.6,
|
||||||
|
|
@ -832,26 +817,24 @@ class ModelType(Enum):
|
||||||
'labelnames': ["危化品","罐体","危险标识","普通车"],
|
'labelnames': ["危化品","罐体","危险标识","普通车"],
|
||||||
'trtFlag_seg': True,
|
'trtFlag_seg': True,
|
||||||
'trtFlag_det': True,
|
'trtFlag_det': True,
|
||||||
'seg_nclass': 2,
|
'seg_nclass': 3,
|
||||||
'segRegionCnt': 2,
|
'segRegionCnt': 2,
|
||||||
'segPar': {
|
'segPar': {
|
||||||
#'modelSize': (640, 360),
|
'modelSize': (640, 360),
|
||||||
'modelSize': (1920, 1080),
|
|
||||||
'mean': (0.485, 0.456, 0.406),
|
'mean': (0.485, 0.456, 0.406),
|
||||||
'std': (0.229, 0.224, 0.225),
|
'std': (0.229, 0.224, 0.225),
|
||||||
'predResize': True,
|
'predResize': True,
|
||||||
'numpy': False,
|
'numpy': False,
|
||||||
'RGB_convert_first': True,
|
'RGB_convert_first': True,
|
||||||
'mixFunction': {
|
'mixFunction': {
|
||||||
'function': mixCthc_postprocess,
|
'function': mixTraffic_postprocess,
|
||||||
'pars': {
|
'pars': {
|
||||||
#'modelSize': (640, 360),
|
'modelSize': (640, 360),
|
||||||
'modelSize': (1920,1080),
|
|
||||||
'RoadArea': 16000,
|
'RoadArea': 16000,
|
||||||
'roadVehicleAngle': 15,
|
'roadVehicleAngle': 15,
|
||||||
'speedRoadVehicleAngleMax': 75,
|
'speedRoadVehicleAngleMax': 75,
|
||||||
'roundness': 1.0,
|
'roundness': 1.0,
|
||||||
'cls': 4,
|
'cls': 0,
|
||||||
'vehicleFactor': 0.1,
|
'vehicleFactor': 0.1,
|
||||||
'confThres': 0.25,
|
'confThres': 0.25,
|
||||||
'roadIou': 0.6,
|
'roadIou': 0.6,
|
||||||
|
|
@ -865,7 +848,7 @@ class ModelType(Enum):
|
||||||
"name": "post_process",
|
"name": "post_process",
|
||||||
"conf_thres": 0.25,
|
"conf_thres": 0.25,
|
||||||
"iou_thres": 0.25,
|
"iou_thres": 0.25,
|
||||||
"classes": 1,
|
"classes": 4,
|
||||||
"rainbows": COLOR
|
"rainbows": COLOR
|
||||||
},
|
},
|
||||||
'detModelpara': [{"id": str(x), "config": {"k1": "v1", "k2": "v2"}} for x in [0]],
|
'detModelpara': [{"id": str(x), "config": {"k1": "v1", "k2": "v2"}} for x in [0]],
|
||||||
|
|
@ -896,15 +879,26 @@ class ModelType(Enum):
|
||||||
})
|
})
|
||||||
|
|
||||||
CITY_CARPLATE_MODEL = ("30", "301", "自研车牌检测", 'carplate', lambda device, gpuName: {
|
CITY_CARPLATE_MODEL = ("30", "301", "自研车牌检测", 'carplate', lambda device, gpuName: {
|
||||||
|
'labelnames': ["车牌"],
|
||||||
'device': str(device),
|
'device': str(device),
|
||||||
'models':{
|
'rainbows': COLOR,
|
||||||
|
'models': [
|
||||||
{
|
{
|
||||||
'weights': '../AIlib2/weights/conf/jkm/plate_yolov5s_v3.jit',
|
'trtFlag_det': False,
|
||||||
|
'weight': '../weights/pth/AIlib2/carplate/plate_yolov5s_v3.jit',
|
||||||
|
'name': 'yolov5',
|
||||||
|
'model': yolov5Model,
|
||||||
|
'par': {
|
||||||
|
'device': 'cuda:0',
|
||||||
|
'half': False,
|
||||||
'conf_thres': 0.4,
|
'conf_thres': 0.4,
|
||||||
'iou_thres': 0.45,
|
'iou_thres': 0.45,
|
||||||
'nc': 1,
|
'nc': 1,
|
||||||
|
'plate_dilate': (0.5, 0.1)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
'trtFlag_ocr': False,
|
||||||
'weight': '../weights/pth/AIlib2/ocr2/crnn_ch.pth',
|
'weight': '../weights/pth/AIlib2/ocr2/crnn_ch.pth',
|
||||||
'name': 'ocr',
|
'name': 'ocr',
|
||||||
'model': ocrModel,
|
'model': ocrModel,
|
||||||
|
|
@ -919,11 +913,10 @@ class ModelType(Enum):
|
||||||
'std': [0.5, 0.5, 0.5],
|
'std': [0.5, 0.5, 0.5],
|
||||||
'dynamic': False,
|
'dynamic': False,
|
||||||
}
|
}
|
||||||
},
|
}],
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
CITY_INFRAREDPERSON_MODEL = ("30", "302", "红外行人模型", 'infraredperson', lambda device, gpuName: {
|
CITY_INFRAREDPERSON_MODEL = ("30", "302", "红外行人模型", 'infraredPerson', lambda device, gpuName: {
|
||||||
'labelnames': ["行人"],
|
'labelnames': ["行人"],
|
||||||
'postProcess': {'function': default_mix, 'pars': {}},
|
'postProcess': {'function': default_mix, 'pars': {}},
|
||||||
'models':
|
'models':
|
||||||
|
|
@ -965,6 +958,86 @@ class ModelType(Enum):
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
CITY_DENSECROWDCOUNT_MODEL = ("30", "304", "密集人群计数", 'DenseCrowdCount', lambda device, gpuName: {
|
||||||
|
'labelnames': ["人群计数"],
|
||||||
|
'device': str(device),
|
||||||
|
'rainbows': COLOR,
|
||||||
|
'models': [
|
||||||
|
{
|
||||||
|
'trtFlag_det': False,
|
||||||
|
'weight': "../weights/pth/AIlib2/DenseCrowd/SHTechA.pth", ###检测模型路径
|
||||||
|
'vggweight': "../weights/pth/AIlib2/DenseCrowd/vgg16_bn-6c64b313.pth", ###检测模型路径
|
||||||
|
'name': 'p2pnet',
|
||||||
|
'model': p2NnetModel,
|
||||||
|
'par': {
|
||||||
|
'device': 'cuda:0',
|
||||||
|
'row': 2,
|
||||||
|
'line': 2,
|
||||||
|
'point_loss_coef': 0.45,
|
||||||
|
'conf': 0.50,
|
||||||
|
'gpu_id': 0,
|
||||||
|
'eos_coef': '0.5',
|
||||||
|
'set_cost_class': 1,
|
||||||
|
'set_cost_point': 0.05,
|
||||||
|
'backbone': 'vgg16_bn'
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
})
|
||||||
|
|
||||||
|
CITY_DENSECROWDESTIMATION_MODEL = ("30", "305", "密集人群密度估计", 'DenseCrowdEstimation', lambda device, gpuName: {
|
||||||
|
'labelnames': ["密度"],
|
||||||
|
'models':
|
||||||
|
[
|
||||||
|
{
|
||||||
|
'weight': "../weights/pth/AIlib2/DenseCrowd/SHTechA.pth", ###检测模型路径
|
||||||
|
'name': 'yolov5',
|
||||||
|
'model': yolov5Model,
|
||||||
|
'par': {'half': True, 'device': 'cuda:0', 'conf_thres': 0.50, 'iou_thres': 0.45,
|
||||||
|
'allowedList': list(range(20)), 'segRegionCnt': 1, 'trtFlag_det': True,
|
||||||
|
'trtFlag_seg': False, "score_byClass": {"0": 0.50, "1": 0.3, "2": 0.3, "3": 0.3}},
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
'postFile': {
|
||||||
|
"rainbows": COLOR
|
||||||
|
},
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
CITY_UNDERBUILDCOUNT_MODEL = ("30", "306", "建筑物下人群计数", 'perUnderBuild', lambda device, gpuName: {
|
||||||
|
'labelnames': ["建筑物下人群"],
|
||||||
|
'device': str(device),
|
||||||
|
'rainbows': COLOR,
|
||||||
|
'models': [
|
||||||
|
{
|
||||||
|
'weight': "../weights/trt/AIlib2/perUnderBuild/yolov5_%s_fp16.engine" % (gpuName), ###检测模型路径
|
||||||
|
'name': 'yolov5',
|
||||||
|
'model': yolov5Model,
|
||||||
|
'par': {'half': True, 'device': 'cuda:0', 'conf_thres': 0.25, 'iou_thres': 0.45,
|
||||||
|
'allowedList': [0,1,2], 'segRegionCnt': 1, 'trtFlag_det': True,
|
||||||
|
'trtFlag_seg': False, "score_byClass": {"0": 0.25, "1": 0.3, "2": 0.3, "3": 0.3}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'trtFlag_det': False,
|
||||||
|
'weight': "../weights/pth/AIlib2/DenseCrowd/SHTechA.pth", ###检测模型路径
|
||||||
|
'vggweight': "../weights/pth/AIlib2/DenseCrowd/vgg16_bn-6c64b313.pth", ###检测模型路径
|
||||||
|
'name': 'p2pnet',
|
||||||
|
'model': p2NnetModel,
|
||||||
|
'par': {
|
||||||
|
'device': 'cuda:0',
|
||||||
|
'row': 2,
|
||||||
|
'line': 2,
|
||||||
|
'point_loss_coef': 0.45,
|
||||||
|
'conf': 0.50,
|
||||||
|
'gpu_id': 0,
|
||||||
|
'eos_coef': '0.5',
|
||||||
|
'set_cost_class': 1,
|
||||||
|
'set_cost_point': 0.05,
|
||||||
|
'backbone': 'vgg16_bn'
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
})
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def checkCode(code):
|
def checkCode(code):
|
||||||
for model in ModelType:
|
for model in ModelType:
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ from util.PlotsUtils import get_label_arrays, get_label_array_dict
|
||||||
from util.TorchUtils import select_device
|
from util.TorchUtils import select_device
|
||||||
|
|
||||||
sys.path.extend(['..', '../AIlib2'])
|
sys.path.extend(['..', '../AIlib2'])
|
||||||
from AI import AI_process, AI_process_forest, get_postProcess_para, ocr_process, AI_process_N, AI_process_C
|
from AI import AI_process, AI_process_forest, get_postProcess_para, ocr_process, AI_process_N, AI_process_C,AI_process_Ocr,AI_process_Crowd
|
||||||
from stdc import stdcModel
|
from stdc import stdcModel
|
||||||
from segutils.segmodel import SegModel
|
from segutils.segmodel import SegModel
|
||||||
from models.experimental import attempt_load
|
from models.experimental import attempt_load
|
||||||
|
|
@ -46,8 +46,12 @@ class OneModel:
|
||||||
new_device = select_device(par.get('device'))
|
new_device = select_device(par.get('device'))
|
||||||
half = new_device.type != 'cpu'
|
half = new_device.type != 'cpu'
|
||||||
Detweights = par['Detweights']
|
Detweights = par['Detweights']
|
||||||
|
if par['trtFlag_det']:
|
||||||
with open(Detweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
|
with open(Detweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
|
||||||
model = runtime.deserialize_cuda_engine(f.read())
|
model = runtime.deserialize_cuda_engine(f.read())
|
||||||
|
else:
|
||||||
|
model = attempt_load(Detweights, map_location=new_device) # load FP32 model
|
||||||
|
if half: model.half()
|
||||||
par['segPar']['seg_nclass'] = par['seg_nclass']
|
par['segPar']['seg_nclass'] = par['seg_nclass']
|
||||||
Segweights = par['Segweights']
|
Segweights = par['Segweights']
|
||||||
if Segweights:
|
if Segweights:
|
||||||
|
|
@ -354,6 +358,73 @@ def im_process(args):
|
||||||
raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0],
|
raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0],
|
||||||
ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1])
|
ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1])
|
||||||
|
|
||||||
|
def immulti_process(args):
|
||||||
|
model_conf, frame, requestId = args
|
||||||
|
device, modelList, detpar = model_conf[1], model_conf[2], model_conf[3]
|
||||||
|
try:
|
||||||
|
# new_device = torch.device(device)
|
||||||
|
# img, padInfos = pre_process(frame, new_device)
|
||||||
|
# pred = model(img)
|
||||||
|
# boxes = post_process(pred, padInfos, device, conf_thres=pardet['conf_thres'],
|
||||||
|
# iou_thres=pardet['iou_thres'], nc=pardet['nc']) # 后处理
|
||||||
|
return AI_process_Ocr([frame], modelList, device, detpar)
|
||||||
|
except ServiceException as s:
|
||||||
|
raise s
|
||||||
|
except Exception:
|
||||||
|
logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), requestId)
|
||||||
|
raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0],
|
||||||
|
ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1])
|
||||||
|
|
||||||
|
class CARPLATEModel:
|
||||||
|
__slots__ = "model_conf"
|
||||||
|
def __init__(self, device, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None,
|
||||||
|
env=None):
|
||||||
|
try:
|
||||||
|
logger.info("########################加载{}########################, requestId:{}", modeType.value[2],
|
||||||
|
requestId)
|
||||||
|
par = modeType.value[4](str(device), gpu_name)
|
||||||
|
modelList=[ modelPar['model'](weights=modelPar['weight'],par=modelPar['par']) for modelPar in par['models'] ]
|
||||||
|
detpar = par['models'][0]['par']
|
||||||
|
# new_device = torch.device(par['device'])
|
||||||
|
# modelList=[ modelPar['model'](weights=modelPar['weight'],par=modelPar['par']) for modelPar in par['models'] ]
|
||||||
|
logger.info("########################加载 plate_yolov5s_v3.jit 成功 ########################, requestId:{}",
|
||||||
|
requestId)
|
||||||
|
self.model_conf = (modeType, device, modelList, detpar, par['rainbows'])
|
||||||
|
except Exception:
|
||||||
|
logger.error("模型加载异常:{}, requestId:{}", format_exc(), requestId)
|
||||||
|
raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0],
|
||||||
|
ExceptionType.MODEL_LOADING_EXCEPTION.value[1])
|
||||||
|
|
||||||
|
|
||||||
|
class DENSECROWDCOUNTModel:
|
||||||
|
__slots__ = "model_conf"
|
||||||
|
|
||||||
|
def __init__(self, device, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None, env=None):
|
||||||
|
try:
|
||||||
|
logger.info("########################加载{}########################, requestId:{}", modeType.value[2],
|
||||||
|
requestId)
|
||||||
|
par = modeType.value[4](str(device), gpu_name)
|
||||||
|
rainbows = par["rainbows"]
|
||||||
|
models=[ modelPar['model'](weights=modelPar['weight'],par=modelPar['par']) for modelPar in par['models'] ]
|
||||||
|
postPar = [pp['par'] for pp in par['models']]
|
||||||
|
self.model_conf = (modeType, device, models, postPar, rainbows)
|
||||||
|
except Exception:
|
||||||
|
logger.error("模型加载异常:{}, requestId:{}", format_exc(), requestId)
|
||||||
|
raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0],
|
||||||
|
ExceptionType.MODEL_LOADING_EXCEPTION.value[1])
|
||||||
|
|
||||||
|
def cc_process(args):
|
||||||
|
model_conf, frame, requestId = args
|
||||||
|
device, model, postPar = model_conf[1], model_conf[2], model_conf[3]
|
||||||
|
try:
|
||||||
|
return AI_process_Crowd([frame], model, device, postPar)
|
||||||
|
except ServiceException as s:
|
||||||
|
raise s
|
||||||
|
except Exception:
|
||||||
|
logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), requestId)
|
||||||
|
raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0],
|
||||||
|
ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1])
|
||||||
|
|
||||||
|
|
||||||
# 百度AI图片识别模型
|
# 百度AI图片识别模型
|
||||||
class BaiduAiImageModel:
|
class BaiduAiImageModel:
|
||||||
|
|
@ -608,8 +679,8 @@ MODEL_CONFIG = {
|
||||||
),
|
),
|
||||||
# 加载交通模型
|
# 加载交通模型
|
||||||
ModelType.TRAFFICFORDSJ_FARM_MODEL.value[1]: (
|
ModelType.TRAFFICFORDSJ_FARM_MODEL.value[1]: (
|
||||||
lambda x, y, r, t, z, h: OneModel(x, y, r, ModelType.TRAFFIC_FARM_MODEL, t, z, h),
|
lambda x, y, r, t, z, h: OneModel(x, y, r, ModelType.TRAFFICFORDSJ_FARM_MODEL, t, z, h),
|
||||||
ModelType.TRAFFIC_FARM_MODEL,
|
ModelType.TRAFFICFORDSJ_FARM_MODEL,
|
||||||
lambda x, y, z: one_label(x, y, z),
|
lambda x, y, z: one_label(x, y, z),
|
||||||
lambda x: model_process(x)
|
lambda x: model_process(x)
|
||||||
),
|
),
|
||||||
|
|
@ -657,6 +728,13 @@ MODEL_CONFIG = {
|
||||||
lambda x, y, z: one_label(x, y, z),
|
lambda x, y, z: one_label(x, y, z),
|
||||||
lambda x: detSeg_demo2(x)
|
lambda x: detSeg_demo2(x)
|
||||||
),
|
),
|
||||||
|
# 加载自研车牌检测模型
|
||||||
|
ModelType.CITY_CARPLATE_MODEL.value[1]: (
|
||||||
|
lambda x, y, r, t, z, h: CARPLATEModel(x, y, r, ModelType.CITY_CARPLATE_MODEL, t, z, h),
|
||||||
|
ModelType.CITY_CARPLATE_MODEL,
|
||||||
|
None,
|
||||||
|
lambda x: immulti_process(x)
|
||||||
|
),
|
||||||
# 加载红外行人检测模型
|
# 加载红外行人检测模型
|
||||||
ModelType.CITY_INFRAREDPERSON_MODEL.value[1]: (
|
ModelType.CITY_INFRAREDPERSON_MODEL.value[1]: (
|
||||||
lambda x, y, r, t, z, h: cityManagementModel(x, y, r, ModelType.CITY_INFRAREDPERSON_MODEL, t, z, h),
|
lambda x, y, r, t, z, h: cityManagementModel(x, y, r, ModelType.CITY_INFRAREDPERSON_MODEL, t, z, h),
|
||||||
|
|
@ -671,4 +749,18 @@ MODEL_CONFIG = {
|
||||||
lambda x, y, z: one_label(x, y, z),
|
lambda x, y, z: one_label(x, y, z),
|
||||||
lambda x: detSeg_demo2(x)
|
lambda x: detSeg_demo2(x)
|
||||||
),
|
),
|
||||||
|
# 加载密集人群计数检测模型
|
||||||
|
ModelType.CITY_DENSECROWDCOUNT_MODEL.value[1]: (
|
||||||
|
lambda x, y, r, t, z, h: DENSECROWDCOUNTModel(x, y, r, ModelType.CITY_DENSECROWDCOUNT_MODEL, t, z, h),
|
||||||
|
ModelType.CITY_DENSECROWDCOUNT_MODEL,
|
||||||
|
None,
|
||||||
|
lambda x: cc_process(x)
|
||||||
|
),
|
||||||
|
# 加载建筑物下行人检测模型
|
||||||
|
ModelType.CITY_UNDERBUILDCOUNT_MODEL.value[1]: (
|
||||||
|
lambda x, y, r, t, z, h: DENSECROWDCOUNTModel(x, y, r, ModelType.CITY_UNDERBUILDCOUNT_MODEL, t, z, h),
|
||||||
|
ModelType.CITY_UNDERBUILDCOUNT_MODEL,
|
||||||
|
None,
|
||||||
|
lambda x: cc_process(x)
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
from loguru import logger
|
||||||
FONT_PATH = "../AIlib2/conf/platech.ttf"
|
FONT_PATH = "../AIlib2/conf/platech.ttf"
|
||||||
|
|
||||||
zhFont = ImageFont.truetype(FONT_PATH, 20, encoding="utf-8")
|
zhFont = ImageFont.truetype(FONT_PATH, 20, encoding="utf-8")
|
||||||
|
|
@ -67,6 +68,12 @@ def xywh2xyxy2(param):
|
||||||
# return [(lt, yt), (rt, yt), (rt, yr), (lt, yr)]
|
# return [(lt, yt), (rt, yt), (rt, yr), (lt, yr)]
|
||||||
return np.asarray(param[0][0:4], np.int32), float(param[1]), int(param[2])
|
return np.asarray(param[0][0:4], np.int32), float(param[1]), int(param[2])
|
||||||
|
|
||||||
|
def xy2xyxy(box):
|
||||||
|
if not isinstance(box[0], (list, tuple, np.ndarray)):
|
||||||
|
x1, y1, x2, y2 = int(box[0]), int(box[1]), int(box[2]), int(box[3])
|
||||||
|
# 顺时针
|
||||||
|
box = [(x1, y1), (x2, y1), (x2, y2), (x1, y2)]
|
||||||
|
return box
|
||||||
|
|
||||||
def draw_painting_joint(box, img, label_array, score=0.5, color=None, config=None, isNew=False):
|
def draw_painting_joint(box, img, label_array, score=0.5, color=None, config=None, isNew=False):
|
||||||
# 识别问题描述图片的高、宽
|
# 识别问题描述图片的高、宽
|
||||||
|
|
@ -218,6 +225,11 @@ def draw_name_joint(box, img, label_array_dict, score=0.5, color=None, config=No
|
||||||
cv2.putText(img, label, p3, 0, config[3], [225, 255, 255], thickness=config[4], lineType=cv2.LINE_AA)
|
cv2.putText(img, label, p3, 0, config[3], [225, 255, 255], thickness=config[4], lineType=cv2.LINE_AA)
|
||||||
return img, box
|
return img, box
|
||||||
|
|
||||||
|
def draw_name_ocr(box, img, color, line_thickness=2, outfontsize=40):
|
||||||
|
font = ImageFont.truetype(FONT_PATH, outfontsize, encoding='utf-8')
|
||||||
|
# (color=None, label=None, font=None, fontSize=40, unify=False)
|
||||||
|
label_zh = get_label_array(color, box[0], font, outfontsize)
|
||||||
|
return plot_one_box_auto(box[1], img, color, line_thickness, label_zh)
|
||||||
|
|
||||||
def filterBox(det0, det1, pix_dis):
|
def filterBox(det0, det1, pix_dis):
|
||||||
# det0为 (m1, 11) 矩阵
|
# det0为 (m1, 11) 矩阵
|
||||||
|
|
@ -256,3 +268,100 @@ def filterBox(det0, det1, pix_dis):
|
||||||
res = np.sum(mask, axis=1)
|
res = np.sum(mask, axis=1)
|
||||||
det0_copy[..., -1] = res
|
det0_copy[..., -1] = res
|
||||||
return det0_copy
|
return det0_copy
|
||||||
|
|
||||||
|
def plot_one_box_auto(box, img, color=None, line_thickness=2, label_array=None):
|
||||||
|
# print("省略 :%s, box:%s"%('+++' * 10, box))
|
||||||
|
# 识别问题描述图片的高、宽
|
||||||
|
lh, lw = label_array.shape[0:2]
|
||||||
|
# print("省略 :%s, lh:%s, lw:%s"%('+++' * 10, lh, lw))
|
||||||
|
# 图片的长度和宽度
|
||||||
|
imh, imw = img.shape[0:2]
|
||||||
|
box = xy2xyxy(box)
|
||||||
|
# 框框左上的位置
|
||||||
|
x0, y1 = box[0][0], box[0][1]
|
||||||
|
# print("省略 :%s, x0:%s, y1:%s"%('+++' * 10, x0, y1))
|
||||||
|
x1, y0 = x0 + lw, y1 - lh
|
||||||
|
# 如果y0小于0, 说明超过上边框
|
||||||
|
if y0 < 0:
|
||||||
|
y0 = 0
|
||||||
|
# y1等于文字高度
|
||||||
|
y1 = y0 + lh
|
||||||
|
# 如果y1框框的高大于图片高度
|
||||||
|
if y1 > imh:
|
||||||
|
# y1等于图片高度
|
||||||
|
y1 = imh
|
||||||
|
# y0等于y1减去文字高度
|
||||||
|
y0 = y1 - lh
|
||||||
|
# 如果x0小于0
|
||||||
|
if x0 < 0:
|
||||||
|
x0 = 0
|
||||||
|
x1 = x0 + lw
|
||||||
|
if x1 > imw:
|
||||||
|
x1 = imw
|
||||||
|
x0 = x1 - lw
|
||||||
|
# box_tl = max(int(round(imw / 1920 * 3)), 1) or round(0.002 * (imh + imw) / 2) + 1
|
||||||
|
'''
|
||||||
|
1. img(array) 为ndarray类型(可以为cv.imread)直接读取的数据
|
||||||
|
2. box(array):为所画多边形的顶点坐标
|
||||||
|
3. 所画四边形是否闭合,通常为True
|
||||||
|
4. color(tuple):BGR三个通道的值
|
||||||
|
5. thickness(int):画线的粗细
|
||||||
|
6. shift:顶点坐标中小数的位数
|
||||||
|
'''
|
||||||
|
# Plots one bounding box on image img
|
||||||
|
tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1 # line/font thickness
|
||||||
|
box1 = np.asarray(box, np.int32)
|
||||||
|
cv2.polylines(img, [box1], True, color, tl)
|
||||||
|
img[y0:y1, x0:x1, :] = label_array
|
||||||
|
|
||||||
|
return img, box
|
||||||
|
|
||||||
|
|
||||||
|
def draw_name_crowd(dets, img, color, line_thickness=2, outfontsize=20):
|
||||||
|
font = ImageFont.truetype(FONT_PATH, outfontsize, encoding='utf-8')
|
||||||
|
if len(dets) == 1:
|
||||||
|
label = '当前人数:%d'%len(dets[0])
|
||||||
|
detP = dets[0]
|
||||||
|
for p in detP:
|
||||||
|
img = cv2.circle(img, (int(p[0]), int(p[1])), line_thickness, color, -1)
|
||||||
|
label_arr = get_label_array(color, label, font, outfontsize)
|
||||||
|
lh, lw = label_arr.shape[0:2]
|
||||||
|
img[0:lh, 0:lw, :] = label_arr
|
||||||
|
elif len(dets) == 2:
|
||||||
|
detP = dets[1]
|
||||||
|
for p in detP:
|
||||||
|
img = cv2.circle(img, (int(p[0]), int(p[1])), line_thickness, color, -1)
|
||||||
|
|
||||||
|
detM = dets[0]
|
||||||
|
h, w = img.shape[:2]
|
||||||
|
for b in detM:
|
||||||
|
label = '该建筑下行人及数量:%d'%(int(b[4]))
|
||||||
|
label_arr = get_label_array(color, label, font, outfontsize)
|
||||||
|
lh, lw = label_arr.shape[0:2]
|
||||||
|
# 框框左上的位置
|
||||||
|
x0, y1 = int(b[0]), int(b[1])
|
||||||
|
# print("省略 :%s, x0:%s, y1:%s"%('+++' * 10, x0, y1))
|
||||||
|
x1, y0 = x0 + lw, y1 - lh
|
||||||
|
# 如果y0小于0, 说明超过上边框
|
||||||
|
if y0 < 0:
|
||||||
|
y0 = 0
|
||||||
|
# y1等于文字高度
|
||||||
|
y1 = y0 + lh
|
||||||
|
# 如果y1框框的高大于图片高度
|
||||||
|
if y1 > h:
|
||||||
|
# y1等于图片高度
|
||||||
|
y1 = h
|
||||||
|
# y0等于y1减去文字高度
|
||||||
|
y0 = y1 - lh
|
||||||
|
# 如果x0小于0
|
||||||
|
if x0 < 0:
|
||||||
|
x0 = 0
|
||||||
|
x1 = x0 + lw
|
||||||
|
if x1 > w:
|
||||||
|
x1 = w
|
||||||
|
x0 = x1 - lw
|
||||||
|
|
||||||
|
cv2.polylines(img, [np.asarray(xy2xyxy(b), np.int32)], True, (0, 128, 255), 2)
|
||||||
|
img[y0:y1, x0:x1, :] = label_arr
|
||||||
|
|
||||||
|
return img, dets
|
||||||
Loading…
Reference in New Issue