diff --git a/concurrency/FileUploadThread.py b/concurrency/FileUploadThread.py index f328e53..1be5139 100644 --- a/concurrency/FileUploadThread.py +++ b/concurrency/FileUploadThread.py @@ -8,32 +8,32 @@ from loguru import logger import cv2 from entity.FeedBack import message_feedback from enums.ExceptionEnum import ExceptionType +from enums.ModelTypeEnum import ModelType from exception.CustomerException import ServiceException from util.AliyunSdk import AliyunOssSdk from util.MinioSdk import MinioSdk from util import TimeUtils 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 import io from util.LocationUtils import locate_byMqtt + 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') def __init__(self, *args): super().__init__() - self._fb_queue, self._context, self._msg, self._image_queue, self._analyse_type,self._mqtt_list = args + self._fb_queue, self._context, self._msg, self._image_queue, self._analyse_type, self._mqtt_list = args self._storage_source = self._context['service']['storage_source'] - self._algStatus = False # 默认关闭 - + self._algStatus = False # 默认关闭 + # self._algStatus = True # 默认关闭 - self._algSwitch = self._context['service']['algSwitch'] - - - - #0521: - default_enabled = str(self._msg.get("defaultEnabled", "True")).lower() == "true" + self._algSwitch = self._context['service']['algSwitch'] + + # 0521: + default_enabled = str(self._msg.get("defaultEnabled", "True")).lower() == "true" if default_enabled: print("执行默认程序(defaultEnabled=True)") self._algSwitch = True @@ -42,24 +42,16 @@ class FileUpload(Thread): print("执行替代程序(defaultEnabled=False)") # 这里放非默认逻辑的代码 self._algSwitch = False - - print("---line46 :FileUploadThread.py---",self._algSwitch) - - - - - - - - - - -#如果任务是在线、离线处理,则用此类 + + print("---line46 :FileUploadThread.py---", self._algSwitch) + + +# 如果任务是在线、离线处理,则用此类 class ImageFileUpload(FileUpload): __slots__ = () - #@staticmethod - def handle_image(self,frame_msg, frame_step): + # @staticmethod + def handle_image(self, frame_msg, frame_step): # (high_score_image["code"], all_frames, draw_config["font_config"]) # high_score_image["code"][code][cls] = (frame, frame_index_list[i], cls_list) det_xywh, frame, current_frame, all_frames, font_config = frame_msg @@ -72,9 +64,8 @@ class ImageFileUpload(FileUpload): 模型编号:modeCode 检测目标:detectTargetCode ''' - print('*'*100,' mqtt_list:',len(self._mqtt_list)) + print('*' * 100, ' mqtt_list:', len(self._mqtt_list)) - model_info = [] # 更加模型编码解析数据 for code, det_list in det_xywh.items(): @@ -83,15 +74,25 @@ class ImageFileUpload(FileUpload): if len(target_list) > 0: aFrame = frame.copy() for target in target_list: - draw_painting_joint(target[1], aFrame, target[3], target[2], target[4], font_config, target[5]) - igH,igW = aFrame.shape[0:2] - if len(self._mqtt_list)>=1: - #camParas = self._mqtt_list[0]['data'] + # 自研车牌模型判断 + 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] + if len(self._mqtt_list) >= 1: + # camParas = self._mqtt_list[0]['data'] camParas = self._mqtt_list[0] - gps = locate_byMqtt(target[1],igW,igH,camParas,outFormat='wgs84') + gps = locate_byMqtt(target[1], igW, igH, camParas, outFormat='wgs84') else: - gps=[None,None] - model_info.append({"modelCode": str(code), "detectTargetCode": str(cls), "aFrame": aFrame,'gps':gps}) + gps = [None, None] + model_info.append( + {"modelCode": str(code), "detectTargetCode": str(cls), "aFrame": aFrame, 'gps': gps}) if len(model_info) > 0: image_result = { "or_frame": frame, @@ -110,13 +111,15 @@ class ImageFileUpload(FileUpload): image_queue, fb_queue, analyse_type = self._image_queue, self._fb_queue, self._analyse_type service_timeout = int(service["timeout"]) frame_step = int(service["filter"]["frame_step"]) + 120 - if msg['taskType']==0: self._algStatus = False - else: self._algStatus = True + if msg['taskType'] == 0: + self._algStatus = False + else: + self._algStatus = True try: with ThreadPoolExecutor(max_workers=2) as t: # 初始化oss客户端 - if self._storage_source==1: - minioSdk = MinioSdk(base_dir, env, request_id ) + if self._storage_source == 1: + minioSdk = MinioSdk(base_dir, env, request_id) else: aliyunOssSdk = AliyunOssSdk(base_dir, env, request_id) start_time = time() @@ -130,15 +133,17 @@ class ImageFileUpload(FileUpload): # 获取队列中的消息 image_msg = get_no_block_queue(image_queue) if image_msg is not None: - + if image_msg[0] == 2: - logger.info("图片上传线程收到命令:{}, requestId: {}",image_msg[1] ,request_id) + logger.info("图片上传线程收到命令:{}, requestId: {}", image_msg[1], request_id) if 'stop' == image_msg[1]: logger.info("开始停止图片上传线程, requestId:{}", request_id) break - if 'algStart' == image_msg[1]: self._algStatus = True; logger.info("图片上传线程,执行算法开启命令, requestId:{}", request_id) - if 'algStop' == image_msg[1]: self._algStatus = False; logger.info("图片上传线程,执行算法关闭命令, requestId:{}", request_id) - + if 'algStart' == image_msg[1]: self._algStatus = True; logger.info( + "图片上传线程,执行算法开启命令, requestId:{}", request_id) + if 'algStop' == image_msg[1]: self._algStatus = False; logger.info( + "图片上传线程,执行算法关闭命令, requestId:{}", request_id) + if image_msg[0] == 1: image_result = self.handle_image(image_msg[1], frame_step) if image_result is not None: @@ -148,8 +153,8 @@ class ImageFileUpload(FileUpload): image_result["last_frame"], analyse_type, "OR", "0", "0", request_id) - if self._storage_source==1: - or_future = t.submit(minioSdk.put_object, or_image,or_image_name) + if self._storage_source == 1: + or_future = t.submit(minioSdk.put_object, or_image, or_image_name) else: or_future = t.submit(aliyunOssSdk.put_object, or_image_name, or_image.tobytes()) task.append(or_future) @@ -164,38 +169,38 @@ class ImageFileUpload(FileUpload): model_info["modelCode"], model_info["detectTargetCode"], request_id) - if self._storage_source==1: + if self._storage_source == 1: ai_future = t.submit(minioSdk.put_object, ai_image, - ai_image_name) + ai_image_name) else: ai_future = t.submit(aliyunOssSdk.put_object, ai_image_name, - ai_image.tobytes()) - + ai_image.tobytes()) + task.append(ai_future) - #msg_list.append(message_feedback(request_id, + # msg_list.append(message_feedback(request_id, # AnalysisStatus.RUNNING.value, # analyse_type, "", "", "", # or_image_name, # ai_image_name, # model_info['modelCode'], # model_info['detectTargetCode'])) - remote_image_list=[] + remote_image_list = [] for tk in task: - remote_image_list.append( tk.result()) + remote_image_list.append(tk.result()) - for ii,model_info in enumerate(model_info_list): - msg_list.append( message_feedback(request_id, + for ii, model_info in enumerate(model_info_list): + msg_list.append(message_feedback(request_id, AnalysisStatus.RUNNING.value, analyse_type, "", "", "", remote_image_list[0], - remote_image_list[ii+1], + remote_image_list[ii + 1], model_info['modelCode'], model_info['detectTargetCode'], longitude=model_info['gps'][0], latitude=model_info['gps'][1], - ) ) - - if (not self._algSwitch) or ( self._algStatus and self._algSwitch): + )) + + if (not self._algSwitch) or (self._algStatus and self._algSwitch): for msg in msg_list: put_queue(fb_queue, msg, timeout=2, is_ex=False) del task, msg_list @@ -220,9 +225,9 @@ def build_image_name(*args): time_now = TimeUtils.now_date_to_str("%Y-%m-%d-%H-%M-%S") return "%s/%s_frame-%s-%s_type_%s-%s-%s-%s_%s.jpg" % (request_id, time_now, current_frame, last_frame, random_num, mode_type, modeCode, target, image_type) - -#如果任务是图像处理,则用此类 + +# 如果任务是图像处理,则用此类 class ImageTypeImageFileUpload(Thread): __slots__ = ('_fb_queue', '_context', '_image_queue', '_analyse_type', '_msg') @@ -230,6 +235,7 @@ class ImageTypeImageFileUpload(Thread): super().__init__() self._fb_queue, self._context, self._msg, self._image_queue, self._analyse_type = args self._storage_source = self._context['service']['storage_source'] + @staticmethod 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: aiFrame = copy_frame.copy() for target in target_list: - draw_painting_joint(target[1], aiFrame, target[3], target[2], target[4], font_config) - model_info.append({ - "modelCode": str(code), - "detectTargetCode": str(cls), - "frame": aiFrame - }) + # 自研车牌模型判断 + 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) + + model_info.append({ + "modelCode": str(code), + "detectTargetCode": str(cls), + "frame": aiFrame + }) + if len(model_info) > 0: image_result = { "or_frame": copy_frame, @@ -274,11 +289,11 @@ class ImageTypeImageFileUpload(Thread): with ThreadPoolExecutor(max_workers=2) as t: try: # 初始化oss客户端 - if self._storage_source==1: - minioSdk = MinioSdk(base_dir, env, request_id ) + if self._storage_source == 1: + minioSdk = MinioSdk(base_dir, env, request_id) else: aliyunOssSdk = AliyunOssSdk(base_dir, env, request_id) - + start_time = time() while True: try: @@ -299,15 +314,15 @@ class ImageTypeImageFileUpload(Thread): if det_xywh is None: ai_image_name = build_image_name(0, 0, analyse_type, "AI", result.get("modelCode"), result.get("type"), request_id) - - if self._storage_source==1: - ai_future = t.submit(minioSdk.put_object, copy_frame,ai_image_name) + + if self._storage_source == 1: + ai_future = t.submit(minioSdk.put_object, copy_frame, ai_image_name) else: ai_future = t.submit(aliyunOssSdk.put_object, ai_image_name, copy_frame) - + task.append(ai_future) remote_names.append(ai_image_name) - #msg_list.append(message_feedback(request_id, + # msg_list.append(message_feedback(request_id, # AnalysisStatus.RUNNING.value, # analyse_type, "", "", "", # image_url, @@ -318,17 +333,17 @@ class ImageTypeImageFileUpload(Thread): else: image_result = self.handle_image(det_xywh, copy_frame, font_config) if image_result: - + # 图片帧数编码 if image_url is None: or_result, or_image = cv2.imencode(".jpg", image_result.get("or_frame")) image_url_0 = build_image_name(image_result.get("current_frame"), - image_result.get("last_frame"), - analyse_type, - "OR", "0", "O", request_id) - - if self._storage_source==1: - or_future = t.submit(minioSdk.put_object, or_image,image_url_0) + image_result.get("last_frame"), + analyse_type, + "OR", "0", "O", request_id) + + if self._storage_source == 1: + or_future = t.submit(minioSdk.put_object, or_image, image_url_0) else: or_future = t.submit(aliyunOssSdk.put_object, image_url_0, or_image.tobytes()) @@ -344,14 +359,14 @@ class ImageTypeImageFileUpload(Thread): model_info.get("modelCode"), model_info.get("detectTargetCode"), request_id) - if self._storage_source==1: - ai_future = t.submit(minioSdk.put_object, ai_image, ai_image_name) - else: + if self._storage_source == 1: + ai_future = t.submit(minioSdk.put_object, ai_image, ai_image_name) + else: ai_future = t.submit(aliyunOssSdk.put_object, ai_image_name, ai_image.tobytes()) task.append(ai_future) remote_names.append(ai_image_name) - #msg_list.append(message_feedback(request_id, + # msg_list.append(message_feedback(request_id, # AnalysisStatus.RUNNING.value, # analyse_type, "", "", "", # image_url, @@ -362,9 +377,8 @@ class ImageTypeImageFileUpload(Thread): remote_url_list = [] for thread_result in task: remote_url_list.append(thread_result.result()) - - - #以下代码是为了获取图像上传后,返回的全路径地址 + + # 以下代码是为了获取图像上传后,返回的全路径地址 if det_xywh is None: msg_list.append(message_feedback(request_id, AnalysisStatus.RUNNING.value, @@ -377,12 +391,12 @@ class ImageTypeImageFileUpload(Thread): else: if image_result: if image_url is None: - for ii in range(len(remote_names)-1): + for ii in range(len(remote_names) - 1): msg_list.append(message_feedback(request_id, AnalysisStatus.RUNNING.value, analyse_type, "", "", "", remote_url_list[0], - remote_url_list[1+ii], + remote_url_list[1 + ii], model_info.get('modelCode'), model_info.get('detectTargetCode'), analyse_results=result)) @@ -394,13 +408,10 @@ class ImageTypeImageFileUpload(Thread): image_url, remote_url_list[ii], model_info_list[ii].get('modelCode'), - model_info_list[ii].get('detectTargetCode'), + model_info_list[ii].get( + 'detectTargetCode'), analyse_results=result)) - - - - for msg in msg_list: put_queue(fb_queue, msg, timeout=2, is_ex=False) else: diff --git a/concurrency/IntelligentRecognitionProcess.py b/concurrency/IntelligentRecognitionProcess.py index 7c40632..78f9aae 100644 --- a/concurrency/IntelligentRecognitionProcess.py +++ b/concurrency/IntelligentRecognitionProcess.py @@ -46,7 +46,9 @@ from util.PlotsUtils import xywh2xyxy2 from util.QueUtil import put_queue, get_no_block_queue, clear_queue from util.TimeUtils import now_date_to_str, YMDHMSF from util.CpuUtils import print_cpu_status -import inspect +import inspect + + class IntelligentRecognitionProcess(Process): __slots__ = ('_fb_queue', '_msg', '_analyse_type', '_context', 'event_queue', '_pull_queue', '_hb_queue', "_image_queue", "_push_queue", '_push_ex_queue') @@ -62,8 +64,9 @@ class IntelligentRecognitionProcess(Process): # 发送waitting消息 put_queue(self._fb_queue, message_feedback(self._msg["request_id"], AnalysisStatus.WAITING.value, self._analyse_type, progress=init_progess), timeout=2, is_ex=True) - self._storage_source = self._context['service']['storage_source'] + self._storage_source = self._context['service']['storage_source'] self._algStatus = False + def sendEvent(self, eBody): put_queue(self.event_queue, eBody, timeout=2, is_ex=True) @@ -91,9 +94,6 @@ class IntelligentRecognitionProcess(Process): hb_thread.start() return hb_thread - - - class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): __slots__ = () @@ -113,19 +113,16 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): pullProcess.start() return pullProcess - - def upload_video(self,base_dir, env, request_id, orFilePath, aiFilePath): - if self._storage_source==1: - minioSdk = MinioSdk(base_dir, env, request_id ) + def upload_video(self, base_dir, env, request_id, orFilePath, aiFilePath): + if self._storage_source == 1: + minioSdk = MinioSdk(base_dir, env, request_id) upload_video_thread_or = Common(minioSdk.put_object, orFilePath, "or_online_%s.mp4" % request_id) upload_video_thread_ai = Common(minioSdk.put_object, aiFilePath, "ai_online_%s.mp4" % request_id) - else: + else: aliyunVodSdk = ThAliyunVodSdk(base_dir, env, 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_or.setDaemon(True) upload_video_thread_ai.setDaemon(True) upload_video_thread_or.start() @@ -133,6 +130,7 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): or_url = upload_video_thread_or.get_result() ai_url = upload_video_thread_ai.get_result() return or_url, ai_url + ''' @staticmethod def upload_video(base_dir, env, request_id, orFilePath, aiFilePath): @@ -146,7 +144,7 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): or_url = upload_video_thread_or.get_result() ai_url = upload_video_thread_ai.get_result() return or_url, ai_url - ''' + ''' @staticmethod def ai_normal_dtection(model, frame, request_id): @@ -226,10 +224,10 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): ex = None # 拉流进程、推流进程、心跳线程 pull_process, push_process, hb_thread = None, None, None - + # 事件队列、拉流队列、心跳队列、反馈队列 event_queue, pull_queue, hb_queue, fb_queue = self.event_queue, self._pull_queue, self._hb_queue, self._fb_queue - + # 推流队列、推流异常队列、图片队列 push_queue, push_ex_queue, image_queue = self._push_queue, self._push_ex_queue, self._image_queue try: @@ -237,22 +235,21 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): init_log(base_dir, env) # 打印启动日志 logger.info("开始启动实时分析进程!requestId: {}", request_id) - + # 启动拉流进程(包含拉流线程, 图片上传线程,mqtt读取线程) # 拉流进程初始化时间长, 先启动 pull_process = self.start_pull_stream(msg, context, fb_queue, pull_queue, image_queue, analyse_type, 25) - #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, # 启动心跳线程 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) - #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 # 启动推流进程 push_process = self.start_push_stream(msg, push_queue, image_queue, push_ex_queue, hb_queue, context) - #print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) + # print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) # 第一个参数: 模型是否初始化 0:未初始化 1:初始化 # 第二个参数: 检测是否有问题 0: 没有问题, 1: 有问题 task_status = [0, 0] @@ -268,27 +265,27 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): pull_queue, request_id) # 检查推流是否异常 push_status = get_no_block_queue(push_ex_queue) - #print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) #9.5,11.2 + # print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) #9.5,11.2 if push_status is not None and push_status[0] == 1: raise ServiceException(push_status[1], push_status[2]) # 获取停止指令 event_result = get_no_block_queue(event_queue) - + if event_result: cmdStr = event_result.get("command") - #接收到算法开启、或者关闭的命令 - if cmdStr in ['algStart' , 'algStop' ]: - logger.info("发送向推流进程发送算法命令, requestId: {}, {}", request_id,cmdStr ) + # 接收到算法开启、或者关闭的命令 + if cmdStr in ['algStart', 'algStop']: + logger.info("发送向推流进程发送算法命令, requestId: {}, {}", request_id, cmdStr) put_queue(push_queue, (2, cmdStr), timeout=1, is_ex=True) pull_process.sendCommand({"command": cmdStr}) - + # 接收到停止指令 if "stop" == cmdStr: logger.info("实时任务开始停止, requestId: {}", request_id) pull_process.sendCommand({"command": 'stop'}) - #print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) + # print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) pull_result = get_no_block_queue(pull_queue) - #print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) + # print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) if pull_result is None: sleep(1) continue @@ -301,20 +298,32 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): task_status[0] = 1 for i, model in enumerate(model_array): model_conf, code = model - model_param = model_conf[1] - # (modeType, model_param, allowedList, names, rainbows) - 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'] - #print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) + 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] + # (modeType, model_param, allowedList, names, rainbows) + 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'] + + + # print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) # 多线程并发处理, 经过测试两个线程最优 det_array = [] for i, frame in enumerate(frame_list): @@ -322,11 +331,11 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): frame_index_list[i], tt, request_id) det_array.append(det_result) push_objs = [det.result() for det in det_array] - #print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) + # print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) put_queue(push_queue, (1, (frame_list, frame_index_list, all_frames, draw_config, push_objs)), timeout=2, is_ex=True) - #print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) + # print_cpu_status(requestId=request_id,lineNum=inspect.currentframe().f_lineno) del det_array, push_objs del frame_list, frame_index_list, all_frames elif pull_result[0] == 1: @@ -437,23 +446,23 @@ class OnlineIntelligentRecognitionProcess(IntelligentRecognitionProcess): class OfflineIntelligentRecognitionProcess(IntelligentRecognitionProcess): __slots__ = () - - def upload_video(self,base_dir, env, request_id, aiFilePath): + + def upload_video(self, base_dir, env, request_id, aiFilePath): aliyunVodSdk = ThAliyunVodSdk(base_dir, env, request_id) upload_video_thread_ai = Common(aliyunVodSdk.get_play_url, aiFilePath, "ai_online_%s" % request_id) - - if self._storage_source==1: - minioSdk = MinioSdk(base_dir, env, request_id ) + + if self._storage_source == 1: + minioSdk = MinioSdk(base_dir, env, request_id) upload_video_thread_ai = Common(minioSdk.put_object, aiFilePath, "ai_online_%s.mp4" % request_id) else: aliyunVodSdk = ThAliyunVodSdk(base_dir, env, request_id) upload_video_thread_ai = Common(aliyunVodSdk.get_play_url, aiFilePath, "ai_online_%s" % request_id) - + upload_video_thread_ai.setDaemon(True) upload_video_thread_ai.start() ai_url = upload_video_thread_ai.get_result() return ai_url - + ''' @staticmethod def upload_video(base_dir, env, request_id, aiFilePath): @@ -464,6 +473,7 @@ class OfflineIntelligentRecognitionProcess(IntelligentRecognitionProcess): ai_url = upload_video_thread_ai.get_result() return ai_url ''' + @staticmethod def ai_normal_dtection(model, frame, request_id): model_conf, code = model @@ -598,11 +608,11 @@ class OfflineIntelligentRecognitionProcess(IntelligentRecognitionProcess): if "stop" == cmdStr: logger.info("离线任务开始停止, requestId: {}", request_id) pull_process.sendCommand({"command": 'stop'}) - if cmdStr in ['algStart' , 'algStop' ]: - logger.info("发送向推流进程发送算法命令, requestId: {}, {}", request_id,cmdStr ) + if cmdStr in ['algStart', 'algStop']: + logger.info("发送向推流进程发送算法命令, requestId: {}, {}", request_id, cmdStr) put_queue(push_queue, (2, cmdStr), timeout=1, is_ex=True) pull_process.sendCommand({"command": cmdStr}) - + pull_result = get_no_block_queue(pull_queue) if pull_result is None: sleep(1) @@ -616,19 +626,32 @@ class OfflineIntelligentRecognitionProcess(IntelligentRecognitionProcess): task_status[0] = 1 for i, model in enumerate(model_array): model_conf, code = model - model_param = model_conf[1] - # (modeType, model_param, allowedList, names, rainbows) - 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'] + 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] + # (modeType, model_param, allowedList, names, rainbows) + 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 = [] for i, frame in enumerate(frame_list): det_result = t.submit(self.obj_det, self, model_array, frame, task_status, @@ -745,7 +768,7 @@ class PhotosIntelligentRecognitionProcess(Process): put_queue(self._fb_queue, message_feedback(self._msg["request_id"], AnalysisStatus.WAITING.value, self._analyse_type, progress=init_progess), timeout=2, is_ex=True) self.build_logo(self._msg, self._context) - self._storage_source = self._context['service']['storage_source'] + self._storage_source = self._context['service']['storage_source'] @staticmethod def build_logo(msg, context): @@ -922,6 +945,62 @@ class PhotosIntelligentRecognitionProcess(Process): logger.error("模型分析异常: {}, requestId: {}", format_exc(), request_id) 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 +1015,26 @@ class PhotosIntelligentRecognitionProcess(Process): for r in obj_list: 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): try: model_conf, code = mod @@ -943,7 +1042,7 @@ class PhotosIntelligentRecognitionProcess(Process): image = url2Array(imageUrl) MODEL_CONFIG[code][2](image.shape[1], image.shape[0], model_conf) p_result = MODEL_CONFIG[code][3]([model_conf, image, request_id])[0] - #print(' line872:p_result[2]:',p_result[2] ) + # print(' line872:p_result[2]:',p_result[2] ) if p_result is None or len(p_result) < 3 or p_result[2] is None or len(p_result[2]) == 0: return if logo: @@ -966,7 +1065,7 @@ class PhotosIntelligentRecognitionProcess(Process): det_xywh[code][cls] = [[cls, box, score, label_array, color]] else: det_xywh[code][cls].append([cls, box, score, label_array, color]) - #print('ai_result_list:{},allowlist:{}'.format(ai_result_list,allowedList )) + # print('ai_result_list:{},allowlist:{}'.format(ai_result_list,allowedList )) if len(det_xywh) > 0: put_queue(image_queue, (1, (det_xywh, imageUrl, image, font_config, "")), timeout=2, is_ex=False) except ServiceException as s: @@ -1114,18 +1213,19 @@ class PhotosIntelligentRecognitionProcess(Process): image_thread.setDaemon(True) image_thread.start() return image_thread - def check_ImageUrl_Vaild(self,url,timeout=1): + + def check_ImageUrl_Vaild(self, url, timeout=1): try: # 发送 HTTP 请求,尝试访问图片 response = requests.get(url, timeout=timeout) # 设置超时时间为 10 秒 if response.status_code == 200: - return True,url + return True, url else: - return False,f"图片地址无效,状态码:{response.status_code}" + return False, f"图片地址无效,状态码:{response.status_code}" except requests.exceptions.RequestException as e: # 捕获请求过程中可能出现的异常(如网络问题、超时等) - return False,str(e) - + return False, str(e) + def run(self): fb_queue, msg, analyse_type, context = self._fb_queue, self._msg, self._analyse_type, self._context request_id, logo, image_queue = msg["request_id"], context['logo'], self._image_queue @@ -1133,24 +1233,23 @@ class PhotosIntelligentRecognitionProcess(Process): imageUrls = msg["image_urls"] image_thread = None init_log(base_dir, env) - valFlag=True + valFlag = True for url in imageUrls: - valFlag,ret = self.check_ImageUrl_Vaild(url,timeout=1) - + valFlag, ret = self.check_ImageUrl_Vaild(url, timeout=1) + if not valFlag: - logger.error("图片分析异常: {}, requestId:{},url:{}",ret, request_id,url) - #print("AnalysisStatus.FAILED.value:{},ExceptionType.URL_ADDRESS_ACCESS_FAILED.value[0]:{},ExceptionType.URL_ADDRESS_ACCESS_FAILED.value[1]:{}".format(AnalysisStatus.FAILED.value,ExceptionType.URL_ADDRESS_ACCESS_FAILED.value[0],ExceptionType.URL_ADDRESS_ACCESS_FAILED.value[1] ) ) + logger.error("图片分析异常: {}, requestId:{},url:{}", ret, request_id, url) + # print("AnalysisStatus.FAILED.value:{},ExceptionType.URL_ADDRESS_ACCESS_FAILED.value[0]:{},ExceptionType.URL_ADDRESS_ACCESS_FAILED.value[1]:{}".format(AnalysisStatus.FAILED.value,ExceptionType.URL_ADDRESS_ACCESS_FAILED.value[0],ExceptionType.URL_ADDRESS_ACCESS_FAILED.value[1] ) ) put_queue(fb_queue, message_feedback(request_id, AnalysisStatus.FAILED.value, - analyse_type, - ExceptionType.URL_ADDRESS_ACCESS_FAILED.value[0], - ExceptionType.URL_ADDRESS_ACCESS_FAILED.value[1]), timeout=2) - - return + analyse_type, + ExceptionType.URL_ADDRESS_ACCESS_FAILED.value[0], + ExceptionType.URL_ADDRESS_ACCESS_FAILED.value[1]), timeout=2) + return with ThreadPoolExecutor(max_workers=1) as t: try: - #init_log(base_dir, env) + # init_log(base_dir, env) logger.info("开始启动图片识别进程, requestId: {}", request_id) model_array = get_model(msg, context, analyse_type) image_thread = self.start_File_upload(fb_queue, context, msg, image_queue, analyse_type) @@ -1168,6 +1267,15 @@ class PhotosIntelligentRecognitionProcess(Process): elif model[1] == ModelType.PLATE_MODEL.value[1]: result = t.submit(self.epidemicPrevention, imageUrls, model, base_dir, env, request_id) 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: result = t.submit(self.publicIdentification, imageUrls, model, image_queue, logo, request_id) task_list.append(result) @@ -1214,7 +1322,8 @@ class ScreenRecordingProcess(Process): put_queue(self._fb_queue, recording_feedback(self._msg["request_id"], RecordingStatus.RECORDING_WAITING.value[0]), timeout=1, is_ex=True) - self._storage_source = self._context['service']['storage_source'] + self._storage_source = self._context['service']['storage_source'] + def sendEvent(self, result): put_queue(self._event_queue, result, timeout=2, is_ex=True) @@ -1380,21 +1489,19 @@ class ScreenRecordingProcess(Process): clear_queue(self._hb_queue) clear_queue(self._pull_queue) - - - - def upload_video(self,base_dir, env, request_id, orFilePath): - if self._storage_source==1: - minioSdk = MinioSdk(base_dir, env, request_id ) + def upload_video(self, base_dir, env, request_id, orFilePath): + if self._storage_source == 1: + minioSdk = MinioSdk(base_dir, env, request_id) upload_video_thread_ai = Common(minioSdk.put_object, aiFilePath, "%s/ai_online.mp4" % request_id) else: aliyunVodSdk = ThAliyunVodSdk(base_dir, env, request_id) upload_video_thread_ai = Common(aliyunVodSdk.get_play_url, aiFilePath, "ai_online_%s" % request_id) - + upload_video_thread_ai.setDaemon(True) upload_video_thread_ai.start() or_url = upload_video_thread_ai.get_result() return or_url + ''' @staticmethod def upload_video(base_dir, env, request_id, orFilePath): @@ -1406,6 +1513,7 @@ class ScreenRecordingProcess(Process): return or_url ''' + """ "models": [{ "code": "模型编号", diff --git a/concurrency/PushVideoStreamProcess.py b/concurrency/PushVideoStreamProcess.py index d10841c..9c0577c 100644 --- a/concurrency/PushVideoStreamProcess.py +++ b/concurrency/PushVideoStreamProcess.py @@ -1,4 +1,4 @@ -#ne -*- coding: utf-8 -*- +# ne -*- coding: utf-8 -*- from concurrent.futures import ThreadPoolExecutor from multiprocessing import Process @@ -23,7 +23,8 @@ from util.Cv2Utils import video_conjuncing, write_or_video, write_ai_video, push from util.ImageUtils import url2Array, add_water_pic 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 @@ -35,12 +36,11 @@ class PushStreamProcess(Process): super().__init__() # 传参 self._msg, self._push_queue, self._image_queue, self._push_ex_queue, self._hb_queue, self._context = args - self._algStatus = False # 默认关闭 - self._algSwitch = self._context['service']['algSwitch'] - - - #0521: - default_enabled = str(self._msg.get("defaultEnabled", "True")).lower() == "true" + self._algStatus = False # 默认关闭 + self._algSwitch = self._context['service']['algSwitch'] + + # 0521: + default_enabled = str(self._msg.get("defaultEnabled", "True")).lower() == "true" if default_enabled: print("执行默认程序(defaultEnabled=True)") self._algSwitch = True @@ -49,16 +49,9 @@ class PushStreamProcess(Process): print("执行替代程序(defaultEnabled=False)") # 这里放非默认逻辑的代码 self._algSwitch = False - - - print("---line53 :PushVideoStreamProcess.py---",self._algSwitch) - - - - - - - + + print("---line53 :PushVideoStreamProcess.py---", self._algSwitch) + def build_logo_url(self): logo = None if self._context["video"]["video_add_water"]: @@ -114,7 +107,7 @@ class OnPushStreamProcess(PushStreamProcess): pix_dis = 60 try: init_log(base_dir, env) - logger.info("开始实时启动推流进程!requestId:{},pid:{}, ppid:{}", request_id,os.getpid(),os.getppid()) + logger.info("开始实时启动推流进程!requestId:{},pid:{}, ppid:{}", request_id, os.getpid(), os.getppid()) with ThreadPoolExecutor(max_workers=2) as t: # 定义三种推流、写原视频流、写ai视频流策略 # 第一个参数时间, 第二个参数重试次数 @@ -139,7 +132,7 @@ class OnPushStreamProcess(PushStreamProcess): if push_r[0] == 1: frame_list, frame_index_list, all_frames, draw_config, push_objs = push_r[1] for i, frame in enumerate(frame_list): - pix_dis = int((frame.shape[0]//10)*1.2) + pix_dis = int((frame.shape[0] // 10) * 1.2) # 复制帧用来画图 copy_frame = frame.copy() det_xywh, thread_p = {}, [] @@ -152,49 +145,73 @@ class OnPushStreamProcess(PushStreamProcess): # 每个单独模型处理 # 模型编号、100帧的所有问题, 检测目标、颜色、文字图片 if len(det_result) > 0: - font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"] - rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"] + font_config, allowedList = draw_config["font_config"], draw_config[code][ + "allowedList"] + rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code][ + "label_arrays"] for qs in det_result: - try: # 应对NaN情况 - box, score, cls = xywh2xyxy2(qs) - except: - continue - if cls not in allowedList or score < frame_score: - continue - label_array, color = label_arrays[cls], rainbows[cls] - 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]) + # 自研车牌模型处理 + 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 + # crowdlabel, points = qs + 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: - rr = t.submit(draw_painting_joint, box, copy_frame, label_array, score, color, font_config) + try: # 应对NaN情况 + box, score, cls = xywh2xyxy2(qs) + except: + continue + if cls not in allowedList or score < frame_score: + continue + label_array, color = label_arrays[cls], rainbows[cls] + 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]) + else: + rr = t.submit(draw_painting_joint, box, copy_frame, label_array, + score, color, font_config) + thread_p.append(rr) if det_xywh.get(code) is None: det_xywh[code] = {} cd = det_xywh[code].get(cls) - if not (ModelType.CHANNEL2_MODEL.value[1] == str(code) and cls == 2): + if not (ModelType.CHANNEL2_MODEL.value[1] == str(code) and cls == 2) : if cd is None: det_xywh[code][cls] = [[cls, box, score, label_array, color]] else: - det_xywh[code][cls].append([cls, box, score, label_array, color]) + det_xywh[code][cls].append([cls, box, score, label_array, color]) if qs_np is None: - qs_np = np.array([box[0][0], box[0][1], box[1][0], box[1][1], - box[2][0], box[2][1], box[3][0], box[3][1], - score, cls, code],dtype=np.float32) + qs_np = np.array([box[0][0], box[0][1], box[1][0], box[1][1], + box[2][0], box[2][1], box[3][0], box[3][1], + score, cls, code], dtype=np.float32) else: - result_li = np.array([box[0][0], box[0][1], box[1][0], box[1][1], - box[2][0], box[2][1], box[3][0], box[3][1], - score, cls, code],dtype=np.float32) + result_li = np.array([box[0][0], box[0][1], box[1][0], box[1][1], + box[2][0], box[2][1], box[3][0], box[3][1], + score, cls, code], dtype=np.float32) qs_np = np.row_stack((qs_np, result_li)) - + if logo: frame = add_water_pic(frame, logo, request_id) copy_frame = add_water_pic(copy_frame, logo, request_id) if len(thread_p) > 0: for r in thread_p: r.result() - #print('----line173:',self._algSwitch,self._algStatus) + # print('----line173:',self._algSwitch,self._algStatus) if self._algSwitch and (not self._algStatus): frame_merge = video_conjuncing(frame, frame.copy()) - else: + else: frame_merge = video_conjuncing(frame, copy_frame) # 写原视频到本地 write_or_video_result = t.submit(write_or_video, frame, orFilePath, or_video_file, @@ -207,19 +224,19 @@ class OnPushStreamProcess(PushStreamProcess): # 如果有问题, 走下面的逻辑 if qs_np is not None: if len(qs_np.shape) == 1: - qs_np = qs_np[np.newaxis,...] + qs_np = qs_np[np.newaxis, ...] qs_np_id = qs_np.copy() b = np.ones(qs_np_id.shape[0]) - qs_np_id = np.column_stack((qs_np_id,b)) + qs_np_id = np.column_stack((qs_np_id, b)) if qs_np_tmp is None: if picture_similarity: qs_np_tmp = qs_np_id.copy() b = np.zeros(qs_np.shape[0]) - qs_reurn = np.column_stack((qs_np,b)) + qs_reurn = np.column_stack((qs_np, b)) else: qs_reurn = filterBox(qs_np, qs_np_tmp, pix_dis) if picture_similarity: - qs_np_tmp = np.append(qs_np_tmp,qs_np_id,axis=0) + qs_np_tmp = np.append(qs_np_tmp, qs_np_id, axis=0) qs_np_tmp[:, 11] += 1 qs_np_tmp = np.delete(qs_np_tmp, np.where((qs_np_tmp[:, 11] >= 75))[0], axis=0) has = False @@ -233,34 +250,43 @@ class OnPushStreamProcess(PushStreamProcess): if q[11] >= 1: cls = int(q[9]) if not (cls in new_lab): - continue # 为了防止其他类别被带出 + continue # 为了防止其他类别被带出 code = str(int(q[10])).zfill(3) if det_xywh2.get(code) is None: det_xywh2[code] = {} cd = det_xywh2[code].get(cls) score = q[8] - rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"] + rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code][ + "label_arrays"] label_array, color = label_arrays[cls], rainbows[cls] - box = [(int(q[0]), int(q[1])), (int(q[2]), int(q[3])), - (int(q[4]), int(q[5])), (int(q[6]), int(q[7]))] + box = [(int(q[0]), int(q[1])), (int(q[2]), int(q[3])), + (int(q[4]), int(q[5])), (int(q[6]), int(q[7]))] is_new = False if q[11] == 1: 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: - 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: - det_xywh2[code][cls].append([cls, box, score, label_array, color, is_new]) + det_xywh2[code][cls].append( + [cls, box, score, label_array, color, is_new]) if len(det_xywh2) > 0: - put_queue(image_queue, (1, [det_xywh2, frame, frame_index_list[i], all_frames, draw_config["font_config"]])) + put_queue(image_queue, (1, [det_xywh2, frame, frame_index_list[i], all_frames, + draw_config["font_config"]])) push_p = push_stream_result.result(timeout=60) ai_video_file = write_ai_video_result.result(timeout=60) or_video_file = write_or_video_result.result(timeout=60) # 接收停止指令 if push_r[0] == 2: - logger.info("拉流进程收到控制命令为:{}, requestId: {}",push_r[1] ,request_id) - if 'algStart' == push_r[1]: self._algStatus = True;logger.info("算法识别开启, requestId: {}", request_id) - if 'algStop' == push_r[1]: self._algStatus = False;logger.info("算法识别关闭, requestId: {}", request_id) + logger.info("拉流进程收到控制命令为:{}, requestId: {}", push_r[1], request_id) + if 'algStart' == push_r[1]: self._algStatus = True;logger.info( + "算法识别开启, requestId: {}", request_id) + if 'algStop' == push_r[1]: self._algStatus = False;logger.info( + "算法识别关闭, requestId: {}", request_id) if 'stop' == push_r[1]: logger.info("停止推流进程, requestId: {}", request_id) break @@ -268,7 +294,7 @@ class OnPushStreamProcess(PushStreamProcess): ex_status = False logger.info("停止推流进程, requestId: {}", request_id) break - + del push_r else: sleep(1) @@ -317,12 +343,14 @@ class OffPushStreamProcess(PushStreamProcess): picture_similarity = bool(context["service"]["filter"]["picture_similarity"]) qs_np_tmp = None pix_dis = 60 - if msg['taskType']==0: self._algStatus = False - else: self._algStatus = True + if msg['taskType'] == 0: + self._algStatus = False + else: + self._algStatus = True try: init_log(base_dir, env) logger.info("开始启动离线推流进程!requestId:{}", request_id) - with ThreadPoolExecutor(max_workers=2) as t: + with (ThreadPoolExecutor(max_workers=2) as t): # 定义三种推流、写原视频流、写ai视频流策略 # 第一个参数时间, 第二个参数重试次数 p_push_status, ai_write_status = [0, 0], [0, 0] @@ -348,8 +376,10 @@ class OffPushStreamProcess(PushStreamProcess): if push_r[0] == 1: frame_list, frame_index_list, all_frames, draw_config, push_objs = push_r[1] # 处理每一帧图片 + # 每100帧上传一次 + ncount = 0 for i, frame in enumerate(frame_list): - pix_dis = int((frame.shape[0]//10)*1.2) + pix_dis = int((frame.shape[0] // 10) * 1.2) if frame_index_list[i] % 300 == 0 and frame_index_list[i] <= all_frames: task_process = "%.2f" % (float(frame_index_list[i]) / float(all_frames)) put_queue(hb_queue, {"hb_value": task_process}, timeout=2) @@ -363,24 +393,49 @@ class OffPushStreamProcess(PushStreamProcess): qs_reurn = [] for det in push_objs[i]: code, det_result = det - + # 每个单独模型处理 # 模型编号、100帧的所有问题, 检测目标、颜色、文字图片 if len(det_result) > 0: - font_config, allowedList = draw_config["font_config"], draw_config[code]["allowedList"] - rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"] + font_config, allowedList = draw_config["font_config"], draw_config[code][ + "allowedList"] + rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code][ + "label_arrays"] for qs in det_result: - box, score, cls = xywh2xyxy2(qs) - - if cls not in allowedList or score < frame_score: - continue - label_array, color = label_arrays[cls], rainbows[cls] - 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]) + # 自研车牌模型处理 + 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: - rr = t.submit(draw_painting_joint, box, copy_frame, label_array, score, color, font_config) + box, score, cls = xywh2xyxy2(qs) + if cls not in allowedList or score < frame_score: + continue + label_array, color = label_arrays[cls], rainbows[cls] + 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]) + else: + rr = t.submit(draw_painting_joint, box, copy_frame, label_array, + score, color, font_config) + thread_p.append(rr) - + if det_xywh.get(code) is None: det_xywh[code] = {} cd = det_xywh[code].get(cls) @@ -388,17 +443,17 @@ class OffPushStreamProcess(PushStreamProcess): if cd is None: det_xywh[code][cls] = [[cls, box, score, label_array, color]] else: - det_xywh[code][cls].append([cls, box, score, label_array, color]) + det_xywh[code][cls].append([cls, box, score, label_array, color]) if qs_np is None: - qs_np = np.array([box[0][0], box[0][1], box[1][0], box[1][1], - box[2][0], box[2][1], box[3][0], box[3][1], - score, cls, code],dtype=np.float32) + qs_np = np.array([box[0][0], box[0][1], box[1][0], box[1][1], + box[2][0], box[2][1], box[3][0], box[3][1], + score, cls, code], dtype=np.float32) else: - result_li = np.array([box[0][0], box[0][1], box[1][0], box[1][1], - box[2][0], box[2][1], box[3][0], box[3][1], - score, cls, code],dtype=np.float32) + result_li = np.array([box[0][0], box[0][1], box[1][0], box[1][1], + box[2][0], box[2][1], box[3][0], box[3][1], + score, cls, code], dtype=np.float32) qs_np = np.row_stack((qs_np, result_li)) - + if logo: frame = add_water_pic(frame, logo, request_id) copy_frame = add_water_pic(copy_frame, logo, request_id) @@ -407,7 +462,7 @@ class OffPushStreamProcess(PushStreamProcess): r.result() if self._algSwitch and (not self._algStatus): frame_merge = video_conjuncing(frame, frame.copy()) - else: + else: frame_merge = video_conjuncing(frame, copy_frame) # 写识别视频到本地 write_ai_video_result = t.submit(write_ai_video, frame_merge, aiFilePath, @@ -416,22 +471,21 @@ class OffPushStreamProcess(PushStreamProcess): push_stream_result = t.submit(push_video_stream, frame_merge, push_p, push_url, p_push_status, request_id) - if qs_np is not None: if len(qs_np.shape) == 1: - qs_np = qs_np[np.newaxis,...] + qs_np = qs_np[np.newaxis, ...] qs_np_id = qs_np.copy() b = np.ones(qs_np_id.shape[0]) - qs_np_id = np.column_stack((qs_np_id,b)) + qs_np_id = np.column_stack((qs_np_id, b)) if qs_np_tmp is None: if picture_similarity: qs_np_tmp = qs_np_id.copy() b = np.zeros(qs_np.shape[0]) - qs_reurn = np.column_stack((qs_np,b)) + qs_reurn = np.column_stack((qs_np, b)) else: qs_reurn = filterBox(qs_np, qs_np_tmp, pix_dis) if picture_similarity: - qs_np_tmp = np.append(qs_np_tmp,qs_np_id,axis=0) + qs_np_tmp = np.append(qs_np_tmp, qs_np_id, axis=0) qs_np_tmp[:, 11] += 1 qs_np_tmp = np.delete(qs_np_tmp, np.where((qs_np_tmp[:, 11] >= 75))[0], axis=0) has = False @@ -446,32 +500,42 @@ class OffPushStreamProcess(PushStreamProcess): if q[11] >= 1: cls = int(q[9]) if not (cls in new_lab): - continue # 为了防止其他类别被带出 + continue # 为了防止其他类别被带出 code = str(int(q[10])).zfill(3) if det_xywh2.get(code) is None: det_xywh2[code] = {} cd = det_xywh2[code].get(cls) score = q[8] - rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code]["label_arrays"] + rainbows, label_arrays = draw_config[code]["rainbows"], draw_config[code][ + "label_arrays"] label_array, color = label_arrays[cls], rainbows[cls] - box = [(int(q[0]), int(q[1])), (int(q[2]), int(q[3])), - (int(q[4]), int(q[5])), (int(q[6]), int(q[7]))] + box = [(int(q[0]), int(q[1])), (int(q[2]), int(q[3])), + (int(q[4]), int(q[5])), (int(q[6]), int(q[7]))] is_new = False if q[11] == 1: 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: - 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: - det_xywh2[code][cls].append([cls, box, score, label_array, color, is_new]) + det_xywh2[code][cls].append( + [cls, box, score, label_array, color, is_new]) if len(det_xywh2) > 0: - put_queue(image_queue, (1, [det_xywh2, frame, frame_index_list[i], all_frames, draw_config["font_config"]])) + put_queue(image_queue, (1, [det_xywh2, frame, frame_index_list[i], all_frames, + draw_config["font_config"]])) push_p = push_stream_result.result(timeout=60) ai_video_file = write_ai_video_result.result(timeout=60) # 接收停止指令 if push_r[0] == 2: - logger.info("拉流进程收到控制命令为:{}, requestId: {}",push_r[1] ,request_id) - if 'algStart' == push_r[1]: self._algStatus = True;logger.info("算法识别开启, requestId: {}", request_id) - if 'algStop' == push_r[1]: self._algStatus = False;logger.info("算法识别关闭, requestId: {}", request_id) + logger.info("拉流进程收到控制命令为:{}, requestId: {}", push_r[1], request_id) + if 'algStart' == push_r[1]: self._algStatus = True;logger.info( + "算法识别开启, requestId: {}", request_id) + if 'algStop' == push_r[1]: self._algStatus = False;logger.info( + "算法识别关闭, requestId: {}", request_id) if 'stop' == push_r[1]: logger.info("停止推流进程, requestId: {}", request_id) break diff --git a/config/service/dsp_prod_service.yml b/config/service/dsp_prod_service.yml index 006c393..8126b0d 100644 --- a/config/service/dsp_prod_service.yml +++ b/config/service/dsp_prod_service.yml @@ -3,6 +3,7 @@ video: file_path: "../dsp/video/" # 是否添加水印 video_add_water: false +role : 1 service: filter: # 图片得分多少分以上返回图片 diff --git a/enums/ModelTypeEnum-jcq.py b/enums/ModelTypeEnum-jcq.py deleted file mode 100644 index aa7de0a..0000000 --- a/enums/ModelTypeEnum-jcq.py +++ /dev/null @@ -1,768 +0,0 @@ -import sys -from enum import Enum, unique - -from common.Constant import COLOR - -sys.path.extend(['..', '../AIlib2']) -from DMPR import DMPRModel -from DMPRUtils.jointUtil import dmpr_yolo -from segutils.segmodel import SegModel -from utilsK.queRiver import riverDetSegMixProcess -from utilsK.crowdGather import gather_post_process -from segutils.trafficUtils import tracfficAccidentMixFunction -from utilsK.drownUtils import mixDrowing_water_postprocess -from utilsK.noParkingUtils import mixNoParking_road_postprocess -from utilsK.illParkingUtils import illParking_postprocess -from stdc import stdcModel -from yolov5 import yolov5Model -from DMPRUtils.jointUtil import dmpr_yolo_stdc -from AI import default_mix -from ocr import ocrModel -from utilsK.channel2postUtils import channel2_post_process - -''' -参数说明 -1. 编号 -2. 模型编号 -3. 模型名称 -4. 选用的模型名称 -5. 模型配置 -6. 模型引用配置[Detweights文件, Segweights文件, 引用计数] -''' - - -@unique -class ModelType(Enum): - WATER_SURFACE_MODEL = ("1", "001", "河道模型", 'river', lambda device, gpuName: { - 'device': device, - 'labelnames': ["排口", "水生植被", "其它", "漂浮物", "污染排口", "菜地", "违建", "岸坡垃圾"], - 'seg_nclass': 2, - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'segRegionCnt': 1, - 'segPar': { - 'modelSize': (640, 360), - 'mean': (0.485, 0.456, 0.406), - 'std': (0.229, 0.224, 0.225), - 'numpy': False, - 'RGB_convert_first': True, - 'mixFunction': { - 'function': riverDetSegMixProcess, - 'pars': { - 'slopeIndex': [5, 6, 7], - 'riverIou': 0.1 - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Detweights': "../AIlib2/weights/river/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../AIlib2/weights/river/stdc_360X640_%s_fp16.engine' % gpuName - }) - - # FOREST_FARM_MODEL = ("2", "002", "森林模型", 'forest2', lambda device, gpuName: { - # 'device': device, - # 'gpu_name': gpuName, - # 'labelnames': ["林斑", "病死树", "行人", "火焰", "烟雾","云朵"], - # 'trtFlag_det': True, - # 'trtFlag_seg': False, - # 'Detweights': "../AIlib2/weights/forest2/yolov5_%s_fp16.engine" % gpuName, - # 'seg_nclass': 2, - # 'segRegionCnt': 0, - # 'slopeIndex': [], - # 'segPar': None, - # 'postFile': { - # "name": "post_process", - # "conf_thres": 0.25, - # "iou_thres": 0.45, - # "classes": 6, - # "rainbows": COLOR - # }, - # 'Segweights': None - # }) - - - FOREST_FARM_MODEL = ("2", "002", "森林模型", 'forest2', lambda device, gpuName: { - 'labelnames': ["林斑", "病死树", "行人", "火焰", "烟雾","云朵"], - 'postProcess':{'function':default_mix,'pars':{}}, - 'models': - [ - { - 'weight':"../AIlib2/weights/forest2/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - - - ], - - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'segRegionCnt':2,###分割模型结果需要保留的等值线数目 - "pixScale": 1.2, - - - }) - - - - TRAFFIC_FARM_MODEL = ("3", "003", "交通模型", 'highWay2', lambda device, gpuName: { - 'device': str(device), - 'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水", "影子", "事故"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 3, - 'segRegionCnt': 2, - 'segPar': { - '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, - 'mixFunction': { - 'function': tracfficAccidentMixFunction, - 'pars': { - 'modelSize': (640, 360), - #'modelSize': (1920,1080), - 'RoadArea': 16000, - 'roadVehicleAngle': 15, - 'speedRoadVehicleAngleMax': 75, - 'roundness': 1.0, - 'cls': 9, - 'vehicleFactor': 0.1, - 'confThres': 0.25, - 'roadIou': 0.6, - 'radius': 50, - 'vehicleFlag': False, - 'distanceFlag': False - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 10, - "rainbows": COLOR - }, - 'Detweights': "../AIlib2/weights/highWay2/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../AIlib2/weights/highWay2/stdc_360X640_%s_fp16.engine' % gpuName - }) - - EPIDEMIC_PREVENTION_MODEL = ("4", "004", "防疫模型", None, None) - - PLATE_MODEL = ("5", "005", "车牌模型", None, None) - - VEHICLE_MODEL = ("6", "006", "车辆模型", 'vehicle', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["车辆"], - 'seg_nclass': 2, - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/vehicle/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - PEDESTRIAN_MODEL = ("7", "007", "行人模型", 'pedestrian', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["行人"], - 'seg_nclass': 2, - 'segRegionCnt': 0, - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/pedestrian/yolov5_%s_fp16.engine" % gpuName, - 'slopeIndex': [], - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - SMOGFIRE_MODEL = ("8", "008", "烟火模型", 'smogfire', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["火焰", "烟雾"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/smogfire/yolov5_%s_fp16.engine" % gpuName, - 'slopeIndex': [], - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - ANGLERSWIMMER_MODEL = ("9", "009", "钓鱼游泳模型", 'AnglerSwimmer', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["钓鱼", "游泳"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/AnglerSwimmer/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - COUNTRYROAD_MODEL = ("10", "010", "乡村模型", 'countryRoad', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["违法种植"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/countryRoad/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - SHIP_MODEL = ("11", "011", "船只模型", 'ship2', lambda device, gpuName: { - 'model_size': (608, 608), - 'K': 100, - 'conf_thresh': 0.18, - 'device': 'cuda:%s' % device, - 'down_ratio': 4, - 'num_classes': 15, - 'weights': '../AIlib2/weights/ship2/obb_608X608_%s_fp16.engine' % gpuName, - 'dataset': 'dota', - 'half': False, - 'mean': (0.5, 0.5, 0.5), - 'std': (1, 1, 1), - 'heads': {'hm': None, 'wh': 10, 'reg': 2, 'cls_theta': 1}, - 'decoder': None, - 'test_flag': True, - "rainbows": COLOR, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'drawBox': False, - 'label_array': None, - 'labelnames': ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "船只"), - }) - - BAIDU_MODEL = ("12", "012", "百度AI图片识别模型", None, None) - - CHANNEL_EMERGENCY_MODEL = ("13", "013", "航道模型", 'channelEmergency', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["人"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/channelEmergency/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - RIVER2_MODEL = ("15", "015", "河道检测模型", 'river2', lambda device, gpuName: { - 'device': device, - 'labelnames': ["漂浮物", "岸坡垃圾", "排口", "违建", "菜地", "水生植物", "河湖人员", "钓鱼人员", "船只", - "蓝藻"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 2, - 'segRegionCnt': 1, - 'segPar': { - 'modelSize': (640, 360), - 'mean': (0.485, 0.456, 0.406), - 'std': (0.229, 0.224, 0.225), - 'numpy': False, - 'RGB_convert_first': True, - 'mixFunction': { - 'function': riverDetSegMixProcess, - 'pars': { - 'slopeIndex': [1, 3, 4, 7], - 'riverIou': 0.1 - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.3, - "ovlap_thres_crossCategory": 0.65, - "classes": 5, - "rainbows": COLOR - }, - # "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3] - 'Detweights': "../AIlib2/weights/river2/yolov5_%s_fp16.engine" % gpuName, - # '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3] - 'Segweights': '../AIlib2/weights/river2/stdc_360X640_%s_fp16.engine' % gpuName - }) - - CITY_MANGEMENT_MODEL = ("16", "016", "城管模型", 'cityMangement2', lambda device, gpuName: { - 'labelnames': ["车辆", "垃圾", "商贩", "违停"], - 'postProcess':{ - 'function':dmpr_yolo_stdc, - 'pars':{'carCls':0 ,'illCls':3,'scaleRatio':0.5,'border':80,'rubCls': 1, 'Rubfilter': 150} - }, - 'models':[ - { - #'weight':'../AIlib2/weights/conf/cityMangement3/yolov5.pt', - 'weight':'../AIlib2/weights/cityMangement3/yolov5_%s_fp16.engine'%(gpuName), - 'name':'yolov5', - 'model':yolov5Model, - 'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.25,'iou_thres':0.5,'allowedList':[0,1,2,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.8,"1":0.4,"2":0.5,"3":0.5 } } - }, - { - 'weight':'../AIlib2/weights/conf/cityMangement3/dmpr.pth', - 'par':{ - 'depth_factor':32,'NUM_FEATURE_MAP_CHANNEL':6,'dmpr_thresh':0.1, 'dmprimg_size':640, - 'name':'dmpr' - }, - 'model':DMPRModel, - 'name':'dmpr' - }, - { - 'weight':'../AIlib2/weights/conf/cityMangement3/stdc_360X640.pth', - - '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},###分割模型预处理参数 - 'model':stdcModel, - 'name':'stdc' - } - ], - 'postFile': { - "name": "post_process", - "conf_thres": 0.5, - "iou_thres": 0.5, - "classes": 5, - "rainbows": COLOR - }, - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'segRegionCnt':2,###分割模型结果需要保留的等值线数目 - "pixScale": 1.2, - }) - - DROWING_MODEL = ("17", "017", "人员落水模型", 'drowning', lambda device, gpuName: { - 'device': device, - 'labelnames': ["人头", "人", "船只"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 2, - 'segRegionCnt': 2, - 'segPar': { - '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, - 'mixFunction': { - 'function': mixDrowing_water_postprocess, - 'pars': { - 'modelSize': (640, 360) - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 9, - "rainbows": COLOR - }, - # "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3] - 'Detweights': "../AIlib2/weights/drowning/yolov5_%s_fp16.engine" % gpuName, - # '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3] - 'Segweights': '../AIlib2/weights/drowning/stdc_360X640_%s_fp16.engine' % gpuName - }) - - NOPARKING_MODEL = ( - "18", "018", "城市违章模型", 'noParking', lambda device, gpuName: { - 'device': device, - 'labelnames': ["车辆", "违停"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 4, - 'segRegionCnt': 2, - 'segPar': { - '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, ###分割模型预处理参数 - 'mixFunction': { - 'function': mixNoParking_road_postprocess, - 'pars': { - 'modelSize': (640, 360), - 'roundness': 0.3, - 'cls': 9, - 'laneArea': 10, - 'laneAngleCha': 5, - 'RoadArea': 16000, - 'fitOrder':2 - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 9, - "rainbows": COLOR - }, - 'Detweights': "../AIlib2/weights/noParking/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../AIlib2/weights/noParking/stdc_360X640_%s_fp16.engine' % gpuName - }) - - ILLPARKING_MODEL = ("19", "019", "车辆违停模型", 'illParking', lambda device, gpuName: { - 'device': device, - 'labelnames': ["车", "T角点", "L角点", "违停"], - 'trtFlag_seg': False, - 'trtFlag_det': True, - 'seg_nclass': 4, - 'segRegionCnt': 2, - 'segPar': { - 'mixFunction': { - 'function': illParking_postprocess, - 'pars': {} - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 9, - "rainbows": COLOR - }, - 'Detweights': "../AIlib2/weights/illParking/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': None - }) - - CITYROAD_MODEL = ("20", "020", "城市公路模型", 'cityRoad', lambda device, gpuName: { - 'device': device, - 'labelnames': ["护栏", "交通标志", "非交通标志", "施工", "施工"], - 'trtFlag_seg': False, - 'trtFlag_det': True, - 'slopeIndex': [], - 'seg_nclass': 2, - 'segRegionCnt': 0, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.5, - "classes": 5, - "rainbows": COLOR - }, - 'Detweights': "../AIlib2/weights/cityRoad/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': None - }) - - POTHOLE_MODEL = ("23", "023", "坑槽检测模型", 'pothole', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["坑槽"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/pothole/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None, - }) - - CHANNEL2_MODEL = ("24", "024", "船只综合检测模型", 'channel2', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - - 'labelnames': ["国旗", "浮标", "船名", "船只","未挂国旗船只","未封仓"], # 保持原来的标签顺序不变,方便后面业务端增加 - 'segRegionCnt': 0, - 'postProcess':{'function':channel2_post_process,'name':'channel2','pars':{ - 'objs':[2], - 'wRation':1/6.0, - 'hRation':1/6.0, - 'smallId':0, #旗帜 - 'bigId':3, #船只 - 'newId':4, #未挂国旗船只 - 'uncoverId':5, #未封仓标签 - 'recScale':1.2, - 'target_cls':3.0, #目标种类 - 'filter_cls':4.0 #被过滤的种类 - }}, - 'models':[ - { - #'weight':'../AIlib2/weights/conf/channel2/yolov5.pt', - # 'weight':'../AIlib2/weights/channel2/yolov5_%s_fp16.engine'%(gpuName), - - 'weight':'/home/thsw2/jcq/test/AIlib2/weights/channel2/best.pt', # yolov5 原来模型基础上增加了未封仓 - - # 'weight':'../AIlib2/weights/channel2/yolov5_%s_fp16.engine'%(gpuName), - - 'name':'yolov5', - '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} } - }, - { - # 'weight' : '../AIlib2/weights/ocr2/crnn_ch_4090_fp16_192X32.engine', - 'weight' : '../AIlib2/weights/conf/ocr2/crnn_ch.pth', - 'name':'ocr', - 'model':ocrModel, - 'par':{ - 'char_file':'../AIlib2/weights/conf/ocr2/benchmark.txt', - 'mode':'ch', - 'nc':3, - 'imgH':32, - 'imgW':192, - 'hidden':256, - 'mean':[0.5,0.5,0.5], - 'std':[0.5,0.5,0.5], - 'dynamic':False, - }, - } , - - - # { - # 'weight':'/home/thsw2/jcq/test/AIlib2/weights1/conf/channel2/yolov5_04.pt', # yolov5_04 添加了uncover 0 4 ;标签 yolov5_jcq - # 'name':'yolov5', - # 'model':yolov5Model, - # 'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.15,'iou_thres':0.25,'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} } - # } - - - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3]], - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None, - }) - - RIVERT_MODEL = ("25", "025", "河道检测模型(T)", 'riverT', lambda device, gpuName: { - 'device': device, - 'labelnames': ["漂浮物", "岸坡垃圾", "排口", "违建", "菜地", "水生植物", "河湖人员", "钓鱼人员", "船只", - "蓝藻"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 2, - 'segRegionCnt': 1, - 'segPar': { - 'modelSize': (640, 360), - 'mean': (0.485, 0.456, 0.406), - 'std': (0.229, 0.224, 0.225), - 'numpy': False, - 'RGB_convert_first': True, - 'mixFunction': { - 'function': riverDetSegMixProcess, - 'pars': { - 'slopeIndex': [1, 3, 4, 7], - 'riverIou': 0.1 - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.3, - "ovlap_thres_crossCategory": 0.65, - "classes": 5, - "rainbows": COLOR - }, - # "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3] - 'Detweights': "../AIlib2/weights/riverT/yolov5_%s_fp16.engine" % gpuName, - # '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3] - 'Segweights': '../AIlib2/weights/riverT/stdc_360X640_%s_fp16.engine' % gpuName - }) - - - - FORESTCROWD_FARM_MODEL = ("2", "026", "森林人群模型", 'forestCrowd', lambda device, gpuName: { - 'labelnames': ["林斑", "病死树", "行人", "火焰", "烟雾","人群"], - 'postProcess':{'function':gather_post_process,'pars':{'pedestrianId':2,'crowdThreshold':4,'gatherId':5,'distancePersonScale':2.0}}, - 'models': - [ - { - 'weight':"../AIlib2/weights/forestCrowd/yolov5_%s_fp16.engine"%(gpuName),###检测模型路径 - 'name':'yolov5', - 'model':yolov5Model, - 'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.25,'iou_thres':0.5,'allowedList':[0,1,2,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{ "0":0.25,"1":0.25,"2":0.6,"3":0.6,'4':0.6 ,'5':0.6 } }, - } - - - ], - - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'segRegionCnt':2,###分割模型结果需要保留的等值线数目 - "pixScale": 1.2, - - - }) - TRAFFICFORDSJ_FARM_MODEL = ("27", "027", "交通模型-大数据局", 'highWay2T', lambda device, gpuName: { - 'device': str(device), - 'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水", "影子", "事故", "桥梁外观","设施破损缺失","龙门架","防抛网","标识牌损坏","护栏损坏","钢筋裸露" ], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 3, - 'segRegionCnt': 2, - 'segPar': { - '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, - 'mixFunction': { - 'function': tracfficAccidentMixFunction, - 'pars': { - 'modelSize': (640, 360), - #'modelSize': (1920,1080), - 'RoadArea': 16000, - 'roadVehicleAngle': 15, - 'speedRoadVehicleAngleMax': 75, - 'roundness': 1.0, - 'cls': 9, - 'vehicleFactor': 0.1, - 'confThres': 0.25, - 'roadIou': 0.6, - 'radius': 50, - 'vehicleFlag': False, - 'distanceFlag': False - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 10, - "rainbows": COLOR - }, - 'Detweights': "../AIlib2/weights/highWay2/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../AIlib2/weights/highWay2/stdc_360X640_%s_fp16.engine' % gpuName - }) - - - - @staticmethod - def checkCode(code): - for model in ModelType: - if model.value[1] == code: - return True - return False - - -''' - 参数1: 检测目标名称 - 参数2: 检测目标 - 参数3: 初始化百度检测客户端 -''' - - -@unique -class BaiduModelTarget(Enum): - VEHICLE_DETECTION = ( - "车辆检测", 0, lambda client0, client1, url, request_id: client0.vehicleDetectUrl(url, request_id)) - - HUMAN_DETECTION = ( - "人体检测与属性识别", 1, lambda client0, client1, url, request_id: client1.bodyAttr(url, request_id)) - - PEOPLE_COUNTING = ("人流量统计", 2, lambda client0, client1, url, request_id: client1.bodyNum(url, request_id)) - - -BAIDU_MODEL_TARGET_CONFIG = { - BaiduModelTarget.VEHICLE_DETECTION.value[1]: BaiduModelTarget.VEHICLE_DETECTION, - BaiduModelTarget.HUMAN_DETECTION.value[1]: BaiduModelTarget.HUMAN_DETECTION, - BaiduModelTarget.PEOPLE_COUNTING.value[1]: BaiduModelTarget.PEOPLE_COUNTING -} - -EPIDEMIC_PREVENTION_CONFIG = {1: "行程码", 2: "健康码"} - - -# 模型分析方式 -@unique -class ModelMethodTypeEnum(Enum): - # 方式一: 正常识别方式 - NORMAL = 1 - - # 方式二: 追踪识别方式 - TRACE = 2 diff --git a/enums/ModelTypeEnum-raw.py b/enums/ModelTypeEnum-raw.py deleted file mode 100644 index 79fd69c..0000000 --- a/enums/ModelTypeEnum-raw.py +++ /dev/null @@ -1,807 +0,0 @@ -import sys -from enum import Enum, unique - -from common.Constant import COLOR - -sys.path.extend(['..', '../AIlib2']) -from DMPR import DMPRModel -from DMPRUtils.jointUtil import dmpr_yolo -from segutils.segmodel import SegModel -from utilsK.queRiver import riverDetSegMixProcess -from utilsK.crowdGather import gather_post_process -from segutils.trafficUtils import tracfficAccidentMixFunction -from utilsK.drownUtils import mixDrowing_water_postprocess -from utilsK.noParkingUtils import mixNoParking_road_postprocess -from utilsK.illParkingUtils import illParking_postprocess -from stdc import stdcModel -from yolov5 import yolov5Model -from DMPRUtils.jointUtil import dmpr_yolo_stdc -from AI import default_mix -from ocr import ocrModel -from utilsK.channel2postUtils import channel2_post_process - -''' -参数说明 -1. 编号 -2. 模型编号 -3. 模型名称 -4. 选用的模型名称 -5. 模型配置 -6. 模型引用配置[Detweights文件, Segweights文件, 引用计数] -''' - - -@unique -class ModelType(Enum): - WATER_SURFACE_MODEL = ("1", "001", "河道模型", 'river', lambda device, gpuName: { - 'device': device, - 'labelnames': ["排口", "水生植被", "其它", "漂浮物", "污染排口", "菜地", "违建", "岸坡垃圾"], - 'seg_nclass': 2, - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'segRegionCnt': 1, - 'segPar': { - 'modelSize': (640, 360), - 'mean': (0.485, 0.456, 0.406), - 'std': (0.229, 0.224, 0.225), - 'numpy': False, - 'RGB_convert_first': True, - 'mixFunction': { - 'function': riverDetSegMixProcess, - 'pars': { - 'slopeIndex': [5, 6, 7], - 'riverIou': 0.1 - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Detweights': "../AIlib2/weights/river/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../AIlib2/weights/river/stdc_360X640_%s_fp16.engine' % gpuName - }) - - # FOREST_FARM_MODEL = ("2", "002", "森林模型", 'forest2', lambda device, gpuName: { - # 'device': device, - # 'gpu_name': gpuName, - # 'labelnames': ["林斑", "病死树", "行人", "火焰", "烟雾","云朵"], - # 'trtFlag_det': True, - # 'trtFlag_seg': False, - # 'Detweights': "../AIlib2/weights/forest2/yolov5_%s_fp16.engine" % gpuName, - # 'seg_nclass': 2, - # 'segRegionCnt': 0, - # 'slopeIndex': [], - # 'segPar': None, - # 'postFile': { - # "name": "post_process", - # "conf_thres": 0.25, - # "iou_thres": 0.45, - # "classes": 6, - # "rainbows": COLOR - # }, - # 'Segweights': None - # }) - - - FOREST_FARM_MODEL = ("2", "002", "森林模型", 'forest2', lambda device, gpuName: { - 'labelnames': ["林斑", "病死树", "行人", "火焰", "烟雾","云朵"], - 'postProcess':{'function':default_mix,'pars':{}}, - 'models': - [ - { - 'weight':"../AIlib2/weights/forest2/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - - - ], - - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'segRegionCnt':2,###分割模型结果需要保留的等值线数目 - "pixScale": 1.2, - - - }) - - - - TRAFFIC_FARM_MODEL = ("3", "003", "交通模型", 'highWay2', lambda device, gpuName: { - 'device': str(device), - 'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水", "影子", "事故"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 3, - 'segRegionCnt': 2, - 'segPar': { - #'modelSize': (640, 360), - 'modelSize': (1920, 1080), - 'mean': (0.485, 0.456, 0.406), - 'std': (0.229, 0.224, 0.225), - 'predResize': True, - 'numpy': False, - 'RGB_convert_first': True, - 'mixFunction': { - 'function': tracfficAccidentMixFunction, - 'pars': { - #'modelSize': (640, 360), - 'modelSize': (1920,1080), - 'RoadArea': 16000, - 'roadVehicleAngle': 15, - 'speedRoadVehicleAngleMax': 75, - 'roundness': 1.0, - 'cls': 10, - 'vehicleFactor': 0.1, - 'confThres': 0.25, - 'roadIou': 0.6, - 'radius': 50, - 'vehicleFlag': False, - 'distanceFlag': False - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 10, - "rainbows": COLOR - }, - 'Detweights': "../AIlib2/weights/highWay2/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../AIlib2/weights/highWay2/stdc_360X640_%s_fp16.engine' % gpuName - }) - - EPIDEMIC_PREVENTION_MODEL = ("4", "004", "防疫模型", None, None) - - PLATE_MODEL = ("5", "005", "车牌模型", None, None) - - VEHICLE_MODEL = ("6", "006", "车辆模型", 'vehicle', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["车辆"], - 'seg_nclass': 2, - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/vehicle/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - PEDESTRIAN_MODEL = ("7", "007", "行人模型", 'pedestrian', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["行人"], - 'seg_nclass': 2, - 'segRegionCnt': 0, - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/pedestrian/yolov5_%s_fp16.engine" % gpuName, - 'slopeIndex': [], - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - SMOGFIRE_MODEL = ("8", "008", "烟火模型", 'smogfire', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["火焰", "烟雾"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/smogfire/yolov5_%s_fp16.engine" % gpuName, - 'slopeIndex': [], - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - ANGLERSWIMMER_MODEL = ("9", "009", "钓鱼游泳模型", 'AnglerSwimmer', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["钓鱼", "游泳"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/AnglerSwimmer/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - COUNTRYROAD_MODEL = ("10", "010", "乡村模型", 'countryRoad', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["违法种植"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/countryRoad/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - SHIP_MODEL = ("11", "011", "船只模型", 'ship2', lambda device, gpuName: { - 'model_size': (608, 608), - 'K': 100, - 'conf_thresh': 0.18, - 'device': 'cuda:%s' % device, - 'down_ratio': 4, - 'num_classes': 15, - 'weights': '../AIlib2/weights/ship2/obb_608X608_%s_fp16.engine' % gpuName, - 'dataset': 'dota', - 'half': False, - 'mean': (0.5, 0.5, 0.5), - 'std': (1, 1, 1), - 'heads': {'hm': None, 'wh': 10, 'reg': 2, 'cls_theta': 1}, - 'decoder': None, - 'test_flag': True, - "rainbows": COLOR, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'drawBox': False, - 'label_array': None, - 'labelnames': ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "船只"), - }) - - BAIDU_MODEL = ("12", "012", "百度AI图片识别模型", None, None) - - CHANNEL_EMERGENCY_MODEL = ("13", "013", "航道模型", 'channelEmergency', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["人"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/channelEmergency/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - RIVER2_MODEL = ("15", "015", "河道检测模型", 'river2', lambda device, gpuName: { - 'device': device, - 'labelnames': ["漂浮物", "岸坡垃圾", "排口", "违建", "菜地", "水生植物", "河湖人员", "钓鱼人员", "船只", - "蓝藻"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 2, - 'segRegionCnt': 1, - 'segPar': { - 'modelSize': (640, 360), - 'mean': (0.485, 0.456, 0.406), - 'std': (0.229, 0.224, 0.225), - 'numpy': False, - 'RGB_convert_first': True, - 'mixFunction': { - 'function': riverDetSegMixProcess, - 'pars': { - 'slopeIndex': [1, 3, 4, 7], - 'riverIou': 0.1 - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.3, - "ovlap_thres_crossCategory": 0.65, - "classes": 5, - "rainbows": COLOR - }, - # "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3] - 'Detweights': "../AIlib2/weights/river2/yolov5_%s_fp16.engine" % gpuName, - # '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3] - 'Segweights': '../AIlib2/weights/river2/stdc_360X640_%s_fp16.engine' % gpuName - }) - - CITY_MANGEMENT_MODEL = ("16", "016", "城管模型", 'cityMangement2', lambda device, gpuName: { - 'labelnames': ["车辆", "垃圾", "商贩", "裸土","占道经营","违停"], - 'postProcess':{ - 'function':dmpr_yolo_stdc, - 'pars':{'carCls':0 ,'illCls':5,'scaleRatio':0.5,'border':80} - }, - 'models':[ - { - #'weight':'../AIlib2/weights/conf/cityMangement3/yolov5.pt', - 'weight':'../AIlib2/weights/cityMangement3/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,3,4,5],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.8,"1":0.4,"2":0.5,"3":0.5,"4":0.4,"5":0.5 } } - }, - { - 'weight':'../AIlib2/weights/conf/cityMangement3/dmpr.pth', - 'par':{ - 'depth_factor':32,'NUM_FEATURE_MAP_CHANNEL':6,'dmpr_thresh':0.1, 'dmprimg_size':640, - 'name':'dmpr' - }, - 'model':DMPRModel, - 'name':'dmpr' - }, - { - 'weight':'../AIlib2/weights/conf/cityMangement3/stdc_360X640.pth', - '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},###分割模型预处理参数 - 'model':stdcModel, - 'name':'stdc' - } - ], - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'segRegionCnt':2,###分割模型结果需要保留的等值线数目 - "pixScale": 1.2, - }) - - DROWING_MODEL = ("17", "017", "人员落水模型", 'drowning', lambda device, gpuName: { - 'device': device, - 'labelnames': ["人头", "人", "船只"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 2, - 'segRegionCnt': 2, - 'segPar': { - '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, - 'mixFunction': { - 'function': mixDrowing_water_postprocess, - 'pars': { - 'modelSize': (640, 360) - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 9, - "rainbows": COLOR - }, - # "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3] - 'Detweights': "../AIlib2/weights/drowning/yolov5_%s_fp16.engine" % gpuName, - # '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3] - 'Segweights': '../AIlib2/weights/drowning/stdc_360X640_%s_fp16.engine' % gpuName - }) - - NOPARKING_MODEL = ( - "18", "018", "城市违章模型", 'noParking', lambda device, gpuName: { - 'device': device, - 'labelnames': ["车辆", "违停"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 4, - 'segRegionCnt': 2, - 'segPar': { - '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, ###分割模型预处理参数 - 'mixFunction': { - 'function': mixNoParking_road_postprocess, - 'pars': { - 'modelSize': (640, 360), - 'roundness': 0.3, - 'cls': 9, - 'laneArea': 10, - 'laneAngleCha': 5, - 'RoadArea': 16000, - 'fitOrder':2 - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 9, - "rainbows": COLOR - }, - 'Detweights': "../AIlib2/weights/noParking/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../AIlib2/weights/noParking/stdc_360X640_%s_fp16.engine' % gpuName - }) - - ILLPARKING_MODEL = ("19", "019", "车辆违停模型", 'illParking', lambda device, gpuName: { - 'device': device, - 'labelnames': ["车", "T角点", "L角点", "违停"], - 'trtFlag_seg': False, - 'trtFlag_det': True, - 'seg_nclass': 4, - 'segRegionCnt': 2, - 'segPar': { - 'mixFunction': { - 'function': illParking_postprocess, - 'pars': {} - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 9, - "rainbows": COLOR - }, - 'Detweights': "../AIlib2/weights/illParking/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': None - }) - - CITYROAD_MODEL = ("20", "020", "城市公路模型", 'cityRoad', lambda device, gpuName: { - 'device': device, - 'labelnames': ["护栏", "交通标志", "非交通标志", "施工", "施工"], - 'trtFlag_seg': False, - 'trtFlag_det': True, - 'slopeIndex': [], - 'seg_nclass': 2, - 'segRegionCnt': 0, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.8, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Detweights': "../AIlib2/weights/cityRoad/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': None - }) - - POTHOLE_MODEL = ("23", "023", "坑槽检测模型", 'pothole', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["坑槽"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../AIlib2/weights/pothole/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None, - }) - - CHANNEL2_MODEL = ("24", "024", "船只综合检测模型", 'channel2', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["国旗", "浮标", "船名", "船只","未挂国旗船只"], - 'segRegionCnt': 0, - 'postProcess':{'function':channel2_post_process,'name':'channel2','pars':{ - 'objs':[2], - 'wRation':1/6.0, - 'hRation':1/6.0, - 'smallId':0, - 'bigId':3, - 'newId':4, - 'recScale':1.2}}, - 'models':[ - { - #'weight':'../AIlib2/weights/conf/channel2/yolov5.pt', - 'weight':'../AIlib2/weights/channel2/yolov5_%s_fp16.engine'%(gpuName), - 'name':'yolov5', - '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} } - }, - { - # 'weight' : '../AIlib2/weights/ocr2/crnn_ch_4090_fp16_192X32.engine', - 'weight' : '../AIlib2/weights/conf/ocr2/crnn_ch.pth', - 'name':'ocr', - 'model':ocrModel, - 'par':{ - 'char_file':'../AIlib2/weights/conf/ocr2/benchmark.txt', - 'mode':'ch', - 'nc':3, - 'imgH':32, - 'imgW':192, - 'hidden':256, - 'mean':[0.5,0.5,0.5], - 'std':[0.5,0.5,0.5], - 'dynamic':False, - }, - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3]], - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None, - }) - - RIVERT_MODEL = ("25", "025", "河道检测模型(T)", 'riverT', lambda device, gpuName: { - 'device': device, - 'labelnames': ["漂浮物", "岸坡垃圾", "排口", "违建", "菜地", "水生植物", "河湖人员", "钓鱼人员", "船只", - "蓝藻"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 2, - 'segRegionCnt': 1, - 'segPar': { - 'modelSize': (640, 360), - 'mean': (0.485, 0.456, 0.406), - 'std': (0.229, 0.224, 0.225), - 'numpy': False, - 'RGB_convert_first': True, - 'mixFunction': { - 'function': riverDetSegMixProcess, - 'pars': { - 'slopeIndex': [1, 3, 4, 7], - 'riverIou': 0.1 - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.3, - "ovlap_thres_crossCategory": 0.65, - "classes": 5, - "rainbows": COLOR - }, - # "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3] - 'Detweights': "../AIlib2/weights/riverT/yolov5_%s_fp16.engine" % gpuName, - # '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3] - 'Segweights': '../AIlib2/weights/riverT/stdc_360X640_%s_fp16.engine' % gpuName - }) - - - - FORESTCROWD_FARM_MODEL = ("26", "026", "森林人群模型", 'forestCrowd', lambda device, gpuName: { - 'labelnames': ["林斑", "病死树", "行人", "火焰", "烟雾","人群"], - 'postProcess':{'function':gather_post_process,'pars':{'pedestrianId':2,'crowdThreshold':4,'gatherId':5,'distancePersonScale':2.0}}, - 'models': - [ - { - 'weight':"../AIlib2/weights/forestCrowd/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{ "0":0.25,"1":0.25,"2":0.6,"3":0.6,'4':0.6 ,'5':0.6 } }, - } - - - ], - - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'segRegionCnt':2,###分割模型结果需要保留的等值线数目 - "pixScale": 1.2, - - - }) - TRAFFICFORDSJ_FARM_MODEL = ("27", "027", "交通模型-大数据局", 'highWay2T', lambda device, gpuName: { - 'device': str(device), - 'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水", "影子", "事故", "桥梁外观","设施破损缺失","龙门架","防抛网","标识牌损坏","护栏损坏","钢筋裸露" ], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 3, - 'segRegionCnt': 2, - 'segPar': { - '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, - 'mixFunction': { - 'function': tracfficAccidentMixFunction, - 'pars': { - 'modelSize': (640, 360), - #'modelSize': (1920,1080), - 'RoadArea': 16000, - 'roadVehicleAngle': 15, - 'speedRoadVehicleAngleMax': 75, - 'roundness': 1.0, - 'cls': 9, - 'vehicleFactor': 0.1, - 'confThres': 0.25, - 'roadIou': 0.6, - 'radius': 50, - 'vehicleFlag': False, - 'distanceFlag': False - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 10, - "rainbows": COLOR - }, - 'Detweights': "../AIlib2/weights/highWay2/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../AIlib2/weights/highWay2/stdc_360X640_%s_fp16.engine' % gpuName - }) - - SMARTSITE_MODEL = ("28", "028", "智慧工地模型", 'smartSite', lambda device, gpuName: { - 'labelnames': [ "工人","塔式起重机","悬臂","起重机","压路机","推土机","挖掘机","卡车","装载机","泵车","混凝土搅拌车","打桩","其他车辆" ], - 'postProcess':{'function':default_mix,'pars':{}}, - 'models': - [ - { - 'weight':"../AIlib2/weights/smartSite/yolov5_%s_fp16.engine"%(gpuName),###检测模型路径 - 'name':'yolov5', - 'model':yolov5Model, - 'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.25,'iou_thres':0.45,'allowedList':list(range(20)),'segRegionCnt':1, 'trtFlag_det':True,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - - - ], - 'postFile': { - "rainbows": COLOR - }, - - }) - - RUBBISH_MODEL = ("29", "029", "垃圾模型", 'rubbish', lambda device, gpuName: { - 'labelnames': [ "建筑垃圾","白色垃圾","其他垃圾"], - 'postProcess':{'function':default_mix,'pars':{}}, - 'models': - [ - { - 'weight':"../AIlib2/weights/rubbish/yolov5_%s_fp16.engine"%(gpuName),###检测模型路径 - 'name':'yolov5', - 'model':yolov5Model, - 'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.25,'iou_thres':0.45,'allowedList':list(range(20)),'segRegionCnt':1, 'trtFlag_det':True,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - - - ], - 'postFile': { - "rainbows": COLOR - }, - - }) - - FIREWORK_MODEL = ("30", "030", "烟花模型", 'firework', lambda device, gpuName: { - 'labelnames': [ "烟花"], - 'postProcess':{'function':default_mix,'pars':{}}, - 'models': - [ - { - 'weight':"../AIlib2/weights/firework/yolov5_%s_fp16.engine"%(gpuName),###检测模型路径 - 'name':'yolov5', - 'model':yolov5Model, - 'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.25,'iou_thres':0.45,'allowedList':list(range(20)),'segRegionCnt':1, 'trtFlag_det':True,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - - - ], - 'postFile': { - "rainbows": COLOR - }, - - }) - - - @staticmethod - def checkCode(code): - for model in ModelType: - if model.value[1] == code: - return True - return False - - -''' - 参数1: 检测目标名称 - 参数2: 检测目标 - 参数3: 初始化百度检测客户端 -''' - - -@unique -class BaiduModelTarget(Enum): - VEHICLE_DETECTION = ( - "车辆检测", 0, lambda client0, client1, url, request_id: client0.vehicleDetectUrl(url, request_id)) - - HUMAN_DETECTION = ( - "人体检测与属性识别", 1, lambda client0, client1, url, request_id: client1.bodyAttr(url, request_id)) - - PEOPLE_COUNTING = ("人流量统计", 2, lambda client0, client1, url, request_id: client1.bodyNum(url, request_id)) - - -BAIDU_MODEL_TARGET_CONFIG = { - BaiduModelTarget.VEHICLE_DETECTION.value[1]: BaiduModelTarget.VEHICLE_DETECTION, - BaiduModelTarget.HUMAN_DETECTION.value[1]: BaiduModelTarget.HUMAN_DETECTION, - BaiduModelTarget.PEOPLE_COUNTING.value[1]: BaiduModelTarget.PEOPLE_COUNTING -} - -EPIDEMIC_PREVENTION_CONFIG = {1: "行程码", 2: "健康码"} - - -# 模型分析方式 -@unique -class ModelMethodTypeEnum(Enum): - # 方式一: 正常识别方式 - NORMAL = 1 - - # 方式二: 追踪识别方式 - TRACE = 2 diff --git a/enums/ModelTypeEnum.py b/enums/ModelTypeEnum.py index 8168344..68158ea 100644 --- a/enums/ModelTypeEnum.py +++ b/enums/ModelTypeEnum.py @@ -4,24 +4,7 @@ from enum import Enum, unique from common.Constant import COLOR sys.path.extend(['..', '../AIlib2']) -from DMPR import DMPRModel -from DMPRUtils.jointUtil import dmpr_yolo -from segutils.segmodel import SegModel from utilsK.queRiver import riverDetSegMixProcess -from utilsK.crowdGather import gather_post_process -from segutils.trafficUtils import tracfficAccidentMixFunction -from utilsK.drownUtils import mixDrowing_water_postprocess -from utilsK.noParkingUtils import mixNoParking_road_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 stdc import stdcModel -from yolov5 import yolov5Model -from DMPRUtils.jointUtil import dmpr_yolo_stdc -from AI import default_mix -from ocr import ocrModel -from utilsK.channel2postUtils import channel2_post_process ''' 参数说明 @@ -36,307 +19,15 @@ from utilsK.channel2postUtils import channel2_post_process @unique class ModelType(Enum): - WATER_SURFACE_MODEL = ("1", "001", "河道模型", 'river', lambda device, gpuName: { - 'device': device, - 'labelnames': ["排口", "水生植被", "其它", "漂浮物", "污染排口", "菜地", "违建", "岸坡垃圾"], - 'seg_nclass': 2, - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'segRegionCnt': 1, - 'segPar': { - 'modelSize': (640, 360), - 'mean': (0.485, 0.456, 0.406), - 'std': (0.229, 0.224, 0.225), - 'numpy': False, - 'RGB_convert_first': True, - 'mixFunction': { - 'function': riverDetSegMixProcess, - 'pars': { - 'slopeIndex': [5, 6, 7], - 'riverIou': 0.1 - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Detweights': "../weights/trt/AIlib2/river/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../weights/trt/AIlib2/river/stdc_360X640_%s_fp16.engine' % gpuName - }) - - # FOREST_FARM_MODEL = ("2", "002", "森林模型", 'forest2', lambda device, gpuName: { - # 'device': device, - # 'gpu_name': gpuName, - # 'labelnames': ["林斑", "病死树", "行人", "火焰", "烟雾","云朵"], - # 'trtFlag_det': True, - # 'trtFlag_seg': False, - # 'Detweights': "../weights/trt/AIlib2/forest2/yolov5_%s_fp16.engine" % gpuName, - # 'seg_nclass': 2, - # 'segRegionCnt': 0, - # 'slopeIndex': [], - # 'segPar': None, - # 'postFile': { - # "name": "post_process", - # "conf_thres": 0.25, - # "iou_thres": 0.45, - # "classes": 6, - # "rainbows": COLOR - # }, - # 'Segweights': None - # }) - - - FOREST_FARM_MODEL = ("2", "002", "森林模型", 'forest2', lambda device, gpuName: { - 'labelnames': ["林斑", "病死树", "行人", "火焰", "烟雾","云朵"], - 'postProcess':{'function':default_mix,'pars':{}}, - 'models': - [ - { - 'weight':"../weights/trt/AIlib2/forest2/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - - - ], - - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'segRegionCnt':2,###分割模型结果需要保留的等值线数目 - "pixScale": 1.2, - - - }) - - - - TRAFFIC_FARM_MODEL = ("3", "003", "交通模型", 'highWay2', lambda device, gpuName: { - 'device': str(device), - 'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水", "影子", - "事故","抛撒物", "危化品车辆", "虚标线","其他标线","其他","桥梁外观","设施破损缺失","龙门架","防抛网","标识牌损坏","护栏损坏","钢筋裸露"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 3, - 'segRegionCnt': 2, - 'segPar': { - #'modelSize': (640, 360), - 'modelSize': (1920, 1080), - 'mean': (0.485, 0.456, 0.406), - 'std': (0.229, 0.224, 0.225), - 'predResize': True, - 'numpy': False, - 'RGB_convert_first': True, - 'mixFunction': { - 'function': tracfficAccidentMixFunction, - 'pars': { - #'modelSize': (640, 360), - 'modelSize': (1920,1080), - 'RoadArea': 16000, - 'roadVehicleAngle': 15, - 'speedRoadVehicleAngleMax': 75, - 'roundness': 1.0, - 'cls': 10, - 'CarId':1, - 'CthcId':12, - 'vehicleFactor': 0.1, - 'confThres': 0.25, - 'roadIou': 0.6, - 'radius': 50, - 'vehicleFlag': False, - 'distanceFlag': False - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 10, - "rainbows": COLOR - }, - 'allowedList':[0,1,2,3,4,5,6,7,8,9,10,11,12,16,17,18,19,20,21,22], - 'Detweights': "../weights/trt/AIlib2/highWay2/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../weights/trt/AIlib2/highWay2/stdc_360X640_%s_fp16.engine' % gpuName - }) - - EPIDEMIC_PREVENTION_MODEL = ("4", "004", "防疫模型", None, None) - - PLATE_MODEL = ("5", "005", "车牌模型", None, None) - - VEHICLE_MODEL = ("6", "006", "车辆模型", 'vehicle', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["车辆"], - 'seg_nclass': 2, - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../weights/trt/AIlib2/vehicle/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - PEDESTRIAN_MODEL = ("7", "007", "行人模型", 'pedestrian', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["行人"], - 'seg_nclass': 2, - 'segRegionCnt': 0, - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../weights/trt/AIlib2/pedestrian/yolov5_%s_fp16.engine" % gpuName, - 'slopeIndex': [], - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - SMOGFIRE_MODEL = ("8", "008", "烟火模型", 'smogfire', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["火焰", "烟雾"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../weights/trt/AIlib2/smogfire/yolov5_%s_fp16.engine" % gpuName, - 'slopeIndex': [], - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - ANGLERSWIMMER_MODEL = ("9", "009", "钓鱼游泳模型", 'AnglerSwimmer', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["钓鱼", "游泳"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../weights/trt/AIlib2/AnglerSwimmer/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - COUNTRYROAD_MODEL = ("10", "010", "乡村模型", 'countryRoad', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["违法种植"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../weights/trt/AIlib2/countryRoad/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) - - SHIP_MODEL = ("11", "011", "船只模型", 'ship2', lambda device, gpuName: { - 'model_size': (608, 608), - 'K': 100, - 'conf_thresh': 0.18, - 'device': 'cuda:%s' % device, - 'down_ratio': 4, - 'num_classes': 15, - 'weights': '../weights/trt/AIlib2/ship2/obb_608X608_%s_fp16.engine' % gpuName, - 'dataset': 'dota', - 'half': False, - 'mean': (0.5, 0.5, 0.5), - 'std': (1, 1, 1), - 'heads': {'hm': None, 'wh': 10, 'reg': 2, 'cls_theta': 1}, - 'decoder': None, - 'test_flag': True, - "rainbows": COLOR, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'drawBox': False, - 'label_array': None, - 'labelnames': ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "船只"), - }) - - BAIDU_MODEL = ("12", "012", "百度AI图片识别模型", None, None) - - CHANNEL_EMERGENCY_MODEL = ("13", "013", "航道模型", 'channelEmergency', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["人"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../weights/trt/AIlib2/channelEmergency/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None - }) RIVER2_MODEL = ("15", "015", "河道检测模型", 'river2', lambda device, gpuName: { - 'device': device, + # 实际具体服务器显卡数 + 'device': '0,1', 'labelnames': ["漂浮物", "岸坡垃圾", "排口", "违建", "菜地", "水生植物", "河湖人员", "钓鱼人员", "船只", "蓝藻"], - 'trtFlag_seg': True, - 'trtFlag_det': True, + 'trtFlag_seg': False, + 'trtFlag_det': False, 'seg_nclass': 2, 'segRegionCnt': 1, 'segPar': { @@ -361,610 +52,10 @@ class ModelType(Enum): "classes": 5, "rainbows": COLOR }, - # "../weights/pth/AIlib2/%s/yolov5.pt" % modeType.value[3] - '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 + 'Detweights': "../weights/pth/AIlib2/river2/yolov5.pt", + 'Segweights': '../weights/pth/AIlib2/river2/stdc_360X640.pth' }) - CITY_MANGEMENT_MODEL = ("16", "016", "城管模型", 'cityMangement2', lambda device, gpuName: { - 'labelnames': [ "车辆", "垃圾", "商贩", "违停","占道经营","裸土","未覆盖裸土" ], - 'postProcess':{ - 'function':dmpr_yolo_stdc, - 'pars':{ - 'carCls':0 ,'illCls':6,'scaleRatio':0.5,'border':80, - #车辆","垃圾","商贩","裸土","占道经营","违停"---> - #"车辆","垃圾","商贩","违停","占道经营","裸土" - 'classReindex':{ 0:0,1:1,2:2,3:6,4:4,5:5,6:3} - } - }, - 'models':[ - { - 'weight':'../weights/pth/AIlib2/cityMangement3/yolov5.pt', - #'weight':'../weights/trt/AIlib2/cityMangement3/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.4,"2":0.5,"3":0.5 } } - }, - { - 'weight':'../weights/pth/AIlib2/cityMangement3/dmpr.pth', - 'par':{ - 'depth_factor':32,'NUM_FEATURE_MAP_CHANNEL':6,'dmpr_thresh':0.1, 'dmprimg_size':640, - 'name':'dmpr' - }, - 'model':DMPRModel, - 'name':'dmpr' - }, - { - 'weight':'../weights/pth/AIlib2/cityMangement3/stdc_360X640.pth', - '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},###分割模型预处理参数 - 'model':stdcModel, - 'name':'stdc' - } - ], - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 6, - "rainbows": COLOR - }, - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'segRegionCnt':2,###分割模型结果需要保留的等值线数目 - "pixScale": 1.2, - }) - - DROWING_MODEL = ("17", "017", "人员落水模型", 'drowning', lambda device, gpuName: { - 'device': device, - 'labelnames': ["人头", "人", "船只"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 2, - 'segRegionCnt': 2, - 'segPar': { - '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, - 'mixFunction': { - 'function': mixDrowing_water_postprocess, - 'pars': { - 'modelSize': (640, 360) - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 9, - "rainbows": COLOR - }, - # "../weights/pth/AIlib2/%s/yolov5.pt" % modeType.value[3] - '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 - }) - - NOPARKING_MODEL = ( - "18", "018", "城市违章模型", 'noParking', lambda device, gpuName: { - 'device': device, - 'labelnames': ["车辆", "违停"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 4, - 'segRegionCnt': 2, - 'segPar': { - '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, ###分割模型预处理参数 - 'mixFunction': { - 'function': mixNoParking_road_postprocess, - 'pars': { - 'modelSize': (640, 360), - 'roundness': 0.3, - 'cls': 9, - 'laneArea': 10, - 'laneAngleCha': 5, - 'RoadArea': 16000, - 'fitOrder':2 - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 9, - "rainbows": COLOR - }, - 'Detweights': "../weights/trt/AIlib2/noParking/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../weights/trt/AIlib2/noParking/stdc_360X640_%s_fp16.engine' % gpuName - }) - - ILLPARKING_MODEL = ("19", "019", "车辆违停模型", 'illParking', lambda device, gpuName: { - 'device': device, - 'labelnames': ["车", "T角点", "L角点", "违停"], - 'trtFlag_seg': False, - 'trtFlag_det': True, - 'seg_nclass': 4, - 'segRegionCnt': 2, - 'segPar': { - 'mixFunction': { - 'function': illParking_postprocess, - 'pars': {} - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 9, - "rainbows": COLOR - }, - 'Detweights': "../weights/trt/AIlib2/illParking/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': None - }) - - CITYROAD_MODEL = ("20", "020", "城市公路模型", 'cityRoad', lambda device, gpuName: { - 'device': device, - 'labelnames': ["护栏", "交通标志", "非交通标志", "施工", "施工"], - 'trtFlag_seg': False, - 'trtFlag_det': True, - 'slopeIndex': [], - 'seg_nclass': 2, - 'segRegionCnt': 0, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.8, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Detweights': "../weights/trt/AIlib2/cityRoad/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': None - }) - - POTHOLE_MODEL = ("23", "023", "坑槽检测模型", 'pothole', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - 'labelnames': ["坑槽"], - 'seg_nclass': 2, # 分割模型类别数目,默认2类 - 'segRegionCnt': 0, - 'slopeIndex': [], - 'trtFlag_det': True, - 'trtFlag_seg': False, - 'Detweights': "../weights/trt/AIlib2/pothole/yolov5_%s_fp16.engine" % gpuName, - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None, - }) - - CHANNEL2_MODEL = ("24", "024", "船只综合检测模型", 'channel2', lambda device, gpuName: { - 'device': device, - 'gpu_name': gpuName, - # 'labelnames': ["国旗", "浮标", "船名", "船只","未挂国旗船只"], - 'labelnames': ["国旗", "浮标", "船名", "船只", "未挂国旗船只","未封仓船只","未挂国旗且未封仓船只"], - 'segRegionCnt': 0, - 'postProcess':{'function':channel2_post_process,'name':'channel2','pars':{ - 'objs':[2], - 'wRation':1/6.0, - 'hRation':1/6.0, - 'flagId':0, - 'boatId':3, - 'unflagId': 4, # 未挂国旗船只 - 'uncoverId': 5, # 未封仓 - 'unflagAndcoverId': 6, # 未挂国旗且未封仓 - 'recScale':1.2, - 'target_cls': 3, # 船只目标种类 - 'filter_cls': 4 # 被过滤的种类,模型文件中未封仓实际index - }}, - 'models':[ - { - #'weight':'../weights/pth/AIlib2/channel2/yolov5.pt', - 'weight':'../weights/trt/AIlib2/channel2/yolov5_%s_fp16.engine'%(gpuName), - 'name':'yolov5', - '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} } - }, - { - # 'weight' : '../weights/trt/AIlib2/ocr2/crnn_ch_4090_fp16_192X32.engine', - 'weight' : '../weights/pth/AIlib2/ocr2/crnn_ch.pth', - 'name':'ocr', - 'model':ocrModel, - 'par':{ - 'char_file':'../AIlib2/conf/ocr2/benchmark.txt', - 'mode':'ch', - 'nc':3, - 'imgH':32, - 'imgW':192, - 'hidden':256, - 'mean':[0.5,0.5,0.5], - 'std':[0.5,0.5,0.5], - 'dynamic':False, - }, - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6]], - 'segPar': None, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'Segweights': None, - }) - - RIVERT_MODEL = ("25", "025", "河道检测模型(T)", 'riverT', lambda device, gpuName: { - 'device': device, - 'labelnames': ["漂浮物", "岸坡垃圾", "排口", "违建", "菜地", "水生植物", "河湖人员", "钓鱼人员", "船只", - "蓝藻"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 2, - 'segRegionCnt': 1, - 'segPar': { - 'modelSize': (640, 360), - 'mean': (0.485, 0.456, 0.406), - 'std': (0.229, 0.224, 0.225), - 'numpy': False, - 'RGB_convert_first': True, - 'mixFunction': { - 'function': riverDetSegMixProcess, - 'pars': { - 'slopeIndex': [1, 3, 4, 7], - 'riverIou': 0.1 - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.3, - "ovlap_thres_crossCategory": 0.65, - "classes": 5, - "rainbows": COLOR - }, - # "../weights/pth/AIlib2/%s/yolov5.pt" % modeType.value[3] - '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 - }) - - - - FORESTCROWD_FARM_MODEL = ("26", "026", "森林人群模型", 'forestCrowd', lambda device, gpuName: { - 'labelnames': ["林斑", "病死树", "行人", "火焰", "烟雾","人群"], - 'postProcess':{'function':gather_post_process,'pars':{'pedestrianId':2,'crowdThreshold':4,'gatherId':5,'distancePersonScale':2.0}}, - 'models': - [ - { - 'weight':"../weights/trt/AIlib2/forestCrowd/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{ "0":0.25,"1":0.25,"2":0.6,"3":0.6,'4':0.6 ,'5':0.6 } }, - } - - - ], - - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'segRegionCnt':2,###分割模型结果需要保留的等值线数目 - "pixScale": 1.2, - - - }) - TRAFFICFORDSJ_FARM_MODEL = ("27", "027", "交通模型-大数据局", 'highWay2T', lambda device, gpuName: { - 'device': str(device), - 'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水", "影子", "事故", "桥梁外观","设施破损缺失","龙门架","防抛网","标识牌损坏","护栏损坏","钢筋裸露" ], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 3, - 'segRegionCnt': 2, - 'segPar': { - '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, - 'mixFunction': { - 'function': tracfficAccidentMixFunction, - 'pars': { - 'modelSize': (640, 360), - #'modelSize': (1920,1080), - 'RoadArea': 16000, - 'roadVehicleAngle': 15, - 'speedRoadVehicleAngleMax': 75, - 'roundness': 1.0, - 'cls': 10, - 'vehicleFactor': 0.1, - 'confThres': 0.25, - 'roadIou': 0.6, - 'radius': 50, - 'vehicleFlag': False, - 'distanceFlag': False - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 10, - "rainbows": COLOR - }, - 'Detweights': "../weights/trt/AIlib2/highWay2T/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../weights/trt/AIlib2/highWay2T/stdc_360X640_%s_fp16.engine' % gpuName - }) - - SMARTSITE_MODEL = ("28", "028", "智慧工地模型", 'smartSite', lambda device, gpuName: { - 'labelnames': [ "工人","塔式起重机","悬臂","起重机","压路机","推土机","挖掘机","卡车","装载机","泵车","混凝土搅拌车","打桩","其他车辆" ], - 'postProcess':{'function':default_mix,'pars':{}}, - 'models': - [ - { - 'weight':"../weights/trt/AIlib2/smartSite/yolov5_%s_fp16.engine"%(gpuName),###检测模型路径 - 'name':'yolov5', - 'model':yolov5Model, - 'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.25,'iou_thres':0.45,'allowedList':list(range(20)),'segRegionCnt':1, 'trtFlag_det':True,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - - - ], - 'postFile': { - "rainbows": COLOR - }, - - }) - - RUBBISH_MODEL = ("29", "029", "垃圾模型", 'rubbish', lambda device, gpuName: { - 'labelnames': [ "建筑垃圾","白色垃圾","其他垃圾"], - 'postProcess':{'function':default_mix,'pars':{}}, - 'models': - [ - { - 'weight':"../weights/trt/AIlib2/rubbish/yolov5_%s_fp16.engine"%(gpuName),###检测模型路径 - 'name':'yolov5', - 'model':yolov5Model, - 'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.25,'iou_thres':0.45,'allowedList':list(range(20)),'segRegionCnt':1, 'trtFlag_det':True,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - - - ], - 'postFile': { - "rainbows": COLOR - }, - - }) - - FIREWORK_MODEL = ("30", "030", "烟花模型", 'firework', lambda device, gpuName: { - 'labelnames': [ "烟花"], - 'postProcess':{'function':default_mix,'pars':{}}, - 'models': - [ - { - 'weight':"../weights/trt/AIlib2/firework/yolov5_%s_fp16.engine"%(gpuName),###检测模型路径 - 'name':'yolov5', - 'model':yolov5Model, - 'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.25,'iou_thres':0.45,'allowedList':list(range(20)),'segRegionCnt':1, 'trtFlag_det':True,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - - - ], - 'postFile': { - "rainbows": COLOR - }, - - }) - - TRAFFIC_SPILL_MODEL = ("50", "501", "高速公路抛洒物模型", 'highWaySpill', lambda device, gpuName: { - 'device': str(device), - 'labelnames': ["抛洒物","车辆"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 2, - 'segRegionCnt': 2, - 'segPar': { - #'modelSize': (640, 360), - 'modelSize': (1920, 1080), - 'mean': (0.485, 0.456, 0.406), - 'std': (0.229, 0.224, 0.225), - 'predResize': True, - 'numpy': False, - 'RGB_convert_first': True, - 'mixFunction': { - 'function': mixSpillage_postprocess, - 'pars': { - #'modelSize': (640, 360), - 'modelSize': (1920,1080), - 'RoadArea': 16000, - 'roadVehicleAngle': 15, - 'speedRoadVehicleAngleMax': 75, - 'roundness': 1.0, - 'cls': 1, - 'vehicleFactor': 0.1, - 'confThres': 0.25, - 'roadIou': 0.6, - 'radius': 50, - 'vehicleFlag': False, - 'distanceFlag': False - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 2, - "rainbows": COLOR - }, - 'detModelpara': [{"id": str(x), "config": {"k1": "v1", "k2": "v2"}} for x in [0]], - ###控制哪些检测类别显示、输出 - 'Detweights': "../weights/trt/AIlib2/highWaySpill/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../weights/trt/AIlib2/highWaySpill/stdc_360X640_%s_fp16.engine' % gpuName - }) - - TRAFFIC_CTHC_MODEL = ("50", "502", "高速公路危化品模型", 'highWayCthc', lambda device, gpuName: { - 'device': str(device), - 'labelnames': ["危化品","罐体","危险标识","普通车"], - 'trtFlag_seg': True, - 'trtFlag_det': True, - 'seg_nclass': 2, - 'segRegionCnt': 2, - 'segPar': { - #'modelSize': (640, 360), - 'modelSize': (1920, 1080), - 'mean': (0.485, 0.456, 0.406), - 'std': (0.229, 0.224, 0.225), - 'predResize': True, - 'numpy': False, - 'RGB_convert_first': True, - 'mixFunction': { - 'function': mixCthc_postprocess, - 'pars': { - #'modelSize': (640, 360), - 'modelSize': (1920,1080), - 'RoadArea': 16000, - 'roadVehicleAngle': 15, - 'speedRoadVehicleAngleMax': 75, - 'roundness': 1.0, - 'cls': 4, - 'vehicleFactor': 0.1, - 'confThres': 0.25, - 'roadIou': 0.6, - 'radius': 50, - 'vehicleFlag': False, - 'distanceFlag': False - } - } - }, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 1, - "rainbows": COLOR - }, - 'detModelpara': [{"id": str(x), "config": {"k1": "v1", "k2": "v2"}} for x in [0]], - ###控制哪些检测类别显示、输出 - 'Detweights': "../weights/trt/AIlib2/highWayCthc/yolov5_%s_fp16.engine" % gpuName, - 'Segweights': '../weights/trt/AIlib2/highWayCthc/stdc_360X640_%s_fp16.engine' % gpuName - }) - - TRAFFIC_PANNEL_MODEL = ("50", "503", "光伏板模型", 'pannel', lambda device, gpuName: { - 'labelnames': ["光伏板","覆盖物","裂缝"], - 'postProcess': {'function': pannel_post_process, 'pars': {'objs': [0]}}, - 'models': - [ - { - 'weight': "../weights/trt/AIlib2/pannel/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}}, - } - - ], - 'postFile': { - "rainbows": COLOR - }, - - }) - - CITY_CARPLATE_MODEL = ("30", "301", "自研车牌检测", 'carplate', lambda device, gpuName: { - 'device': str(device), - 'models':{ - { - 'weights': '../AIlib2/weights/conf/jkm/plate_yolov5s_v3.jit', - 'conf_thres': 0.4, - 'iou_thres': 0.45, - 'nc':1, - }, - { - 'weight' : '../weights/pth/AIlib2/ocr2/crnn_ch.pth', - 'name':'ocr', - 'model':ocrModel, - 'par':{ - 'char_file':'../AIlib2/conf/ocr2/benchmark.txt', - 'mode':'ch', - 'nc':3, - 'imgH':32, - 'imgW':192, - 'hidden':256, - 'mean':[0.5,0.5,0.5], - 'std':[0.5,0.5,0.5], - 'dynamic':False, - } - }, - } - }) - - CITY_INFRAREDPERSON_MODEL = ("30", "302", "红外行人模型", 'infraredperson', lambda device, gpuName: { - 'labelnames': ["行人"], - 'postProcess': {'function': default_mix, 'pars': {}}, - 'models': - [ - { - 'weight': "../weights/trt/AIlib2/infraredPerson/yolov5_%s_fp16.engine" % (gpuName), ###检测模型路径 - '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_NIGHTFIRESMOKE_MODEL = ("30", "303", "夜间烟火模型", 'nightFireSmoke', lambda device, gpuName: { - 'labelnames': ["火","烟雾"], - 'postProcess': {'function': default_mix, 'pars': {}}, - 'models': - [ - { - 'weight': "../weights/trt/AIlib2/nightFireSmoke/yolov5_%s_fp16.engine" % (gpuName), ###检测模型路径 - '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 - }, - - }) - @staticmethod def checkCode(code): for model in ModelType: @@ -973,33 +64,6 @@ class ModelType(Enum): return False -''' - 参数1: 检测目标名称 - 参数2: 检测目标 - 参数3: 初始化百度检测客户端 -''' - - -@unique -class BaiduModelTarget(Enum): - VEHICLE_DETECTION = ( - "车辆检测", 0, lambda client0, client1, url, request_id: client0.vehicleDetectUrl(url, request_id)) - - HUMAN_DETECTION = ( - "人体检测与属性识别", 1, lambda client0, client1, url, request_id: client1.bodyAttr(url, request_id)) - - PEOPLE_COUNTING = ("人流量统计", 2, lambda client0, client1, url, request_id: client1.bodyNum(url, request_id)) - - -BAIDU_MODEL_TARGET_CONFIG = { - BaiduModelTarget.VEHICLE_DETECTION.value[1]: BaiduModelTarget.VEHICLE_DETECTION, - BaiduModelTarget.HUMAN_DETECTION.value[1]: BaiduModelTarget.HUMAN_DETECTION, - BaiduModelTarget.PEOPLE_COUNTING.value[1]: BaiduModelTarget.PEOPLE_COUNTING -} - -EPIDEMIC_PREVENTION_CONFIG = {1: "行程码", 2: "健康码"} - - # 模型分析方式 @unique class ModelMethodTypeEnum(Enum): diff --git a/enums/ModelTypeEnum2.py b/enums/ModelTypeEnum2.py deleted file mode 100644 index 7e796c0..0000000 --- a/enums/ModelTypeEnum2.py +++ /dev/null @@ -1,762 +0,0 @@ -import sys -from enum import Enum, unique - -from common.Constant import COLOR - -sys.path.extend(['..', '../AIlib2']) -from segutils.segmodel import SegModel -from utilsK.queRiver import riverDetSegMixProcess_N -from segutils.trafficUtils import tracfficAccidentMixFunction_N -from utilsK.drownUtils import mixDrowing_water_postprocess_N -from utilsK.noParkingUtils import mixNoParking_road_postprocess_N -from utilsK.illParkingUtils import illParking_postprocess -from DMPR import DMPRModel -from DMPRUtils.jointUtil import dmpr_yolo -from yolov5 import yolov5Model -from stdc import stdcModel -from AI import default_mix -from DMPRUtils.jointUtil import dmpr_yolo_stdc - -''' -参数说明 -1. 编号 -2. 模型编号 -3. 模型名称 -4. 选用的模型名称 -''' - - -@unique -class ModelType2(Enum): - WATER_SURFACE_MODEL = ("1", "001", "河道模型", 'river', lambda device, gpuName: { - 'device': device, - 'labelnames': ["排口", "水生植被", "其它", "漂浮物", "污染排口", "菜地", "违建", "岸坡垃圾"], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6,7] ],###控制哪些检测类别显示、输出 - 'trackPar': { - 'sort_max_age': 2, # 跟踪链断裂时允许目标消失最大的次数。超过之后,会认为是新的目标。 - 'sort_min_hits': 3, # 每隔目标连续出现的次数,超过这个次数才认为是一个目标。 - 'sort_iou_thresh': 0.2, # 检测最小的置信度。 - 'det_cnt': 10, # 每隔几次做一个跟踪和检测,默认10。 - 'windowsize': 29, # 轨迹平滑长度,一定是奇数,表示每隔几帧做一平滑,默认29。一个目标在多个帧中出现,每一帧中都有一个位置,这些位置的连线交轨迹。 - 'patchCnt': 100, # 每次送入图像的数量,不宜少于100帧。 - }, - 'postProcess':{'function':riverDetSegMixProcess_N,'pars':{'slopeIndex':[1,3,4,7], 'riverIou':0.1}}, #分割和检测混合处理的函数 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'txtFontSize': 80, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'segLineShow': False, - 'waterLineColor': (0, 255, 255), - 'waterLineWidth': 3 - }, - 'models': - [ - { - 'weight':"../AIlib2/weights/river/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,3], - 'segRegionCnt':1, - 'trtFlag_det':False, - 'trtFlag_seg':False, - "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - }, - { - 'weight':'../AIlib2/weights/conf/river/stdc_360X640.pth', - 'par':{ - 'modelSize':(640,360), - 'mean':(0.485, 0.456, 0.406), - 'std' :(0.229, 0.224, 0.225), - 'numpy':False, - 'RGB_convert_first':True, - 'seg_nclass':2},###分割模型预处理参数 - 'model':stdcModel, - 'name':'stdc' - } - - ], - }) - - FOREST_FARM_MODEL = ("2", "002", "森林模型", 'forest2', lambda device, gpuName: { - 'device': device, - 'labelnames': ["林斑", "病死树", "行人", "火焰", "烟雾"], - 'models': - [ - { - 'weight':"../AIlib2/weights/forest2/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,3], - 'segRegionCnt':1, - 'trtFlag_det':False, - 'trtFlag_seg':False, - "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } - }, - } - ], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100}, - 'postProcess':{'function':default_mix,'pars':{ }}, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'txtFontSize': 80, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'segLineShow': False, - 'waterLineColor': (0, 255, 255), - 'waterLineWidth': 3 - } - }) - - TRAFFIC_FARM_MODEL = ("3", "003", "交通模型", 'highWay2', lambda device, gpuName: { - 'device': device, - 'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水", "事故"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':5,'windowsize':29,'patchCnt':100}, - 'postProcess':{ - 'function':tracfficAccidentMixFunction_N, - 'pars':{ - 'RoadArea': 16000, - 'vehicleArea': 10, - 'roadVehicleAngle': 15, - 'speedRoadVehicleAngleMax': 75, - 'radius': 50 , - 'roundness': 1.0, - 'cls': 9, - 'vehicleFactor': 0.1, - 'cls':9, - 'confThres':0.25, - 'roadIou':0.6, - 'vehicleFlag':False, - 'distanceFlag': False, - 'modelSize':(640,360), - } - }, - 'models': - [ - { - 'weight':"../AIlib2/weights/highWay2/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,3], - 'segRegionCnt':1, - 'trtFlag_det':False, - 'trtFlag_seg':False, - "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - }, - { - 'weight':'../AIlib2/weights/conf/highWay2/stdc_360X640.pth', - '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':3},###分割模型预处理参数 - 'model':stdcModel, - 'name':'stdc' - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 9, - "rainbows": COLOR - }, - 'txtFontSize': 20, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'waterLineColor': (0, 255, 255), - 'segLineShow': False, - 'waterLineWidth': 2 - } - }) - - EPIDEMIC_PREVENTION_MODEL = ("4", "004", "防疫模型", None, None) - - PLATE_MODEL = ("5", "005", "车牌模型", None, None) - - VEHICLE_MODEL = ("6", "006", "车辆模型", 'vehicle', lambda device, gpuName: { - 'device': device, - 'labelnames': ["车辆"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100}, - 'postProcess':{'function':default_mix,'pars':{ }}, - 'models': - [ - { - 'weight':"../AIlib2/weights/vehicle/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,3], - 'segRegionCnt':1, - 'trtFlag_det':False, - 'trtFlag_seg':False, - "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'txtFontSize': 40, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'waterLineColor': (0, 255, 255), - 'segLineShow': False, - 'waterLineWidth': 3 - } - }) - - PEDESTRIAN_MODEL = ("7", "007", "行人模型", 'pedestrian', lambda device, gpuName: { - 'device': device, - 'labelnames': ["行人"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100}, - 'postProcess':{'function':default_mix,'pars':{ }}, - 'models': - [ - { - 'weight':"../AIlib2/weights/pedestrian/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - ], - - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'segLineShow': False, - 'waterLineColor': (0, 255, 255), - 'waterLineWidth': 3 - } - }) - - SMOGFIRE_MODEL = ("8", "008", "烟火模型", 'smogfire', lambda device, gpuName: { - 'device': device, - 'labelnames': ["烟雾", "火焰"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100}, - 'postProcess':{'function':default_mix,'pars':{ }}, - 'models': - [ - { - 'weight':"../AIlib2/weights/smogfire/yolov5_%s_fp16.engine"% gpuName,###检测模型路径 - #'weight':'../AIlib2/weights/conf/%s/yolov5.pt'%(opt['business'] ), - 'name':'yolov5', - '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.3,"2":0.3,"3":0.3 } }, - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'txtFontSize': 40, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'segLineShow': False, - 'waterLineColor': (0, 255, 255), - 'waterLineWidth': 3 - } - }) - - ANGLERSWIMMER_MODEL = ("9", "009", "钓鱼游泳模型", 'AnglerSwimmer', lambda device, gpuName: { - 'device': device, - 'labelnames': ["钓鱼", "游泳"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100}, - 'postProcess':{'function':default_mix,'pars':{ }}, - 'models': - [ - { - 'weight':"../AIlib2/weights/AnglerSwimmer/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'txtFontSize': 40, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'segLineShow': False, - 'waterLineColor': (0, 255, 255), - 'waterLineWidth': 3 - }, - }) - - COUNTRYROAD_MODEL = ("10", "010", "乡村模型", 'countryRoad', lambda device, gpuName: { - 'device': device, - 'labelnames': ["违法种植"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100}, - 'postProcess':{'function':default_mix,'pars':{ }}, - 'models': - [ - { - 'weight':"../AIlib2/weights/countryRoad/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'txtFontSize': 40, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'segLineShow': False, - 'waterLineColor': (0, 255, 255), - 'waterLineWidth': 3 - } - }) - - SHIP_MODEL = ("11", "011", "船只模型", 'ship2', lambda device, gpuName: { - 'obbModelPar': { - 'labelnames': ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "船只"], - 'model_size': (608, 608), - 'K': 100, - 'conf_thresh': 0.3, - 'down_ratio': 4, - 'num_classes': 15, - 'dataset': 'dota', - 'heads': { - 'hm': None, - 'wh': 10, - 'reg': 2, - 'cls_theta': 1 - }, - 'mean': (0.5, 0.5, 0.5), - 'std': (1, 1, 1), - 'half': False, - 'test_flag': True, - 'decoder': None, - 'weights': '../AIlib2/weights/ship2/obb_608X608_%s_fp16.engine' % gpuName - }, - 'trackPar': { - 'sort_max_age': 2, # 跟踪链断裂时允许目标消失最大的次数。超过之后,会认为是新的目标。 - 'sort_min_hits': 3, # 每隔目标连续出现的次数,超过这个次数才认为是一个目标。 - 'sort_iou_thresh': 0.2, # 检测最小的置信度。 - 'det_cnt': 10, # 每隔几次做一个跟踪和检测,默认10。 - 'windowsize': 29, # 轨迹平滑长度,一定是奇数,表示每隔几帧做一平滑,默认29。一个目标在多个帧中出现,每一帧中都有一个位置,这些位置的连线交轨迹。 - 'patchCnt': 100, # 每次送入图像的数量,不宜少于100帧。 - }, - 'device': "cuda:%s" % device, - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'drawBox': False, - 'drawPar': { - "rainbows": COLOR, - 'digitWordFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'wordSize': 40, - 'fontSize': 1.0, - 'label_location': 'leftTop' - } - }, - 'labelnames': ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "船只"] - }) - - BAIDU_MODEL = ("12", "012", "百度AI图片识别模型", None, None) - - CHANNEL_EMERGENCY_MODEL = ("13", "013", "航道模型", 'channelEmergency', lambda device, gpuName: { - 'device': device, - 'labelnames': ["人"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100}, - 'postProcess':{'function':default_mix,'pars':{ }}, - 'models': - [ - { - 'weight':"../AIlib2/weights/channelEmergency/yolov5_%s_fp16.engine"% gpuName,###检测模型路径 - #'weight':'../AIlib2/weights/conf/%s/yolov5.pt'%(opt['business'] ), - 'name':'yolov5', - '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.3,"2":0.3,"3":0.3 } }, - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [] ],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'txtFontSize': 40, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'segLineShow': False, - 'waterLineColor': (0, 255, 255), - 'waterLineWidth': 3 - } - }) - - RIVER2_MODEL = ("15", "015", "河道检测模型", 'river2', lambda device, gpuName: { - 'device': device, - 'labelnames': ["漂浮物", "岸坡垃圾", "排口", "违建", "菜地", "水生植物", "河湖人员", "钓鱼人员", "船只", - "蓝藻"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100}, - 'postProcess':{'function':riverDetSegMixProcess_N,'pars':{'slopeIndex':[1,3,4,7], 'riverIou':0.1}}, #分割和检测混合处理的函数 - 'models': - [ - { - 'weight':"../AIlib2/weights/river2/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - }, - { - 'weight':'../AIlib2/weights/conf/river2/stdc_360X640.pth', - 'par':{ - 'modelSize':(640,360),'mean':(0.485, 0.456, 0.406),'std' :(0.229, 0.224, 0.225),'numpy':False, 'RGB_convert_first':True,'seg_nclass':2},###分割模型预处理参数 - 'model':stdcModel, - 'name':'stdc' - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.3, - "ovlap_thres_crossCategory": 0.65, - "classes": 5, - "rainbows": COLOR - }, - 'txtFontSize': 80, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'segLineShow': False, - 'waterLineColor': (0, 255, 255), - 'waterLineWidth': 3 - } - }) - - CITY_MANGEMENT_MODEL = ("16", "016", "城管模型", 'cityMangement2', lambda device, gpuName: { - 'device': device, - 'labelnames': ["车辆", "垃圾", "商贩", "违停"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':5,'windowsize':29,'patchCnt':100}, - 'postProcess':{ - 'function':dmpr_yolo_stdc, - 'pars':{'carCls':0 ,'illCls':3,'scaleRatio':0.5,'border':80} - }, - 'models':[ - { - 'weight':"../AIlib2/weights/cityMangement3/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.8,"1":0.5,"2":0.5,"3":0.5 } } - - }, - { - 'weight':"../AIlib2/weights/cityMangement3/dmpr_%s.engine"% gpuName,###DMPR模型路径 - 'par':{ - 'depth_factor':32,'NUM_FEATURE_MAP_CHANNEL':6,'dmpr_thresh':0.3, 'dmprimg_size':640, - 'name':'dmpr' - }, - 'model':DMPRModel, - 'name':'dmpr' - }, - { - 'weight':"../AIlib2/weights/cityMangement3/stdc_360X640_%s_fp16.engine"% gpuName,###分割模型路径 - '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},###分割模型预处理参数 - 'model':stdcModel, - 'name':'stdc' - - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'txtFontSize': 20, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'segLineShow': False, - 'waterLineColor': (0, 255, 255), - 'waterLineWidth': 2 - } - }) - - DROWING_MODEL = ("17", "017", "人员落水模型", 'drowning', lambda device, gpuName: { - 'device': device, - 'labelnames': ["人头", "人", "船只"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100}, - 'postProcess':{'function':mixDrowing_water_postprocess_N, - 'pars':{ }}, - 'models': - [ - { - 'weight':"../AIlib2/weights/drowning/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - }, - { - 'weight':'../AIlib2/weights/conf/drowning/stdc_360X640.pth', - '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},###分割模型预处理参数 - 'model':stdcModel, - 'name':'stdc' - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 9, - "rainbows": COLOR - }, - 'txtFontSize': 20, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'waterLineColor': (0, 255, 255), - 'segLineShow': False, - 'waterLineWidth': 2 - } - }) - - NOPARKING_MODEL = ( - "18", "018", "城市违章模型", 'noParking', lambda device, gpuName: { - 'device': device, - 'labelnames': ["车辆", "违停"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100}, - 'postProcess':{'function':mixNoParking_road_postprocess_N, - 'pars': { 'roundness': 0.3, 'cls': 9, 'laneArea': 10, 'laneAngleCha': 5 ,'RoadArea': 16000,'fitOrder':2, 'modelSize':(640,360)} - } , - 'models': - [ - { - 'weight':"../AIlib2/weights/noParking/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - }, - { - 'weight':'../AIlib2/weights/conf/noParking/stdc_360X640.pth', - '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':4},###分割模型预处理参数 - 'model':stdcModel, - 'name':'stdc' - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.25, - "classes": 9, - "rainbows": COLOR - }, - 'txtFontSize': 20, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'waterLineColor': (0, 255, 255), - 'segLineShow': False, - 'waterLineWidth': 2 - } - } - ) - - CITYROAD_MODEL = ("20", "020", "城市公路模型", 'cityRoad', lambda device, gpuName: { - 'device': device, - 'labelnames': ["护栏", "交通标志", "非交通标志", "施工", "施工"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100}, - 'postProcess':{'function':default_mix,'pars':{ }}, - 'models': - [ - { - 'weight':"../AIlib2/weights/cityRoad/yolov5_%s_fp16.engine"% gpuName,###检测模型路径 - 'name':'yolov5', - 'model':yolov5Model, - 'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.8,'iou_thres':0.45,'allowedList':[0,1,2,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3 } }, - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.8, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'txtFontSize': 40, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'segLineShow': False, - 'waterLineColor': (0, 255, 255), - 'waterLineWidth': 3 - } - }) - - POTHOLE_MODEL = ("23", "023", "坑槽检测模型", 'pothole', lambda device, gpuName: { # 目前集成到另外的模型中去了 不单独使用 - 'device': device, - 'labelnames': ["坑槽"], - 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':3,'windowsize':29,'patchCnt':100}, - 'postProcess':{'function':default_mix,'pars':{ }}, - 'models': - [ - { - 'weight':"../AIlib2/weights/pothole/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,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.25,"1":0.3,"2":0.3,"3":0.3}}, - } - ], - 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0]],###控制哪些检测类别显示、输出 - 'postFile': { - "name": "post_process", - "conf_thres": 0.25, - "iou_thres": 0.45, - "classes": 5, - "rainbows": COLOR - }, - 'txtFontSize': 40, - 'digitFont': { - 'line_thickness': 2, - 'boxLine_thickness': 1, - 'fontSize': 1.0, - 'segLineShow': False, - 'waterLineColor': (0, 255, 255), - 'waterLineWidth': 3 - }, - }) - - - @staticmethod - def checkCode(code): - for model in ModelType2: - if model.value[1] == code: - return True - return False - - -''' - 参数1: 检测目标名称 - 参数2: 检测目标 - 参数3: 初始化百度检测客户端 -''' - - -@unique -class BaiduModelTarget2(Enum): - VEHICLE_DETECTION = ( - "车辆检测", 0, lambda client0, client1, url, request_id: client0.vehicleDetectUrl(url, request_id)) - - HUMAN_DETECTION = ( - "人体检测与属性识别", 1, lambda client0, client1, url, request_id: client1.bodyAttr(url, request_id)) - - PEOPLE_COUNTING = ("人流量统计", 2, lambda client0, client1, url, request_id: client1.bodyNum(url, request_id)) - - -BAIDU_MODEL_TARGET_CONFIG2 = { - BaiduModelTarget2.VEHICLE_DETECTION.value[1]: BaiduModelTarget2.VEHICLE_DETECTION, - BaiduModelTarget2.HUMAN_DETECTION.value[1]: BaiduModelTarget2.HUMAN_DETECTION, - BaiduModelTarget2.PEOPLE_COUNTING.value[1]: BaiduModelTarget2.PEOPLE_COUNTING -} - -EPIDEMIC_PREVENTION_CONFIG = {1: "行程码", 2: "健康码"} - - -# 模型分析方式 -@unique -class ModelMethodTypeEnum2(Enum): - # 方式一: 正常识别方式 - NORMAL = 1 - - # 方式二: 追踪识别方式 - TRACE = 2 diff --git a/util/ModelUtils.py b/util/ModelUtils.py index 49478f1..cf6dfaf 100644 --- a/util/ModelUtils.py +++ b/util/ModelUtils.py @@ -2,33 +2,44 @@ import sys from pickle import dumps, loads from traceback import format_exc -import time import cv2 from loguru import logger -from common.Constant import COLOR -from enums.BaiduSdkEnum import VehicleEnum from enums.ExceptionEnum import ExceptionType -from enums.ModelTypeEnum import ModelType, BAIDU_MODEL_TARGET_CONFIG +from enums.ModelTypeEnum import ModelType from exception.CustomerException import ServiceException -from util.ImgBaiduSdk import AipBodyAnalysisClient, AipImageClassifyClient -from util.PlotsUtils import get_label_arrays, get_label_array_dict +from util.PlotsUtils import get_label_arrays from util.TorchUtils import select_device 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 from stdc import stdcModel -from segutils.segmodel import SegModel from models.experimental import attempt_load -from obbUtils.shipUtils import OBB_infer -from obbUtils.load_obb_model import load_model_decoder_OBB -import torch import tensorrt as trt -from utilsK.jkmUtils import pre_process, post_process, get_return_data from DMPR import DMPRModel FONT_PATH = "../AIlib2/conf/platech.ttf" +def get_label_arraylist(*args): + width, height, names, rainbows = args + # line = int(round(0.002 * (height + width) / 2) + 1) + line = max(1, int(round(width / 1920 * 3))) + label = ' 0.95' + tf = max(line - 1, 1) + fontScale = line * 0.33 + text_width, text_height = cv2.getTextSize(label, 0, fontScale=fontScale, thickness=tf)[0] + # fontsize = int(width / 1920 * 40) + numFontSize = float(format(width / 1920 * 1.1, '.1f')) + digitFont = {'line_thickness': line, + 'boxLine_thickness': line, + 'fontSize': numFontSize, + 'waterLineColor': (0, 255, 255), + 'segLineShow': False, + 'waterLineWidth': line, + 'wordSize': text_height, + 'label_location': 'leftTop'} + label_arraylist = get_label_arrays(names, rainbows, fontSize=text_height, fontPath=FONT_PATH) + return digitFont, label_arraylist, (line, text_width, text_height, fontScale, tf) # 河道模型、河道检测模型、交通模型、人员落水模型、城市违章公共模型 class OneModel: @@ -46,8 +57,12 @@ class OneModel: new_device = select_device(par.get('device')) half = new_device.type != 'cpu' Detweights = par['Detweights'] - with open(Detweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime: - model = runtime.deserialize_cuda_engine(f.read()) + if par['trtFlag_det']: + with open(Detweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime: + 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'] Segweights = par['Segweights'] if Segweights: @@ -82,43 +97,6 @@ class OneModel: logger.error("模型加载异常:{}, requestId:{}", format_exc(), requestId) raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0], ExceptionType.MODEL_LOADING_EXCEPTION.value[1]) -# 纯分类模型 -class cityManagementModel: - __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) - postProcess = par['postProcess'] - names = par['labelnames'] - postFile = par['postFile'] - rainbows = postFile["rainbows"] - modelList=[ modelPar['model'](weights=modelPar['weight'],par=modelPar['par']) for modelPar in par['models'] ] - model_param = { - "modelList": modelList, - "postProcess": postProcess, - } - self.model_conf = (modeType, model_param, allowedList, names, rainbows) - except Exception: - logger.error("模型加载异常:{}, requestId:{}", format_exc(), requestId) - raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0], - ExceptionType.MODEL_LOADING_EXCEPTION.value[1]) -def detSeg_demo2(args): - model_conf, frame, request_id = args - modelList, postProcess = model_conf[1]['modelList'], model_conf[1]['postProcess'] - try: - result = [[ None, None, AI_process_N([frame], modelList, postProcess)[0] ] ] # 为了让返回值适配统一的接口而写的shi - return result - except ServiceException as s: - raise s - except Exception: - # self.num += 1 - # cv2.imwrite('/home/th/tuo_heng/dev/img%s.jpg' % str(self.num), frame) - logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), request_id) - raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0], - ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1]) def model_process(args): model_conf, frame, request_id = args @@ -142,276 +120,6 @@ def model_process(args): raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0], ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1]) - -# 森林模型、车辆模型、行人模型、烟火模型、 钓鱼模型、航道模型、乡村模型、城管模型公共模型 -class TwoModel: - __slots__ = "model_conf" - - def __init__(self, device1, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None, - env=None): - s = time.time() - try: - logger.info("########################加载{}########################, requestId:{}", modeType.value[2], - requestId) - par = modeType.value[4](str(device1), gpu_name) - device = select_device(par.get('device')) - names = par['labelnames'] - half = device.type != 'cpu' - Detweights = par['Detweights'] - with open(Detweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime: - model = runtime.deserialize_cuda_engine(f.read()) - segmodel = None - postFile = par['postFile'] - conf_thres = postFile["conf_thres"] - iou_thres = postFile["iou_thres"] - rainbows = postFile["rainbows"] - otc = postFile.get("ovlap_thres_crossCategory") - model_param = { - "model": model, - "segmodel": segmodel, - "half": half, - "device": device, - "conf_thres": conf_thres, - "iou_thres": iou_thres, - "trtFlag_det": par['trtFlag_det'], - "otc": otc - } - self.model_conf = (modeType, model_param, allowedList, names, rainbows) - except Exception: - logger.error("模型加载异常:{}, requestId:{}", format_exc(), requestId) - raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0], - ExceptionType.MODEL_LOADING_EXCEPTION.value[1]) - logger.info("模型初始化时间:{}, requestId:{}", time.time() - s, requestId) - - -def forest_process(args): - model_conf, frame, request_id = args - model_param, names, rainbows = model_conf[1], model_conf[3], model_conf[4] - try: - return AI_process_forest([frame], model_param['model'], model_param['segmodel'], names, - model_param['label_arraylist'], rainbows, model_param['half'], model_param['device'], - model_param['conf_thres'], model_param['iou_thres'], [], font=model_param['digitFont'], - trtFlag_det=model_param['trtFlag_det'], SecNms=model_param['otc']) - except ServiceException as s: - raise s - except Exception: - # self.num += 1 - # cv2.imwrite('/home/th/tuo_heng/dev/img%s.jpg' % str(self.num), frame) - logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), request_id) - raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0], - ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1]) - -class MultiModel: - __slots__ = "model_conf" - - def __init__(self, device1, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None, - env=None): - s = time.time() - try: - logger.info("########################加载{}########################, requestId:{}", modeType.value[2], - requestId) - par = modeType.value[4](str(device1), gpu_name) - postProcess = par['postProcess'] - names = par['labelnames'] - postFile = par['postFile'] - rainbows = postFile["rainbows"] - modelList=[ modelPar['model'](weights=modelPar['weight'],par=modelPar['par']) for modelPar in par['models'] ] - model_param = { - "modelList": modelList, - "postProcess": postProcess, - } - self.model_conf = (modeType, model_param, allowedList, names, rainbows) - except Exception: - logger.error("模型加载异常:{}, requestId:{}", format_exc(), requestId) - raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0], - ExceptionType.MODEL_LOADING_EXCEPTION.value[1]) - logger.info("模型初始化时间:{}, requestId:{}", time.time() - s, requestId) - -def channel2_process(args): - model_conf, frame, request_id = args - modelList, postProcess = model_conf[1]['modelList'], model_conf[1]['postProcess'] - try: - start = time.time() - result = [[None, None, AI_process_C([frame], modelList, postProcess)[0]]] # 为了让返回值适配统一的接口而写的shi - # print("AI_process_C use time = {}".format(time.time()-start)) - return result - except ServiceException as s: - raise s - except Exception: - logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), request_id) - raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0], - ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1]) - -def get_label_arraylist(*args): - width, height, names, rainbows = args - # line = int(round(0.002 * (height + width) / 2) + 1) - line = max(1, int(round(width / 1920 * 3))) - label = ' 0.95' - tf = max(line - 1, 1) - fontScale = line * 0.33 - text_width, text_height = cv2.getTextSize(label, 0, fontScale=fontScale, thickness=tf)[0] - # fontsize = int(width / 1920 * 40) - numFontSize = float(format(width / 1920 * 1.1, '.1f')) - digitFont = {'line_thickness': line, - 'boxLine_thickness': line, - 'fontSize': numFontSize, - 'waterLineColor': (0, 255, 255), - 'segLineShow': False, - 'waterLineWidth': line, - 'wordSize': text_height, - 'label_location': 'leftTop'} - label_arraylist = get_label_arrays(names, rainbows, fontSize=text_height, fontPath=FONT_PATH) - return digitFont, label_arraylist, (line, text_width, text_height, fontScale, tf) - - -# 船只模型 -class ShipModel: - __slots__ = "model_conf" - - def __init__(self, device1, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None, - env=None): - s = time.time() - try: - logger.info("########################加载{}########################, requestId:{}", modeType.value[2], - requestId) - par = modeType.value[4](str(device1), gpu_name) - model, decoder2 = load_model_decoder_OBB(par) - par['decoder'] = decoder2 - names = par['labelnames'] - rainbows = par['postFile']["rainbows"] - model_param = { - "model": model, - "par": par - } - self.model_conf = (modeType, model_param, allowedList, names, rainbows) - except Exception: - logger.exception("模型加载异常:{}, requestId:{}", format_exc(), requestId) - raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0], - ExceptionType.MODEL_LOADING_EXCEPTION.value[1]) - logger.info("模型初始化时间:{}, requestId:{}", time.time() - s, requestId) - - -def obb_process(args): - model_conf, frame, request_id = args - model_param = model_conf[1] - # font_config, frame, names, label_arrays, rainbows, model, par, requestId = args - try: - return OBB_infer(model_param["model"], frame, model_param["par"]) - except ServiceException as s: - raise s - except Exception: - # self.num += 1 - # cv2.imwrite('/home/th/tuo_heng/dev/img%s.jpg' % str(self.num), frame) - logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), request_id) - raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0], - ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1]) - -# 车牌分割模型、健康码、行程码分割模型 -class IMModel: - __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) - img_type = 'code' - if ModelType.PLATE_MODEL == modeType: - img_type = 'plate' - par = { - 'code': {'weights': '../weights/pth/AIlib2/jkm/health_yolov5s_v3.jit', 'img_type': 'code', 'nc': 10}, - 'plate': {'weights': '../weights/pth/AIlib2/jkm/plate_yolov5s_v3.jit', 'img_type': 'plate', 'nc': 1}, - 'conf_thres': 0.4, - 'iou_thres': 0.45, - 'device': 'cuda:%s' % device, - 'plate_dilate': (0.5, 0.3) - } - - new_device = torch.device(par['device']) - model = torch.jit.load(par[img_type]['weights']) - logger.info("########################加载 jit 模型成功 成功 ########################, requestId:{}", - requestId) - self.model_conf = (modeType, allowedList, new_device, model, par, img_type) - except Exception: - logger.error("模型加载异常:{}, requestId:{}", format_exc(), requestId) - raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0], - ExceptionType.MODEL_LOADING_EXCEPTION.value[1]) - -def im_process(args): - frame, device, model, par, img_type, requestId = args - try: - img, padInfos = pre_process(frame, device) - pred = model(img) - boxes = post_process(pred, padInfos, device, conf_thres=par['conf_thres'], - iou_thres=par['iou_thres'], nc=par[img_type]['nc']) # 后处理 - dataBack = get_return_data(frame, boxes, modelType=img_type, plate_dilate=par['plate_dilate']) - print('-------line351----:',dataBack) - return dataBack - 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图片识别模型 -class BaiduAiImageModel: - __slots__ = "model_conf" - - def __init__(self, device=None, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None, - env=None): - try: - logger.info("########################加载{}########################, requestId:{}", modeType.value[2], - requestId) - # 人体检测与属性识别、 人流量统计客户端 - aipBodyAnalysisClient = AipBodyAnalysisClient(base_dir, env) - # 车辆检测检测客户端 - aipImageClassifyClient = AipImageClassifyClient(base_dir, env) - rainbows = COLOR - vehicle_names = [VehicleEnum.CAR.value[1], VehicleEnum.TRICYCLE.value[1], VehicleEnum.MOTORBIKE.value[1], - VehicleEnum.CARPLATE.value[1], VehicleEnum.TRUCK.value[1], VehicleEnum.BUS.value[1]] - person_names = ['人'] - self.model_conf = (modeType, aipImageClassifyClient, aipBodyAnalysisClient, allowedList, rainbows, - vehicle_names, person_names, requestId) - except Exception: - logger.exception("模型加载异常:{}, requestId:{}", format_exc(), requestId) - raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0], - ExceptionType.MODEL_LOADING_EXCEPTION.value[1]) - - -def get_baidu_label_arraylist(*args): - width, height, vehicle_names, person_names, rainbows = args - # line = int(round(0.002 * (height + width) / 2) + 1) - line = max(1, int(round(width / 1920 * 3) + 1)) - label = ' 0.97' - tf = max(line, 1) - fontScale = line * 0.33 - text_width, text_height = cv2.getTextSize(label, 0, fontScale=fontScale, thickness=tf)[0] - vehicle_label_arrays = get_label_arrays(vehicle_names, rainbows, fontSize=text_height, fontPath=FONT_PATH) - person_label_arrays = get_label_arrays(person_names, rainbows, fontSize=text_height, fontPath=FONT_PATH) - font_config = (line, text_width, text_height, fontScale, tf) - return vehicle_label_arrays, person_label_arrays, font_config - - -def baidu_process(args): - target, url, aipImageClassifyClient, aipBodyAnalysisClient, request_id = args - try: - # [target, url, aipImageClassifyClient, aipBodyAnalysisClient, requestId] - baiduEnum = BAIDU_MODEL_TARGET_CONFIG.get(target) - if baiduEnum is None: - raise ServiceException(ExceptionType.DETECTION_TARGET_TYPES_ARE_NOT_SUPPORTED.value[0], - ExceptionType.DETECTION_TARGET_TYPES_ARE_NOT_SUPPORTED.value[1] - + " target: " + target) - return baiduEnum.value[2](aipImageClassifyClient, aipBodyAnalysisClient, url, request_id) - except ServiceException as s: - raise s - except Exception: - logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), request_id) - raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0], - ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1]) - - def one_label(width, height, model_conf): # modeType, model_param, allowedList, names, rainbows = model_conf names = model_conf[3] @@ -422,253 +130,13 @@ def one_label(width, height, model_conf): model_param['label_arraylist'] = label_arraylist model_param['font_config'] = font_config -def dynamics_label(width, height, model_conf): - # modeType, model_param, allowedList, names, rainbows = model_conf - names = model_conf[3] - rainbows = model_conf[4] - model_param = model_conf[1] - digitFont, label_arraylist, font_config = get_label_arraylist(width, height, names, rainbows) - line = max(1, int(round(width / 1920 * 3))) - label = ' 0.95' - tf = max(line - 1, 1) - fontScale = line * 0.33 - _, text_height = cv2.getTextSize(label, 0, fontScale=fontScale, thickness=tf)[0] - label_dict = get_label_array_dict(rainbows, fontSize=text_height, fontPath=FONT_PATH) - model_param['digitFont'] = digitFont - model_param['label_arraylist'] = label_arraylist - model_param['font_config'] = font_config - model_param['label_dict'] = label_dict -def baidu_label(width, height, model_conf): - # modeType, aipImageClassifyClient, aipBodyAnalysisClient, allowedList, rainbows, - # vehicle_names, person_names, requestId - vehicle_names = model_conf[5] - person_names = model_conf[6] - rainbows = model_conf[4] - vehicle_label_arrays, person_label_arrays, font_config = get_baidu_label_arraylist(width, height, vehicle_names, - person_names, rainbows) - return vehicle_label_arrays, person_label_arrays, font_config - MODEL_CONFIG = { - # 加载河道模型 - ModelType.WATER_SURFACE_MODEL.value[1]: ( - lambda x, y, r, t, z, h: OneModel(x, y, r, ModelType.WATER_SURFACE_MODEL, t, z, h), - ModelType.WATER_SURFACE_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 加载森林模型 - # ModelType.FOREST_FARM_MODEL.value[1]: ( - # lambda x, y, r, t, z, h: TwoModel(x, y, r, ModelType.FOREST_FARM_MODEL, t, z, h), - # ModelType.FOREST_FARM_MODEL, - # lambda x, y, z: one_label(x, y, z), - # lambda x: forest_process(x) - # ), - ModelType.FOREST_FARM_MODEL.value[1]: ( - lambda x, y, r, t, z, h: cityManagementModel(x, y, r, ModelType.FOREST_FARM_MODEL, t, z, h), - ModelType.FOREST_FARM_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: detSeg_demo2(x) - ), - - # 加载交通模型 - ModelType.TRAFFIC_FARM_MODEL.value[1]: ( - lambda x, y, r, t, z, h: OneModel(x, y, r, ModelType.TRAFFIC_FARM_MODEL, t, z, h), - ModelType.TRAFFIC_FARM_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 加载防疫模型 - ModelType.EPIDEMIC_PREVENTION_MODEL.value[1]: ( - lambda x, y, r, t, z, h: IMModel(x, y, r, ModelType.EPIDEMIC_PREVENTION_MODEL, t, z, h), - ModelType.EPIDEMIC_PREVENTION_MODEL, - None, - lambda x: im_process(x)), - # 加载车牌模型 - ModelType.PLATE_MODEL.value[1]: ( - lambda x, y, r, t, z, h: IMModel(x, y, r, ModelType.PLATE_MODEL, t, z, h), - ModelType.PLATE_MODEL, - None, - lambda x: im_process(x)), - # 加载车辆模型 - ModelType.VEHICLE_MODEL.value[1]: ( - lambda x, y, r, t, z, h: TwoModel(x, y, r, ModelType.VEHICLE_MODEL, t, z, h), - ModelType.VEHICLE_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: forest_process(x) - ), - # 加载行人模型 - ModelType.PEDESTRIAN_MODEL.value[1]: ( - lambda x, y, r, t, z, h: TwoModel(x, y, r, ModelType.PEDESTRIAN_MODEL, t, z, h), - ModelType.PEDESTRIAN_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: forest_process(x)), - # 加载烟火模型 - ModelType.SMOGFIRE_MODEL.value[1]: ( - lambda x, y, r, t, z, h: TwoModel(x, y, r, ModelType.SMOGFIRE_MODEL, t, z, h), - ModelType.SMOGFIRE_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: forest_process(x)), - # 加载钓鱼游泳模型 - ModelType.ANGLERSWIMMER_MODEL.value[1]: ( - lambda x, y, r, t, z, h: TwoModel(x, y, r, ModelType.ANGLERSWIMMER_MODEL, t, z, h), - ModelType.ANGLERSWIMMER_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: forest_process(x)), - # 加载乡村模型 - ModelType.COUNTRYROAD_MODEL.value[1]: ( - lambda x, y, r, t, z, h: TwoModel(x, y, r, ModelType.COUNTRYROAD_MODEL, t, z, h), - ModelType.COUNTRYROAD_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: forest_process(x)), - # 加载船只模型 - ModelType.SHIP_MODEL.value[1]: ( - lambda x, y, r, t, z, h: ShipModel(x, y, r, ModelType.SHIP_MODEL, t, z, h), - ModelType.SHIP_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: obb_process(x)), - # 百度AI图片识别模型 - ModelType.BAIDU_MODEL.value[1]: ( - lambda x, y, r, t, z, h: BaiduAiImageModel(x, y, r, ModelType.BAIDU_MODEL, t, z, h), - ModelType.BAIDU_MODEL, - lambda x, y, z: baidu_label(x, y, z), - lambda x: baidu_process(x)), - # 航道模型 - ModelType.CHANNEL_EMERGENCY_MODEL.value[1]: ( - lambda x, y, r, t, z, h: TwoModel(x, y, r, ModelType.CHANNEL_EMERGENCY_MODEL, t, z, h), - ModelType.CHANNEL_EMERGENCY_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: forest_process(x)), # 河道检测模型 ModelType.RIVER2_MODEL.value[1]: ( lambda x, y, r, t, z, h: OneModel(x, y, r, ModelType.RIVER2_MODEL, t, z, h), ModelType.RIVER2_MODEL, lambda x, y, z: one_label(x, y, z), lambda x: model_process(x)), - # 城管模型 - ModelType.CITY_MANGEMENT_MODEL.value[1]: ( - lambda x, y, r, t, z, h: cityManagementModel(x, y, r, ModelType.CITY_MANGEMENT_MODEL, t, z, h), - ModelType.CITY_MANGEMENT_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: detSeg_demo2(x) - ), - # 人员落水模型 - ModelType.DROWING_MODEL.value[1]: ( - lambda x, y, r, t, z, h: OneModel(x, y, r, ModelType.DROWING_MODEL, t, z, h), - ModelType.DROWING_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 城市违章模型 - ModelType.NOPARKING_MODEL.value[1]: ( - lambda x, y, r, t, z, h: OneModel(x, y, r, ModelType.NOPARKING_MODEL, t, z, h), - ModelType.NOPARKING_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 车辆违停模型 - ModelType.ILLPARKING_MODEL.value[1]: ( - lambda x, y, r, t, z, h: OneModel(x, y, r, ModelType.ILLPARKING_MODEL, t, z, h), - ModelType.ILLPARKING_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 城市公路模型 - ModelType.CITYROAD_MODEL.value[1]: ( - lambda x, y, r, t, z, h: TwoModel(x, y, r, ModelType.CITYROAD_MODEL, t, z, h), - ModelType.CITYROAD_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: forest_process(x)), - # 加载坑槽模型 - ModelType.POTHOLE_MODEL.value[1]: ( - lambda x, y, r, t, z, h: TwoModel(x, y, r, ModelType.POTHOLE_MODEL, t, z, h), - ModelType.POTHOLE_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: forest_process(x) - ), - # 加载船只综合检测模型 - ModelType.CHANNEL2_MODEL.value[1]: ( - lambda x, y, r, t, z, h: MultiModel(x, y, r, ModelType.CHANNEL2_MODEL, t, z, h), - ModelType.CHANNEL2_MODEL, - lambda x, y, z: dynamics_label(x, y, z), - lambda x: channel2_process(x) - ), - # 河道检测模型 - ModelType.RIVERT_MODEL.value[1]: ( - lambda x, y, r, t, z, h: OneModel(x, y, r, ModelType.RIVERT_MODEL, t, z, h), - ModelType.RIVERT_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x)), - # 加载森林人群模型 - ModelType.FORESTCROWD_FARM_MODEL.value[1]: ( - lambda x, y, r, t, z, h: cityManagementModel(x, y, r, ModelType.FORESTCROWD_FARM_MODEL, t, z, h), - ModelType.FORESTCROWD_FARM_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: detSeg_demo2(x) - ), - # 加载交通模型 - ModelType.TRAFFICFORDSJ_FARM_MODEL.value[1]: ( - lambda x, y, r, t, z, h: OneModel(x, y, r, ModelType.TRAFFIC_FARM_MODEL, t, z, h), - ModelType.TRAFFIC_FARM_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 加载智慧工地模型 - ModelType.SMARTSITE_MODEL.value[1]: ( - lambda x, y, r, t, z, h: cityManagementModel(x, y, r, ModelType.SMARTSITE_MODEL, t, z, h), - ModelType.SMARTSITE_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: detSeg_demo2(x) - ), - - # 加载垃圾模型 - ModelType.RUBBISH_MODEL.value[1]: ( - lambda x, y, r, t, z, h: cityManagementModel(x, y, r, ModelType.RUBBISH_MODEL, t, z, h), - ModelType.RUBBISH_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: detSeg_demo2(x) - ), - - # 加载烟花模型 - ModelType.FIREWORK_MODEL.value[1]: ( - lambda x, y, r, t, z, h: cityManagementModel(x, y, r, ModelType.FIREWORK_MODEL, t, z, h), - ModelType.FIREWORK_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: detSeg_demo2(x) - ), - # 加载高速公路抛撒物模型 - ModelType.TRAFFIC_SPILL_MODEL.value[1]: ( - lambda x, y, r, t, z, h: OneModel(x, y, r, ModelType.TRAFFIC_SPILL_MODEL, t, z, h), - ModelType.TRAFFIC_SPILL_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 加载高速公路危化品模型 - ModelType.TRAFFIC_CTHC_MODEL.value[1]: ( - lambda x, y, r, t, z, h: OneModel(x, y, r, ModelType.TRAFFIC_CTHC_MODEL, t, z, h), - ModelType.TRAFFIC_CTHC_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 加载光伏板异常检测模型 - ModelType.TRAFFIC_PANNEL_MODEL.value[1]: ( - lambda x, y, r, t, z, h: cityManagementModel(x, y, r, ModelType.TRAFFIC_PANNEL_MODEL, t, z, h), - ModelType.TRAFFIC_PANNEL_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: detSeg_demo2(x) - ), - # 加载红外行人检测模型 - ModelType.CITY_INFRAREDPERSON_MODEL.value[1]: ( - lambda x, y, r, t, z, h: cityManagementModel(x, y, r, ModelType.CITY_INFRAREDPERSON_MODEL, t, z, h), - ModelType.CITY_INFRAREDPERSON_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: detSeg_demo2(x) - ), - # 加载夜间烟火检测模型 - ModelType.CITY_NIGHTFIRESMOKE_MODEL.value[1]: ( - lambda x, y, r, t, z, h: cityManagementModel(x, y, r, ModelType.CITY_NIGHTFIRESMOKE_MODEL, t, z, h), - ModelType.CITY_NIGHTFIRESMOKE_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: detSeg_demo2(x) - ), + } diff --git a/util/ModelUtils2.py b/util/ModelUtils2.py deleted file mode 100644 index 67efcbb..0000000 --- a/util/ModelUtils2.py +++ /dev/null @@ -1,442 +0,0 @@ -# -*- coding: utf-8 -*- -import sys -from json import dumps, loads -from traceback import format_exc - -import cv2 -from loguru import logger - -from common.Constant import COLOR -from enums.BaiduSdkEnum import VehicleEnum -from enums.ExceptionEnum import ExceptionType -from enums.ModelTypeEnum2 import ModelType2, BAIDU_MODEL_TARGET_CONFIG2 -from exception.CustomerException import ServiceException -from util.ImgBaiduSdk import AipBodyAnalysisClient, AipImageClassifyClient -from util.PlotsUtils import get_label_arrays -from util.TorchUtils import select_device -import time -import torch -import tensorrt as trt - -sys.path.extend(['..', '../AIlib2']) -from AI import AI_process, get_postProcess_para, get_postProcess_para_dic, AI_det_track, AI_det_track_batch, AI_det_track_batch_N -from stdc import stdcModel -from utilsK.jkmUtils import pre_process, post_process, get_return_data -from obbUtils.shipUtils import OBB_infer, OBB_tracker, draw_obb, OBB_tracker_batch -from obbUtils.load_obb_model import load_model_decoder_OBB -from trackUtils.sort import Sort -from trackUtils.sort_obb import OBB_Sort -from DMPR import DMPRModel - -FONT_PATH = "../AIlib2/conf/platech.ttf" - - -class Model: - __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) - trackPar = par['trackPar'] - names = par['labelnames'] - detPostPar = par['postFile'] - rainbows = detPostPar["rainbows"] - #第一步加载模型 - modelList=[ modelPar['model'](weights=modelPar['weight'],par=modelPar['par']) for modelPar in par['models'] ] - #第二步准备跟踪参数 - trackPar=par['trackPar'] - sort_tracker = Sort(max_age=trackPar['sort_max_age'], - min_hits=trackPar['sort_min_hits'], - iou_threshold=trackPar['sort_iou_thresh']) - postProcess = par['postProcess'] - model_param = { - "modelList": modelList, - "postProcess": postProcess, - "sort_tracker": sort_tracker, - "trackPar": trackPar, - } - self.model_conf = (modeType, model_param, allowedList, names, rainbows) - except Exception: - logger.error("模型加载异常:{}, requestId:{}", format_exc(), requestId) - raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0], - ExceptionType.MODEL_LOADING_EXCEPTION.value[1]) - -def get_label_arraylist(*args): - width, height, names, rainbows = args - # line = int(round(0.002 * (height + width) / 2) + 1) - line = max(1, int(round(width / 1920 * 3))) - tf = max(line, 1) - fontScale = line * 0.33 - text_width, text_height = cv2.getTextSize(' 0.95', 0, fontScale=fontScale, thickness=tf)[0] - label_arraylist = get_label_arrays(names, rainbows, fontSize=text_height, fontPath=FONT_PATH) - return label_arraylist, (line, text_width, text_height, fontScale, tf) - - -""" -输入: - imgarray_list--图像列表 - iframe_list -- 帧号列表 - modelPar--模型参数,字典,modelPar={'det_Model':,'seg_Model':} - processPar--字典,存放检测相关参数,'half', 'device', 'conf_thres', 'iou_thres','trtFlag_det' - sort_tracker--对象,初始化的跟踪对象。为了保持一致,即使是单帧也要有。 - trackPar--跟踪参数,关键字包括:det_cnt,windowsize - segPar--None,分割模型相关参数。如果用不到,则为None -输入:retResults,timeInfos - retResults:list - retResults[0]--imgarray_list - retResults[1]--所有结果用numpy格式,所有的检测结果,包括8类,每列分别是x1, y1, x2, y2, conf, detclass,iframe,trackId - retResults[2]--所有结果用list表示,其中每一个元素为一个list,表示每一帧的检测结果,每一个结果是由多个list构成,每个list表示一个框,格式为[ cls , x0 ,y0 ,x1 ,y1 ,conf,ifrmae,trackId ],如 retResults[2][j][k]表示第j帧的第k个框。 -""" - - -def model_process(args): - # (modeType, model_param, allowedList, names, rainbows) - imgarray_list, iframe_list, model_param, request_id = args - try: - return AI_det_track_batch_N(imgarray_list, iframe_list, - model_param['modelList'], - model_param['postProcess'], - model_param['sort_tracker'], - model_param['trackPar']) - except ServiceException as s: - raise s - except Exception: - # self.num += 1 - # cv2.imwrite('/home/th/tuo_heng/dev/img%s.jpg' % str(self.num), frame) - logger.error("算法模型分析异常: {}, requestId: {}", format_exc(), request_id) - raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0], - ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1]) - - -# 船只模型 -class ShipModel: - __slots__ = "model_conf" - - def __init__(self, device, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None, env=None): - s = time.time() - try: - logger.info("########################加载船只模型########################, requestId:{}", requestId) - par = modeType.value[4](str(device), gpu_name) - obbModelPar = par['obbModelPar'] - model, decoder2 = load_model_decoder_OBB(obbModelPar) - obbModelPar['decoder'] = decoder2 - names = par['labelnames'] - rainbows = par['postFile']["rainbows"] - trackPar = par['trackPar'] - sort_tracker = OBB_Sort(max_age=trackPar['sort_max_age'], min_hits=trackPar['sort_min_hits'], - iou_threshold=trackPar['sort_iou_thresh']) - modelPar = {'obbmodel': model} - segPar = None - model_param = { - "modelPar": modelPar, - "obbModelPar": obbModelPar, - "sort_tracker": sort_tracker, - "trackPar": trackPar, - "segPar": segPar - } - self.model_conf = (modeType, model_param, allowedList, names, rainbows) - except Exception: - logger.exception("模型加载异常:{}, requestId:{}", format_exc(), requestId) - raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0], - ExceptionType.MODEL_LOADING_EXCEPTION.value[1]) - logger.info("模型初始化时间:{}, requestId:{}", time.time() - s, requestId) - - -def obb_process(args): - imgarray_list, iframe_list, model_param, request_id = args - try: - return OBB_tracker_batch(imgarray_list, iframe_list, model_param['modelPar'], model_param['obbModelPar'], - model_param['sort_tracker'], model_param['trackPar'], model_param['segPar']) - except ServiceException as s: - raise s - except Exception: - # self.num += 1 - # cv2.imwrite('/home/th/tuo_heng/dev/img%s.jpg' % str(self.num), frame) - logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), request_id) - raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0], - ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1]) - - -# 车牌分割模型、健康码、行程码分割模型 -class IMModel: - __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) - img_type = 'code' - if ModelType2.PLATE_MODEL == modeType: - img_type = 'plate' - par = { - 'code': {'weights': '../AIlib2/weights/conf/jkm/health_yolov5s_v3.jit', 'img_type': 'code', 'nc': 10}, - 'plate': {'weights': '../AIlib2/weights/conf/jkm/plate_yolov5s_v3.jit', 'img_type': 'plate', 'nc': 1}, - 'conf_thres': 0.4, - 'iou_thres': 0.45, - 'device': 'cuda:%s' % device, - 'plate_dilate': (0.5, 0.3) - } - new_device = torch.device(par['device']) - model = torch.jit.load(par[img_type]['weights']) - model_param = { - "device": new_device, - "model": model, - "par": par, - "img_type": img_type - } - self.model_conf = (modeType, model_param, allowedList) - except Exception: - logger.error("模型加载异常:{}, requestId:{}", format_exc(), requestId) - raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0], - ExceptionType.MODEL_LOADING_EXCEPTION.value[1]) - - -def im_process(args): - model_param, frame, request_id = args - device, par, img_type = model_param['device'], model_param['par'], model_param['img_type'] - try: - img, padInfos = pre_process(frame, device) - pred = model_param['model'](img) - boxes = post_process(pred, padInfos, device, conf_thres=par['conf_thres'], - iou_thres=par['iou_thres'], nc=par[img_type]['nc']) # 后处理 - dataBack = get_return_data(frame, boxes, modelType=img_type, plate_dilate=par['plate_dilate']) - return dataBack - except ServiceException as s: - raise s - except Exception: - logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), request_id) - raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0], - ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1]) - - -# 百度AI图片识别模型 -class BaiduAiImageModel: - __slots__ = "model_conf" - - def __init__(self, device=None, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None, - env=None): - try: - logger.info("########################加载{}########################, requestId:{}", modeType.value[2], - requestId) - aipBodyAnalysisClient = AipBodyAnalysisClient(base_dir, env) - aipImageClassifyClient = AipImageClassifyClient(base_dir, env) - rainbows = COLOR - vehicle_names = [VehicleEnum.CAR.value[1], VehicleEnum.TRICYCLE.value[1], VehicleEnum.MOTORBIKE.value[1], - VehicleEnum.CARPLATE.value[1], VehicleEnum.TRUCK.value[1], VehicleEnum.BUS.value[1]] - person_names = ['人'] - model_param = { - "vehicle_client": aipImageClassifyClient, - "person_client": aipBodyAnalysisClient, - } - self.model_conf = (modeType, model_param, allowedList, (vehicle_names, person_names), rainbows) - except Exception: - logger.exception("模型加载异常:{}, requestId:{}", format_exc(), requestId) - raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0], - ExceptionType.MODEL_LOADING_EXCEPTION.value[1]) - - -def baidu_process(args): - model_param, target, url, request_id = args - try: - baiduEnum = BAIDU_MODEL_TARGET_CONFIG2.get(target) - if baiduEnum is None: - raise ServiceException(ExceptionType.DETECTION_TARGET_TYPES_ARE_NOT_SUPPORTED.value[0], - ExceptionType.DETECTION_TARGET_TYPES_ARE_NOT_SUPPORTED.value[1] - + " target: " + target) - return baiduEnum.value[2](model_param['vehicle_client'], model_param['person_client'], url, request_id) - except ServiceException as s: - raise s - except Exception: - logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), request_id) - raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0], - ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1]) - - -def get_baidu_label_arraylist(*args): - width, height, vehicle_names, person_names, rainbows = args - # line = int(round(0.002 * (height + width) / 2) + 1) - line = max(1, int(round(width / 1920 * 3) + 1)) - label = ' 0.97' - tf = max(line, 1) - fontScale = line * 0.33 - text_width, text_height = cv2.getTextSize(label, 0, fontScale=fontScale, thickness=tf)[0] - vehicle_label_arrays = get_label_arrays(vehicle_names, rainbows, fontSize=text_height, fontPath=FONT_PATH) - person_label_arrays = get_label_arrays(person_names, rainbows, fontSize=text_height, fontPath=FONT_PATH) - font_config = (line, text_width, text_height, fontScale, tf) - return vehicle_label_arrays, person_label_arrays, font_config - - -def one_label(width, height, model_config): - # (modeType, model_param, allowedList, names, rainbows) - names = model_config[3] - rainbows = model_config[4] - label_arraylist, font_config = get_label_arraylist(width, height, names, rainbows) - model_config[1]['label_arraylist'] = label_arraylist - model_config[1]['font_config'] = font_config - - -def baidu_label(width, height, model_config): - # modeType, model_param, allowedList, (vehicle_names, person_names), rainbows - vehicle_names = model_config[3][0] - person_names = model_config[3][1] - rainbows = model_config[4] - vehicle_label_arrays, person_label_arrays, font_config = get_baidu_label_arraylist(width, height, vehicle_names, - person_names, rainbows) - model_config[1]['vehicle_label_arrays'] = vehicle_label_arrays - model_config[1]['person_label_arrays'] = person_label_arrays - model_config[1]['font_config'] = font_config - - - - -def model_process1(args): - imgarray_list, iframe_list, model_param, request_id = args - model_conf, frame, request_id = args - model_param, names, rainbows = model_conf[1], model_conf[3], model_conf[4] - # modeType, model_param, allowedList, names, rainbows = model_conf - # segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId = args - # model_param['digitFont'] = digitFont - # model_param['label_arraylist'] = label_arraylist - # model_param['font_config'] = font_config - try: - return AI_process([frame], model_param['model'], model_param['segmodel'], names, model_param['label_arraylist'], - rainbows, objectPar=model_param['objectPar'], font=model_param['digitFont'], - segPar=loads(dumps(model_param['segPar'])), mode=model_param['mode'], - postPar=model_param['postPar']) - except ServiceException as s: - raise s - except Exception: - # self.num += 1 - # cv2.imwrite('/home/th/tuo_heng/dev/img%s.jpg' % str(self.num), frame) - logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), request_id) - raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0], - ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1]) - - -MODEL_CONFIG2 = { - # 加载河道模型 - ModelType2.WATER_SURFACE_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.WATER_SURFACE_MODEL, t, z, h), - ModelType2.WATER_SURFACE_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 加载森林模型 - ModelType2.FOREST_FARM_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.FOREST_FARM_MODEL, t, z, h), - ModelType2.FOREST_FARM_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 加载交通模型 - ModelType2.TRAFFIC_FARM_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.TRAFFIC_FARM_MODEL, t, z, h), - ModelType2.TRAFFIC_FARM_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 加载防疫模型 - ModelType2.EPIDEMIC_PREVENTION_MODEL.value[1]: ( - lambda x, y, r, t, z, h: IMModel(x, y, r, ModelType2.EPIDEMIC_PREVENTION_MODEL, t, z, h), - ModelType2.EPIDEMIC_PREVENTION_MODEL, - None, - lambda x: im_process(x)), - # 加载车牌模型 - ModelType2.PLATE_MODEL.value[1]: ( - lambda x, y, r, t, z, h: IMModel(x, y, r, ModelType2.PLATE_MODEL, t, z, h), - ModelType2.PLATE_MODEL, - None, - lambda x: im_process(x)), - # 加载车辆模型 - ModelType2.VEHICLE_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.VEHICLE_MODEL, t, z, h), - ModelType2.VEHICLE_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 加载行人模型 - ModelType2.PEDESTRIAN_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.PEDESTRIAN_MODEL, t, z, h), - ModelType2.PEDESTRIAN_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x)), - # 加载烟火模型 - ModelType2.SMOGFIRE_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.SMOGFIRE_MODEL, t, z, h), - ModelType2.SMOGFIRE_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x)), - # 加载钓鱼游泳模型 - ModelType2.ANGLERSWIMMER_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.ANGLERSWIMMER_MODEL, t, z, h), - ModelType2.ANGLERSWIMMER_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x)), - # 加载乡村模型 - ModelType2.COUNTRYROAD_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.COUNTRYROAD_MODEL, t, z, h), - ModelType2.COUNTRYROAD_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x)), - # 加载船只模型 - ModelType2.SHIP_MODEL.value[1]: ( - lambda x, y, r, t, z, h: ShipModel(x, y, r, ModelType2.SHIP_MODEL, t, z, h), - ModelType2.SHIP_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: obb_process(x)), - # 百度AI图片识别模型 - ModelType2.BAIDU_MODEL.value[1]: ( - lambda x, y, r, t, z, h: BaiduAiImageModel(x, y, r, ModelType2.BAIDU_MODEL, t, z, h), - ModelType2.BAIDU_MODEL, - lambda x, y, z: baidu_label(x, y, z), - lambda x: baidu_process(x)), - # 航道模型 - ModelType2.CHANNEL_EMERGENCY_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.CHANNEL_EMERGENCY_MODEL, t, z, h), - ModelType2.CHANNEL_EMERGENCY_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x)), - # 河道检测模型 - ModelType2.RIVER2_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.RIVER2_MODEL, t, z, h), - ModelType2.RIVER2_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x)), - # 城管模型 - ModelType2.CITY_MANGEMENT_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.CITY_MANGEMENT_MODEL, t, z, h), - ModelType2.CITY_MANGEMENT_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 人员落水模型 - ModelType2.DROWING_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.DROWING_MODEL, t, z, h), - ModelType2.DROWING_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 城市违章模型 - ModelType2.NOPARKING_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.NOPARKING_MODEL, t, z, h), - ModelType2.NOPARKING_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 城市公路模型 - ModelType2.CITYROAD_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.CITYROAD_MODEL, t, z, h), - ModelType2.CITYROAD_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), - # 加载坑槽模型 - ModelType2.POTHOLE_MODEL.value[1]: ( - lambda x, y, r, t, z, h: Model(x, y, r, ModelType2.POTHOLE_MODEL, t, z, h), - ModelType2.POTHOLE_MODEL, - lambda x, y, z: one_label(x, y, z), - lambda x: model_process(x) - ), -} diff --git a/util/PlotsUtils.py b/util/PlotsUtils.py index ddbbce3..f1243c1 100644 --- a/util/PlotsUtils.py +++ b/util/PlotsUtils.py @@ -2,9 +2,10 @@ import cv2 import numpy as np from PIL import Image, ImageDraw, ImageFont import unicodedata +from loguru import logger FONT_PATH = "../AIlib2/conf/platech.ttf" -zhFont = ImageFont.truetype(FONT_PATH, 20, encoding="utf-8") +zhFont = ImageFont.truetype(FONT_PATH, 20, encoding="utf-8") def get_label_array(color=None, label=None, font=None, fontSize=40, unify=False): if unify: @@ -67,6 +68,12 @@ def xywh2xyxy2(param): # return [(lt, yt), (rt, yt), (rt, yr), (lt, yr)] 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): # 识别问题描述图片的高、宽 @@ -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) 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): # det0为 (m1, 11) 矩阵 @@ -251,8 +263,106 @@ def filterBox(det0, det1, pix_dis): x_c, y_c = (x3+x4)//2, (y3+y4)//2 dis = (x2_c - x_c)**2 + (y2_c - y_c)**2 mask = (joint_det[..., 9] == joint_det[..., 20]) & (dis <= pix_dis**2) - + # 类别相同 & 中心点在上一帧的框内 判断为True res = np.sum(mask, axis=1) det0_copy[..., -1] = res - return det0_copy \ No newline at end of file + 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 \ No newline at end of file diff --git a/util/TorchUtils.py b/util/TorchUtils.py index fc87839..b062eb6 100644 --- a/util/TorchUtils.py +++ b/util/TorchUtils.py @@ -70,7 +70,7 @@ def select_device(device='0'): # 设置环境变量 os.environ['CUDA_VISIBLE_DEVICES'] = device assert torch.cuda.is_available(), f'CUDA unavailable, invalid device {device} requested' - return torch.device('cuda:%s' % device) + return torch.device('cuda:1') # def select_device(device='', batch_size=None): diff --git a/vodsdk/common/__pycache__/Constant.cpython-310.pyc b/vodsdk/common/__pycache__/Constant.cpython-310.pyc deleted file mode 100644 index d164c38..0000000 Binary files a/vodsdk/common/__pycache__/Constant.cpython-310.pyc and /dev/null differ diff --git a/vodsdk/common/__pycache__/Constant.cpython-38.pyc b/vodsdk/common/__pycache__/Constant.cpython-38.pyc deleted file mode 100644 index 73d6a84..0000000 Binary files a/vodsdk/common/__pycache__/Constant.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/common/__pycache__/YmlConstant.cpython-38.pyc b/vodsdk/common/__pycache__/YmlConstant.cpython-38.pyc deleted file mode 100644 index 30975e0..0000000 Binary files a/vodsdk/common/__pycache__/YmlConstant.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/common/__pycache__/__init__.cpython-310.pyc b/vodsdk/common/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 58366ca..0000000 Binary files a/vodsdk/common/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/vodsdk/common/__pycache__/__init__.cpython-38.pyc b/vodsdk/common/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 03bd997..0000000 Binary files a/vodsdk/common/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/CommonThread.cpython-38.pyc b/vodsdk/concurrency/__pycache__/CommonThread.cpython-38.pyc deleted file mode 100644 index 1a1ff99..0000000 Binary files a/vodsdk/concurrency/__pycache__/CommonThread.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/FeedbackThread.cpython-38.pyc b/vodsdk/concurrency/__pycache__/FeedbackThread.cpython-38.pyc deleted file mode 100644 index ea9bb03..0000000 Binary files a/vodsdk/concurrency/__pycache__/FeedbackThread.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/FileUploadThread.cpython-38.pyc b/vodsdk/concurrency/__pycache__/FileUploadThread.cpython-38.pyc deleted file mode 100644 index e00f621..0000000 Binary files a/vodsdk/concurrency/__pycache__/FileUploadThread.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/HeartbeatThread.cpython-38.pyc b/vodsdk/concurrency/__pycache__/HeartbeatThread.cpython-38.pyc deleted file mode 100644 index 0f848db..0000000 Binary files a/vodsdk/concurrency/__pycache__/HeartbeatThread.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/IntelligentRecognitionProcess.cpython-38.pyc b/vodsdk/concurrency/__pycache__/IntelligentRecognitionProcess.cpython-38.pyc deleted file mode 100644 index 013cd6c..0000000 Binary files a/vodsdk/concurrency/__pycache__/IntelligentRecognitionProcess.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/IntelligentRecognitionProcess2.cpython-38.pyc b/vodsdk/concurrency/__pycache__/IntelligentRecognitionProcess2.cpython-38.pyc deleted file mode 100644 index ba056c0..0000000 Binary files a/vodsdk/concurrency/__pycache__/IntelligentRecognitionProcess2.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/Pull2PushStreamProcess.cpython-38.pyc b/vodsdk/concurrency/__pycache__/Pull2PushStreamProcess.cpython-38.pyc deleted file mode 100644 index c312d3d..0000000 Binary files a/vodsdk/concurrency/__pycache__/Pull2PushStreamProcess.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/Pull2PushStreamThread.cpython-38.pyc b/vodsdk/concurrency/__pycache__/Pull2PushStreamThread.cpython-38.pyc deleted file mode 100644 index eb13c99..0000000 Binary files a/vodsdk/concurrency/__pycache__/Pull2PushStreamThread.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/PullMqttThread.cpython-38.pyc b/vodsdk/concurrency/__pycache__/PullMqttThread.cpython-38.pyc deleted file mode 100644 index 46040b3..0000000 Binary files a/vodsdk/concurrency/__pycache__/PullMqttThread.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/PullStreamThread.cpython-38.pyc b/vodsdk/concurrency/__pycache__/PullStreamThread.cpython-38.pyc deleted file mode 100644 index f92df66..0000000 Binary files a/vodsdk/concurrency/__pycache__/PullStreamThread.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/PullVideoStreamProcess.cpython-38.pyc b/vodsdk/concurrency/__pycache__/PullVideoStreamProcess.cpython-38.pyc deleted file mode 100644 index 51d27cb..0000000 Binary files a/vodsdk/concurrency/__pycache__/PullVideoStreamProcess.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/PullVideoStreamProcess2.cpython-38.pyc b/vodsdk/concurrency/__pycache__/PullVideoStreamProcess2.cpython-38.pyc deleted file mode 100644 index bf5c126..0000000 Binary files a/vodsdk/concurrency/__pycache__/PullVideoStreamProcess2.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/PushStreamThread.cpython-38.pyc b/vodsdk/concurrency/__pycache__/PushStreamThread.cpython-38.pyc deleted file mode 100644 index 338c44f..0000000 Binary files a/vodsdk/concurrency/__pycache__/PushStreamThread.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/PushStreamThread2.cpython-38.pyc b/vodsdk/concurrency/__pycache__/PushStreamThread2.cpython-38.pyc deleted file mode 100644 index be48993..0000000 Binary files a/vodsdk/concurrency/__pycache__/PushStreamThread2.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/PushVideoStreamProcess.cpython-38.pyc b/vodsdk/concurrency/__pycache__/PushVideoStreamProcess.cpython-38.pyc deleted file mode 100644 index 27cbd8c..0000000 Binary files a/vodsdk/concurrency/__pycache__/PushVideoStreamProcess.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/PushVideoStreamProcess2.cpython-38.pyc b/vodsdk/concurrency/__pycache__/PushVideoStreamProcess2.cpython-38.pyc deleted file mode 100644 index dfc1775..0000000 Binary files a/vodsdk/concurrency/__pycache__/PushVideoStreamProcess2.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/RecordingHeartbeatThread.cpython-38.pyc b/vodsdk/concurrency/__pycache__/RecordingHeartbeatThread.cpython-38.pyc deleted file mode 100644 index 3c2c11f..0000000 Binary files a/vodsdk/concurrency/__pycache__/RecordingHeartbeatThread.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/__init__.cpython-38.pyc b/vodsdk/concurrency/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index b963a8b..0000000 Binary files a/vodsdk/concurrency/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/concurrency/__pycache__/uploadGPU.cpython-38.pyc b/vodsdk/concurrency/__pycache__/uploadGPU.cpython-38.pyc deleted file mode 100644 index 0928cb6..0000000 Binary files a/vodsdk/concurrency/__pycache__/uploadGPU.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/entity/__pycache__/FeedBack.cpython-38.pyc b/vodsdk/entity/__pycache__/FeedBack.cpython-38.pyc deleted file mode 100644 index 0785694..0000000 Binary files a/vodsdk/entity/__pycache__/FeedBack.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/entity/__pycache__/__init__.cpython-38.pyc b/vodsdk/entity/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 40746d9..0000000 Binary files a/vodsdk/entity/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/enums/__pycache__/AnalysisStatusEnum.cpython-38.pyc b/vodsdk/enums/__pycache__/AnalysisStatusEnum.cpython-38.pyc deleted file mode 100644 index f571b45..0000000 Binary files a/vodsdk/enums/__pycache__/AnalysisStatusEnum.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/enums/__pycache__/AnalysisTypeEnum.cpython-38.pyc b/vodsdk/enums/__pycache__/AnalysisTypeEnum.cpython-38.pyc deleted file mode 100644 index 2e06f47..0000000 Binary files a/vodsdk/enums/__pycache__/AnalysisTypeEnum.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/enums/__pycache__/BaiduSdkEnum.cpython-310.pyc b/vodsdk/enums/__pycache__/BaiduSdkEnum.cpython-310.pyc deleted file mode 100644 index d3391b0..0000000 Binary files a/vodsdk/enums/__pycache__/BaiduSdkEnum.cpython-310.pyc and /dev/null differ diff --git a/vodsdk/enums/__pycache__/BaiduSdkEnum.cpython-38.pyc b/vodsdk/enums/__pycache__/BaiduSdkEnum.cpython-38.pyc deleted file mode 100644 index e79c754..0000000 Binary files a/vodsdk/enums/__pycache__/BaiduSdkEnum.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/enums/__pycache__/ExceptionEnum.cpython-310.pyc b/vodsdk/enums/__pycache__/ExceptionEnum.cpython-310.pyc deleted file mode 100644 index f05bf3b..0000000 Binary files a/vodsdk/enums/__pycache__/ExceptionEnum.cpython-310.pyc and /dev/null differ diff --git a/vodsdk/enums/__pycache__/ExceptionEnum.cpython-38.pyc b/vodsdk/enums/__pycache__/ExceptionEnum.cpython-38.pyc deleted file mode 100644 index e2126d1..0000000 Binary files a/vodsdk/enums/__pycache__/ExceptionEnum.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/enums/__pycache__/ModelTypeEnum.cpython-38.pyc b/vodsdk/enums/__pycache__/ModelTypeEnum.cpython-38.pyc deleted file mode 100644 index 9dd09f3..0000000 Binary files a/vodsdk/enums/__pycache__/ModelTypeEnum.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/enums/__pycache__/ModelTypeEnum2.cpython-38.pyc b/vodsdk/enums/__pycache__/ModelTypeEnum2.cpython-38.pyc deleted file mode 100644 index b4815eb..0000000 Binary files a/vodsdk/enums/__pycache__/ModelTypeEnum2.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/enums/__pycache__/RecordingStatusEnum.cpython-38.pyc b/vodsdk/enums/__pycache__/RecordingStatusEnum.cpython-38.pyc deleted file mode 100644 index b7c0f70..0000000 Binary files a/vodsdk/enums/__pycache__/RecordingStatusEnum.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/enums/__pycache__/StatusEnum.cpython-38.pyc b/vodsdk/enums/__pycache__/StatusEnum.cpython-38.pyc deleted file mode 100644 index ec5fb91..0000000 Binary files a/vodsdk/enums/__pycache__/StatusEnum.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/enums/__pycache__/__init__.cpython-310.pyc b/vodsdk/enums/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index d0c53ad..0000000 Binary files a/vodsdk/enums/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/vodsdk/enums/__pycache__/__init__.cpython-38.pyc b/vodsdk/enums/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 17fbca0..0000000 Binary files a/vodsdk/enums/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/exception/__pycache__/CustomerException.cpython-310.pyc b/vodsdk/exception/__pycache__/CustomerException.cpython-310.pyc deleted file mode 100644 index b3b91b5..0000000 Binary files a/vodsdk/exception/__pycache__/CustomerException.cpython-310.pyc and /dev/null differ diff --git a/vodsdk/exception/__pycache__/CustomerException.cpython-38.pyc b/vodsdk/exception/__pycache__/CustomerException.cpython-38.pyc deleted file mode 100644 index 473fc42..0000000 Binary files a/vodsdk/exception/__pycache__/CustomerException.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/exception/__pycache__/__init__.cpython-310.pyc b/vodsdk/exception/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 80858e8..0000000 Binary files a/vodsdk/exception/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/vodsdk/exception/__pycache__/__init__.cpython-38.pyc b/vodsdk/exception/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 5fb7efd..0000000 Binary files a/vodsdk/exception/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/service/__pycache__/Dispatcher.cpython-310.pyc b/vodsdk/service/__pycache__/Dispatcher.cpython-310.pyc deleted file mode 100644 index 060bc19..0000000 Binary files a/vodsdk/service/__pycache__/Dispatcher.cpython-310.pyc and /dev/null differ diff --git a/vodsdk/service/__pycache__/Dispatcher.cpython-38.pyc b/vodsdk/service/__pycache__/Dispatcher.cpython-38.pyc deleted file mode 100644 index 1919f51..0000000 Binary files a/vodsdk/service/__pycache__/Dispatcher.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/service/__pycache__/__init__.cpython-310.pyc b/vodsdk/service/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index d0d3a66..0000000 Binary files a/vodsdk/service/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/vodsdk/service/__pycache__/__init__.cpython-38.pyc b/vodsdk/service/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index a52c2a3..0000000 Binary files a/vodsdk/service/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/AliyunSdk.cpython-38.pyc b/vodsdk/util/__pycache__/AliyunSdk.cpython-38.pyc deleted file mode 100644 index ff407b8..0000000 Binary files a/vodsdk/util/__pycache__/AliyunSdk.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/CpuUtils.cpython-38.pyc b/vodsdk/util/__pycache__/CpuUtils.cpython-38.pyc deleted file mode 100644 index 8380bad..0000000 Binary files a/vodsdk/util/__pycache__/CpuUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/Cv2Utils.cpython-38.pyc b/vodsdk/util/__pycache__/Cv2Utils.cpython-38.pyc deleted file mode 100644 index e879d50..0000000 Binary files a/vodsdk/util/__pycache__/Cv2Utils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/FileUtils.cpython-38.pyc b/vodsdk/util/__pycache__/FileUtils.cpython-38.pyc deleted file mode 100644 index 0fe7fa8..0000000 Binary files a/vodsdk/util/__pycache__/FileUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/GPUtils.cpython-38.pyc b/vodsdk/util/__pycache__/GPUtils.cpython-38.pyc deleted file mode 100644 index 46b5a42..0000000 Binary files a/vodsdk/util/__pycache__/GPUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/ImageUtils.cpython-310.pyc b/vodsdk/util/__pycache__/ImageUtils.cpython-310.pyc deleted file mode 100644 index 74f8546..0000000 Binary files a/vodsdk/util/__pycache__/ImageUtils.cpython-310.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/ImageUtils.cpython-38.pyc b/vodsdk/util/__pycache__/ImageUtils.cpython-38.pyc deleted file mode 100644 index 44a32f2..0000000 Binary files a/vodsdk/util/__pycache__/ImageUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/ImgBaiduSdk.cpython-38.pyc b/vodsdk/util/__pycache__/ImgBaiduSdk.cpython-38.pyc deleted file mode 100644 index 99f5be9..0000000 Binary files a/vodsdk/util/__pycache__/ImgBaiduSdk.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/KafkaUtils.cpython-38.pyc b/vodsdk/util/__pycache__/KafkaUtils.cpython-38.pyc deleted file mode 100644 index 96daf51..0000000 Binary files a/vodsdk/util/__pycache__/KafkaUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/LocationUtils.cpython-38.pyc b/vodsdk/util/__pycache__/LocationUtils.cpython-38.pyc deleted file mode 100644 index e1d16ee..0000000 Binary files a/vodsdk/util/__pycache__/LocationUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/LogUtils.cpython-38.pyc b/vodsdk/util/__pycache__/LogUtils.cpython-38.pyc deleted file mode 100644 index d6eeb6e..0000000 Binary files a/vodsdk/util/__pycache__/LogUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/MinioSdk.cpython-38.pyc b/vodsdk/util/__pycache__/MinioSdk.cpython-38.pyc deleted file mode 100644 index 3ef6bab..0000000 Binary files a/vodsdk/util/__pycache__/MinioSdk.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/ModelUtils.cpython-38.pyc b/vodsdk/util/__pycache__/ModelUtils.cpython-38.pyc deleted file mode 100644 index 2381de6..0000000 Binary files a/vodsdk/util/__pycache__/ModelUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/ModelUtils2.cpython-38.pyc b/vodsdk/util/__pycache__/ModelUtils2.cpython-38.pyc deleted file mode 100644 index 29b6a09..0000000 Binary files a/vodsdk/util/__pycache__/ModelUtils2.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/OcrBaiduSdk.cpython-38.pyc b/vodsdk/util/__pycache__/OcrBaiduSdk.cpython-38.pyc deleted file mode 100644 index e8af1ec..0000000 Binary files a/vodsdk/util/__pycache__/OcrBaiduSdk.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/PlotsUtils.cpython-38.pyc b/vodsdk/util/__pycache__/PlotsUtils.cpython-38.pyc deleted file mode 100644 index db14438..0000000 Binary files a/vodsdk/util/__pycache__/PlotsUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/PushStreamUtils.cpython-38.pyc b/vodsdk/util/__pycache__/PushStreamUtils.cpython-38.pyc deleted file mode 100644 index 1d96aec..0000000 Binary files a/vodsdk/util/__pycache__/PushStreamUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/QueUtil.cpython-38.pyc b/vodsdk/util/__pycache__/QueUtil.cpython-38.pyc deleted file mode 100644 index dec6224..0000000 Binary files a/vodsdk/util/__pycache__/QueUtil.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/RWUtils.cpython-38.pyc b/vodsdk/util/__pycache__/RWUtils.cpython-38.pyc deleted file mode 100644 index 28455a7..0000000 Binary files a/vodsdk/util/__pycache__/RWUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/TimeUtils.cpython-38.pyc b/vodsdk/util/__pycache__/TimeUtils.cpython-38.pyc deleted file mode 100644 index 1a50bb9..0000000 Binary files a/vodsdk/util/__pycache__/TimeUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/TorchUtils.cpython-38.pyc b/vodsdk/util/__pycache__/TorchUtils.cpython-38.pyc deleted file mode 100644 index fedd5ab..0000000 Binary files a/vodsdk/util/__pycache__/TorchUtils.cpython-38.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/__init__.cpython-310.pyc b/vodsdk/util/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 20efd09..0000000 Binary files a/vodsdk/util/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/vodsdk/util/__pycache__/__init__.cpython-38.pyc b/vodsdk/util/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index bf6d77c..0000000 Binary files a/vodsdk/util/__pycache__/__init__.cpython-38.pyc and /dev/null differ