|
- # -*- coding: utf-8 -*-
- import sys
- from pickle import dumps, loads
- from traceback import format_exc
-
- from loguru import logger
-
- from common.Constant import COLOR
- from enums.ExceptionEnum import ExceptionType
- from enums.ModelTypeEnum import ModelType, BAIDU_MODEL_TARGET_CONFIG
- from exception.CustomerException import ServiceException
- from util.ImgBaiduSdk import AipBodyAnalysisClient, AipImageClassifyClient
- 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, AI_Seg_process, ocr_process
- import time
- from segutils.segmodel import SegModel
- from models.experimental import attempt_load
- from utils.torch_utils import select_device
- from utilsK.queRiver import get_labelnames, get_label_arrays, save_problem_images
- 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
-
- FONTPATH = "../AIlib2/conf/platech.ttf"
-
-
- # 河道模型
- class RiverModel:
- __slots__ = "model_conf"
-
- def __init__(self, device, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
- try:
- logger.info("########################加载河道模型########################, requestId:{}", requestId)
- trtFlag_det = True
- trtFlag_seg = True
- # 公共变量
- par = {
- 'device': str(device),
- 'labelnames': ["排口", "水生植被", "其它", "漂浮物", "污染排口", "菜地", "违建", "岸坡垃圾"],
- 'detModelpara': [],
- 'seg_nclass': 2,
- 'segRegionCnt': 1,
- 'slopeIndex': [5, 6, 7],
- 'segPar': {
- 'modelSize': (640, 360),
- 'mean': (0.485, 0.456, 0.406),
- 'std': (0.229, 0.224, 0.225),
- 'numpy': False,
- 'RGB_convert_first': True
- },
- 'postFile': {
- "name": "post_process",
- "conf_thres": 0.25,
- "iou_thres": 0.45,
- "classes": 5,
- "rainbows": COLOR
- }
- }
- if trtFlag_det:
- par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], gpu_name)
- else:
- par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
- if trtFlag_seg:
- par['segweights'] = '../AIlib2/weights/%s/stdc_360X640_%s_fp16.engine' % (modeType.value[3], gpu_name)
- else:
- par['segweights'] = '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3]
- mode = 'others'
- postPar = None
- segPar = par.get('segPar')
- new_device = select_device(par.get('device'))
- names = par.get('labelnames')
- half = new_device.type != 'cpu'
- Detweights = par.get('detweights') # 升级后的检测模型
- if 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)
- if half:
- model.half()
- Segweights = par.get('segweights')
- if trtFlag_seg:
- with open(Segweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
- segmodel = runtime.deserialize_cuda_engine(f.read())
- else:
- segmodel = SegModel(nclass=par.get('seg_nclass'), weights=Segweights, device=new_device)
- conf_thres = par.get('postFile').get("conf_thres")
- iou_thres = par.get('postFile').get("iou_thres")
- # classes = par.get('postFile').get("classes")
- rainbows = par.get('postFile').get("rainbows")
- objectPar = {
- 'half': half,
- 'device': new_device,
- 'conf_thres': conf_thres,
- 'iou_thres': iou_thres,
- 'allowedList': [],
- 'slopeIndex': par.get('slopeIndex'),
- 'segRegionCnt': par.get('segRegionCnt'),
- 'trtFlag_det': trtFlag_det,
- 'trtFlag_seg': trtFlag_seg
- }
- """
- frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
- """
- model_param = [None, model, segmodel, names, None, rainbows, objectPar, None, segPar, mode, postPar,
- requestId]
- self.model_conf = (modeType, allowedList, model_param)
- 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(width, names, rainbows):
- fontsize = int(width / 1920 * 40)
- line_thickness = 1
- boxLine_thickness = 1
- waterLineWidth = 1
- if width >= 960:
- line_thickness = int(round(width / 1920 * 3) - 1)
- boxLine_thickness = int(round(width / 1920 * 3))
- waterLineWidth = int(round(width / 1920 * 3))
- numFontSize = float(format(width / 1920 * 1.1, '.1f')) # 文字大小
- digitFont = {'line_thickness': line_thickness,
- 'boxLine_thickness': boxLine_thickness,
- 'fontSize': numFontSize,
- 'waterLineColor': (0, 255, 255),
- 'segLineShow': False,
- 'waterLineWidth': waterLineWidth}
- label_arraylist = get_label_arrays(names, rainbows, outfontsize=fontsize,
- fontpath=FONTPATH)
- return digitFont, label_arraylist
-
- '''
- #输入参数
- # im0s---原始图像列表
- # model---检测模型,segmodel---分割模型(如若没有用到,则为None)
- #输出:两个元素(列表,字符)构成的元组,[im0s[0],im0,det_xywh,iframe],strout
- # [im0s[0],im0,det_xywh,iframe]中,
- # im0s[0]--原始图像,im0--AI处理后的图像,iframe--帧号/暂时不需用到。
- # det_xywh--检测结果,是一个列表。
- # 其中每一个元素表示一个目标构成如:[float(cls_c), xc,yc,w,h, float(conf_c)]
- # #cls_c--类别,如0,1,2,3; xc,yc,w,h--中心点坐标及宽;conf_c--得分, 取值范围在0-1之间
- # #strout---统计AI处理个环节的时间
- '''
-
-
- def model_process(param):
- # frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
- try:
- return AI_process([param[0]], param[1], param[2], param[3], param[4], param[5], objectPar=param[6],
- font=param[7], segPar=param[8], mode=param[9], postPar=param[10])
- 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(), param[11])
- raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0],
- ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1])
-
-
- # 河道检测模型
- class River2Model:
- __slots__ = "model_conf"
-
- def __init__(self, device, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
- try:
- logger.info("########################加载河道检测模型########################, requestId:{}", requestId)
- trtFlag_det = True, # 检测模型是否采用TRT
- trtFlag_seg = True, # 分割模型是否采用TRT
- # 公共变量
- par = {
- 'device': str(device),
- 'labelnames': [
- "漂浮物", "岸坡垃圾", "排口", "违建", "菜地", "水生植物", "河湖人员", "钓鱼人员", "船只", "蓝藻"],
- 'detModelpara': [],
- 'seg_nclass': 2,
- 'segRegionCnt': 1,
- 'slopeIndex': [1, 3, 4, 7],
- 'segPar': {
- 'modelSize': (640, 360),
- 'mean': (0.485, 0.456, 0.406),
- 'std': (0.229, 0.224, 0.225),
- 'numpy': False,
- 'RGB_convert_first': True
- },
- 'postFile': {
- "name": "post_process",
- "conf_thres": 0.25,
- "iou_thres": 0.45,
- "ovlap_thres_crossCategory": 0.65,
- "classes": 5,
- "rainbows": COLOR
- }
- }
- if trtFlag_det:
- par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], gpu_name)
-
- else:
- par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
- if trtFlag_seg:
- par['segweights'] = '../AIlib2/weights/%s/stdc_360X640_%s_fp16.engine' % (modeType.value[3], gpu_name)
- else:
- par['segweights'] = '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3]
- mode = 'others'
- postPar = None
- new_device = select_device(par.get('device')) # 指定GPU
- names = par.get('labelnames')
- half = new_device.type != 'cpu'
- Detweights = par.get('detweights') # 升级后的检测模型
- if 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)
- if half:
- model.half()
- segPar = par.get('segPar')
- Segweights = par.get('segweights')
- if trtFlag_seg:
- with open(Segweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
- segmodel = runtime.deserialize_cuda_engine(f.read())
- else:
- segmodel = SegModel(nclass=par.get('seg_nclass'), weights=Segweights, device=new_device)
- conf_thres = par.get('postFile').get("conf_thres")
- iou_thres = par.get('postFile').get("iou_thres")
- # classes = par.get('postFile').get("classes")
- rainbows = par.get('postFile').get("rainbows")
- postFile = par.get('postFile')
- ovlap_thres_crossCategory = postFile.get('ovlap_thres_crossCategory')
- objectPar = {
- 'half': half,
- 'device': new_device,
- 'conf_thres': conf_thres,
- 'ovlap_thres_crossCategory': ovlap_thres_crossCategory,
- 'iou_thres': iou_thres,
- 'allowedList': [],
- 'slopeIndex': par.get('slopeIndex'),
- 'segRegionCnt': par.get('segRegionCnt'),
- 'trtFlag_det': trtFlag_det,
- 'trtFlag_seg': trtFlag_seg
- }
- """
- frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar,
- requestId
- """
- model_param = [None, model, segmodel, names, None, rainbows, objectPar, None, segPar, mode, postPar,
- requestId]
- self.model_conf = (modeType, allowedList, model_param)
- except Exception:
- logger.error("模型加载异常:{}, requestId:{}", format_exc(), requestId)
- raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0],
- ExceptionType.MODEL_LOADING_EXCEPTION.value[1])
-
-
- # 高速模型
- class HighWayModel:
- __slots__ = "model_conf"
-
- def __init__(self, device, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
- s = time.time()
- try:
- logger.info("########################加载高速模型########################, requestId:{}", requestId)
- trtFlag_det = True, # 检测模型是否采用TRT
- trtFlag_seg = True, # 分割模型是否采用TRT
- # 公共变量
- par = {
- 'device': str(device),
- 'gpu_name': gpu_name,
- 'labelnames': ["行人", "车辆", "纵向裂缝", "横向裂缝", "修补", "网状裂纹", "坑槽", "块状裂纹", "积水",
- "事故"],
- 'slopeIndex': [],
- '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
- },
- 'postPar': {
- 'label_csv': '../AIlib2/weights/conf/%s/class_dict.csv' % modeType.value[3],
- 'speedRoadArea': 16000,
- 'vehicleArea': 10,
- 'speedRoadVehicleAngleMin': 15,
- 'speedRoadVehicleAngleMax': 75,
- 'roundness': 0.7,
- 'cls': 9,
- 'vehicleFactor': 0.1
- },
- 'mode': 'highWay3.0',
- 'postFile': {
- "name": "post_process",
- "conf_thres": 0.25,
- "iou_thres": 0.25,
- "classes": 9,
- "rainbows": COLOR
- }
- }
- if trtFlag_det:
- par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], par['gpu_name'])
- else:
- par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
- if trtFlag_seg:
- par['segweights'] = '../AIlib2/weights/%s/stdc_360X640_%s_fp16.engine' % (
- modeType.value[3], par['gpu_name'])
- else:
- par['segweights'] = '../AIlib2/weights/conf/%s/stdc_360X640.pth' % modeType.value[3]
- mode = par.get('mode', 'others')
- postPar = par.get('postPar', None)
-
- new_device = select_device(par.get('device')) # 指定GPU
- names = par.get('labelnames')
- half = new_device.type != 'cpu'
- Detweights = par.get('detweights') # 升级后的检测模型
- if 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)
- if half:
- model.half()
- segPar = par.get('segPar')
- Segweights = par.get('segweights')
- if trtFlag_seg:
- with open(Segweights, "rb") as f, trt.Runtime(trt.Logger(trt.Logger.ERROR)) as runtime:
- segmodel = runtime.deserialize_cuda_engine(f.read())
- else:
- seg_nclass = par.get('seg_nclass')
- segmodel = SegModel(nclass=seg_nclass, weights=Segweights, device=new_device)
- conf_thres = par.get('postFile').get("conf_thres")
- iou_thres = par.get('postFile').get("iou_thres")
- # classes = par.get('postFile').get("classes")
- rainbows = par.get('postFile').get("rainbows")
- objectPar = {
- 'half': half,
- 'device': new_device,
- 'conf_thres': conf_thres,
- 'iou_thres': iou_thres,
- 'allowedList': [],
- 'slopeIndex': par.get('slopeIndex'),
- 'segRegionCnt': par.get('segRegionCnt'),
- 'trtFlag_det': trtFlag_det,
- 'trtFlag_seg': trtFlag_seg
- }
- """
- frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
- """
- model_param = [None, model, segmodel, names, None, rainbows, objectPar, None, segPar, mode, postPar,
- requestId]
- self.model_conf = (modeType, allowedList, model_param)
- # self.num = 0
- 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)
-
- '''
- #输入参数
- # im0s---原始图像列表
- # model---检测模型,segmodel---分割模型(如若没有用到,则为None)
- #输出:两个元素(列表,字符)构成的元组,[im0s[0],im0,det_xywh,iframe],strout
- # [im0s[0],im0,det_xywh,iframe]中,
- # im0s[0]--原始图像,im0--AI处理后的图像,iframe--帧号/暂时不需用到。
- # det_xywh--检测结果,是一个列表。
- # 其中每一个元素表示一个目标构成如:[float(cls_c), xc,yc,w,h, float(conf_c)]
- # #cls_c--类别,如0,1,2,3; xc,yc,w,h--中心点坐标及宽;conf_c--得分, 取值范围在0-1之间
- # #strout---统计AI处理个环节的时间
- '''
-
-
- def high_process(param):
- try:
- # frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
- return AI_process([param[0]], param[1], param[2], param[3], param[4], param[5], objectPar=param[6],
- font=param[7], segPar=param[8], mode=param[9], postPar=loads(dumps(param[10])))
- 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(), param[11])
- raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0],
- ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1])
-
-
- # 森林模型
- class ForestModel:
- __slots__ = "model_conf"
-
- def __init__(self, device1, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
- s = time.time()
- try:
- logger.info("########################加载森林模型########################, requestId:{}", requestId)
- trtFlag_det = True, # 检测模型是否采用TRT
- # trtFlag_seg = False, # 分割模型是否采用TRT
- # 公共变量
- par = {
- 'device': str(device1),
- 'gpu_name': gpu_name,
- 'labelnames': ("林斑", "病死树", "行人", "火焰", "烟雾"),
- 'seg_nclass': 2,
- 'segRegionCnt': 0,
- 'slopeIndex': [],
- 'segPar': None,
- 'postFile': {
- "name": "post_process",
- "conf_thres": 0.25,
- "iou_thres": 0.45,
- "classes": 5,
- "rainbows": COLOR
- },
- 'segweights': None
- }
- if trtFlag_det:
- par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], par['gpu_name'])
- else:
- par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
- device = select_device(par.get('device'))
- names = par.get('labelnames')
- half = device.type != 'cpu'
- Detweights = par.get('detweights')
- if 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=device)
- if half:
- model.half()
- segmodel = None
- conf_thres = par.get('postFile').get("conf_thres")
- iou_thres = par.get('postFile').get("iou_thres")
- # classes = par.get('postFile').get("classes")
- rainbows = par.get('postFile').get("rainbows")
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param = [None, model, segmodel, names, None, rainbows, half, device, conf_thres, iou_thres, [], None,
- trtFlag_det, requestId]
- self.model_conf = (modeType, allowedList, model_param)
- 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(param):
- try:
- """
- # frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres, allowedList,
- digitFont, trtFlag_det, requestId
- """
-
- return AI_process_forest([param[0]], param[1], param[2], param[3], param[4], param[5], param[6], param[7],
- param[8], param[9], param[10], font=param[11], trtFlag_det=param[12])
- 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(), param[13])
- raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0],
- ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1])
-
-
- # 车辆模型
- class VehicleModel:
- __slots__ = "model_conf"
-
- def __init__(self, device1, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
- s = time.time()
- try:
- logger.info("########################加载车辆模型########################, requestId:{}", requestId)
- trtFlag_det = True, # 检测模型是否采用TRT
- # trtFlag_seg = False, # 分割模型是否采用TRT
- # 公共变量
- par = {
- 'device': str(device1),
- 'gpu_name': gpu_name,
- 'labelnames': ["车辆"],
- 'seg_nclass': 2, # 分割模型类别数目,默认2类
- 'segRegionCnt': 0,
- 'slopeIndex': [],
- 'segPar': None,
- 'postFile': {
- "name": "post_process",
- "conf_thres": 0.25,
- "iou_thres": 0.45,
- "classes": 5,
- "rainbows": COLOR
- },
- 'segweights': None
- }
- if trtFlag_det:
- par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], par['gpu_name'])
- else:
- par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
- device = select_device(par.get('device'))
- names = par.get('labelnames')
- half = device.type != 'cpu'
- Detweights = par.get('detweights')
- if 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=device)
- if half:
- model.half()
- segmodel = None
- conf_thres = par.get('postFile').get("conf_thres")
- iou_thres = par.get('postFile').get("iou_thres")
- # classes = par.get('postFile').get("classes")
- rainbows = par.get('postFile').get("rainbows")
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param = [None, model, segmodel, names, None, rainbows, half, device, conf_thres, iou_thres, [], None,
- trtFlag_det, requestId]
- self.model_conf = (modeType, allowedList, model_param)
- 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 get_label_arraylist_1(width, names, rainbows):
- fontsize = int(width / 1920 * 40)
- line_thickness = 1
- boxLine_thickness = 1
- waterLineWidth = 1
- if width >= 960:
- line_thickness = int(round(width / 1920 * 3) - 1)
- boxLine_thickness = int(round(width / 1920 * 3))
- waterLineWidth = int(round(width / 1920 * 3))
- numFontSize = float(format(width / 1920 * 1.1, '.1f')) # 文字大小
- digitFont = {'line_thickness': line_thickness,
- 'boxLine_thickness': boxLine_thickness,
- 'fontSize': numFontSize,
- 'segLineShow': False,
- 'waterLineColor': (0, 255, 255),
- 'waterLineWidth': waterLineWidth}
- label_arraylist = get_label_arrays(names, rainbows, outfontsize=fontsize, fontpath=FONTPATH)
- return digitFont, label_arraylist
-
-
- # 行人模型
- class PedestrianModel:
- __slots__ = "model_conf"
-
- def __init__(self, device1, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
- s = time.time()
- try:
- logger.info("########################加载行人模型########################, requestId:{}", requestId)
- trtFlag_det = True, # 检测模型是否采用TRT
- # trtFlag_seg = False, # 分割模型是否采用TRT
- # 公共变量
- par = {
- 'device': str(device1),
- 'gpu_name': gpu_name,
- 'labelnames': ["行人"],
- 'seg_nclass': 2,
- 'segRegionCnt': 0,
- 'slopeIndex': [],
- 'segPar': None,
- 'postFile': {
- "name": "post_process",
- "conf_thres": 0.25,
- "iou_thres": 0.45,
- "classes": 5,
- "rainbows": COLOR
- },
- 'segweights': None
- }
- if trtFlag_det:
- par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], par['gpu_name'])
- else:
- par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
- device = select_device(par.get('device')) # 指定GPU
- names = par.get('labelnames')
- half = device.type != 'cpu'
- Detweights = par.get('detweights') # 升级后的检测模型
- if 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=device)
- if half:
- model.half()
- segmodel = None
- conf_thres = par.get('postFile').get("conf_thres")
- iou_thres = par.get('postFile').get("iou_thres")
- # classes = par.get('postFile').get("classes")
- rainbows = par.get('postFile').get("rainbows")
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param = [None, model, segmodel, names, None, rainbows, half, device, conf_thres, iou_thres, [], None,
- trtFlag_det, requestId]
- self.model_conf = (modeType, allowedList, model_param)
- 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)
-
-
- # 烟火模型
- class SmogfireModel:
- __slots__ = "model_conf"
-
- def __init__(self, device1, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
- s = time.time()
- try:
- logger.info("########################加载烟火模型########################, requestId:{}", requestId)
- trtFlag_det = True, # 检测模型是否采用TRT
- # trtFlag_seg = False, # 分割模型是否采用TRT
- # 公共变量
- par = {
- 'device': str(device1),
- 'gpu_name': gpu_name,
- 'labelnames': ["烟雾", "火焰"],
- 'seg_nclass': 2, # 分割模型类别数目,默认2类
- 'segRegionCnt': 0,
- 'slopeIndex': [],
- 'segPar': None,
- 'postFile': {
- "name": "post_process",
- "conf_thres": 0.25,
- "iou_thres": 0.45,
- "classes": 5,
- "rainbows": COLOR
- },
- 'segweights': None
- }
- if trtFlag_det:
- par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], par['gpu_name'])
- else:
- par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
- device = select_device(par.get('device')) # 指定GPU
- names = par.get('labelnames')
- half = device.type != 'cpu'
- Detweights = par.get('detweights') # 升级后的检测模型
- if 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=device)
- if half:
- model.half()
- segmodel = None
- conf_thres = par.get('postFile').get("conf_thres")
- iou_thres = par.get('postFile').get("iou_thres")
- # classes = par.get('postFile').get("classes")
- rainbows = par.get('postFile').get("rainbows")
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param = [None, model, segmodel, names, None, rainbows, half, device, conf_thres, iou_thres, [], None,
- trtFlag_det, requestId]
- self.model_conf = (modeType, allowedList, model_param)
- 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)
-
-
- # 钓鱼模型
- class AnglerSwimmerModel:
- __slots__ = "model_conf"
-
- def __init__(self, device1, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
- s = time.time()
- try:
- logger.info("########################加载钓鱼模型########################, requestId:{}", requestId)
- trtFlag_det = True, # 检测模型是否采用TRT
- # trtFlag_seg = False, # 分割模型是否采用TRT
- # 公共变量
- par = {
- 'device': str(device1),
- 'gpu_name': gpu_name,
- 'labelnames': ["钓鱼", "游泳"],
- 'seg_nclass': 2, # 分割模型类别数目,默认2类
- 'segRegionCnt': 0,
- 'slopeIndex': [],
- 'segPar': None,
- 'postFile': {
- "name": "post_process",
- "conf_thres": 0.25,
- "iou_thres": 0.45,
- "classes": 5,
- "rainbows": COLOR
- },
- 'segweights': None
- }
- if trtFlag_det:
- par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], par['gpu_name'])
- else:
- par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
- device = select_device(par.get('device')) # 指定GPU
- names = par.get('labelnames')
- half = device.type != 'cpu'
- Detweights = par.get('detweights') # 升级后的检测模型
- if 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=device)
- if half:
- model.half()
- segmodel = None
- conf_thres = par.get('postFile').get("conf_thres")
- iou_thres = par.get('postFile').get("iou_thres")
- # classes = par.get('postFile').get("classes")
- rainbows = par.get('postFile').get("rainbows")
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param = [None, model, segmodel, names, None, rainbows, half, device, conf_thres, iou_thres, [], None,
- trtFlag_det, requestId]
- self.model_conf = (modeType, allowedList, model_param)
- 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)
-
-
- # 乡村模型
- class CountryRoadModel:
- __slots__ = "model_conf"
-
- def __init__(self, device1, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
- s = time.time()
- try:
- logger.info("########################加载乡村模型########################, requestId:{}", requestId)
- trtFlag_det = True, # 检测模型是否采用TRT
- # trtFlag_seg = False, # 分割模型是否采用TRT
- # 公共变量
- par = {
- 'device': str(device1),
- 'gpu_name': gpu_name,
- 'labelnames': ["违法种植"],
- 'seg_nclass': 2, # 分割模型类别数目,默认2类
- 'segRegionCnt': 0,
- 'slopeIndex': [],
- 'segPar': None,
- 'postFile': {
- "name": "post_process",
- "conf_thres": 0.25,
- "iou_thres": 0.45,
- "classes": 5,
- "rainbows": COLOR
- },
- 'segweights': None
- }
- if trtFlag_det:
- par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], par['gpu_name'])
- else:
- par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
-
- device = select_device(par.get('device')) # 指定GPU
- names = par.get('labelnames')
- half = device.type != 'cpu'
- Detweights = par.get('detweights') # 升级后的检测模型
- if 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=device)
- if half:
- model.half()
- segmodel = None
- conf_thres = par.get('postFile').get("conf_thres")
- iou_thres = par.get('postFile').get("iou_thres")
- # classes = par.get('postFile').get("classes")
- rainbows = par.get('postFile').get("rainbows")
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param = [None, model, segmodel, names, None, rainbows, half, device, conf_thres, iou_thres, [], None,
- trtFlag_det, requestId]
- self.model_conf = (modeType, allowedList, model_param)
- 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)
-
-
- # 航道模型
- class ChannelEmergencyModel:
- __slots__ = "model_conf"
-
- def __init__(self, device1, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
- s = time.time()
- try:
- logger.info("########################加载航道模型########################, requestId:{}", requestId)
- trtFlag_det = True, # 检测模型是否采用TRT
- # trtFlag_seg = False, # 分割模型是否采用TRT
- # 公共变量
- par = {
- 'device': str(device1),
- 'gpu_name': gpu_name,
- 'labelnames': ["人"],
- 'seg_nclass': 2, # 分割模型类别数目,默认2类
- 'segRegionCnt': 0,
- 'slopeIndex': [],
- 'segPar': None,
- 'postFile': {
- "name": "post_process",
- "conf_thres": 0.25,
- "iou_thres": 0.45,
- "classes": 5,
- "rainbows": COLOR
- },
- 'segweights': None
- }
- if trtFlag_det:
- par['detweights'] = "../AIlib2/weights/%s/yolov5_%s_fp16.engine" % (modeType.value[3], par['gpu_name'])
- else:
- par['detweights'] = "../AIlib2/weights/conf/%s/yolov5.pt" % modeType.value[3]
-
- device = select_device(par.get('device')) # 指定GPU
- names = par.get('labelnames')
- half = device.type != 'cpu'
- Detweights = par.get('detweights') # 升级后的检测模型
- if 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=device)
- if half:
- model.half()
- segmodel = None
- conf_thres = par.get('postFile').get("conf_thres")
- iou_thres = par.get('postFile').get("iou_thres")
- # classes = par.get('postFile').get("classes")
- rainbows = par.get('postFile').get("rainbows")
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param = [None, model, segmodel, names, None, rainbows, half, device, conf_thres, iou_thres, [], None,
- trtFlag_det, requestId]
- self.model_conf = (modeType, allowedList, model_param)
- 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)
-
-
- # 船只模型
- class ShipModel:
- __slots__ = "model_conf"
-
- def __init__(self, device1, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
- s = time.time()
- try:
- logger.info("########################加载船只模型########################, requestId:{}", requestId)
- # 公共变量
- par = {
- 'model_size': (608, 608),
- 'K': 100,
- 'conf_thresh': 0.18,
- 'device': 'cuda:%s' % str(device1),
- 'down_ratio': 4,
- 'num_classes': 15,
- 'weights': '../AIlib2/weights/%s/obb_608X608_%s_fp16.engine' % (modeType.value[3], gpu_name),
- '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", "船只"),
- }
- model, decoder2 = load_model_decoder_OBB(par)
- par['decoder'] = decoder2
- names = par.get('labelnames')
- # conf_thres = par.get('postFile').get("conf_thres")
- # iou_thres = par.get('postFile').get("iou_thres")
- # classes = par.get('postFile').get("classes")
- rainbows = par.get('postFile').get("rainbows")
- """
- [frame, par, model, requestId]
- """
- model_param = [None, par, model, names, None, rainbows, requestId]
- self.model_conf = (modeType, allowedList, model_param)
- 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 get_label_arraylist_2(width, par, names, rainbows):
- fontsize = int(width / 1920 * 40)
- line_thickness = 1
- boxLine_thickness = 1
- if width >= 960:
- line_thickness = int(round(width / 1920 * 3) - 1)
- boxLine_thickness = int(round(width / 1920 * 3))
- numFontSize = float(format(width / 1920 * 1.1, '.1f')) # 文字大小
- par["digitWordFont"] = {
- 'line_thickness': line_thickness,
- 'boxLine_thickness': boxLine_thickness,
- 'wordSize': fontsize,
- 'fontSize': numFontSize,
- 'label_location': 'leftTop'
- }
- par["label_array"] = get_label_arrays(names, rainbows, outfontsize=fontsize, fontpath=FONTPATH)
-
-
- def obb_process(param):
- try:
- # [frame, par, model, requestId]
- return OBB_infer(param[2], param[0], param[1])
- 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(), param[3])
- raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0],
- ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1])
-
-
- # 车牌分割模型、健康码、行程码分割模型
- class IMModel:
- __slots__ = "model_conf"
-
- def __init__(self, device1, allowedList=None, requestId=None, modeType=None, gpu_name=None, base_dir=None):
- try:
- logger.info("########################加载{}########################, requestId:{}", modeType.value[2],
- requestId)
- img_type = 'code'
- if ModelType.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' % device1,
- 'plate_dilate': (0.5, 0.3)
- }
- device = torch.device(par['device'])
- model = torch.jit.load(par[img_type]['weights'])
- """
- [frame, device, model, par, img_type, requestId]
- """
- model_param = [None, device, model, par, img_type, requestId]
- self.model_conf = (modeType, allowedList, model_param)
- 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(param):
- try:
- # [frame, device, model, par, img_type, requestId]
- img, padInfos = pre_process(param[0], param[1])
- pred = param[2](img)
- boxes = post_process(pred, padInfos, param[1], conf_thres=param[3]['conf_thres'],
- iou_thres=param[3]['iou_thres'], nc=param[3][param[4]]['nc']) # 后处理
- dataBack = get_return_data(param[0], boxes, modelType=param[4], plate_dilate=param[3]['plate_dilate'])
- return dataBack
- except ServiceException as s:
- raise s
- except Exception:
- logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), param[5])
- raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0],
- ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1])
-
-
- # class OCR_Model:
- #
- # def __init__(self, device=None, logger=None, requestId=None):
- # try:
- # logger.info("######################## 加载OCR模型 ########################, requestId:{}", requestId)
- # self.__requestId = requestId
- # self.__logger = logger
- # self.__trtFlag_det = True
- # if self.__trtFlag_det:
- # gpu = get_all_gpu_ids()[int(device)]
- # if '3090' in gpu.name:
- # TRTfile = "../AIlib2/weights/ocr_en/english_g2_3090_fp16_448X32.engine"
- # elif '2080' in gpu.name:
- # TRTfile = "../AIlib2/weights/ocr_en/english_2080Ti_g2_h64_fp16.engine"
- # elif '4090' in gpu.name:
- # TRTfile = "../AIlib2/weights/ocr_en/english_g2_4090_fp16_448X32.engine"
- # elif 'A10' in gpu.name:
- # TRTfile = "../AIlib2/weights/ocr_en/english_g2_A10_fp16_448X32.engine"
- # else:
- # raise Exception("未匹配到该GPU名称的模型, GPU: " + gpu.name)
- # else:
- # TRTfile = "../AIlib2/weights/conf/ocr_en/english_g2.pth"
- # par = {
- # 'TRTfile': TRTfile,
- # 'device': 'cuda: %s' % device,
- # 'dict_list': {'en': '../AIlib2/weights/conf/ocr_en/en.txt'},
- # 'char_file': '../AIlib2/weights/conf/ocr_en/en_character.csv',
- # 'imgH': 100,
- # 'imgW': 400
- # }
- # TRTfile = par['TRTfile']
- # self.__device = par['device']
- # dict_list = par['dict_list']
- # char_file = par['char_file']
- # imgH = par['imgH']
- # imgW = par['imgW']
- # logger = trt.Logger(trt.Logger.ERROR)
- # with open(TRTfile, "rb") as f, trt.Runtime(logger) as runtime:
- # self.engine = runtime.deserialize_cuda_engine(f.read()) # 输入trt本地文件,返回ICudaEngine对象
- # print('#####load TRT file:', TRTfile, 'success #####')
- # self.context = self.engine.create_execution_context()
- #
- # with open(char_file, 'r') as fp:
- # characters = fp.readlines()[0].strip()
- # self.converter = CTCLabelConverter(characters, {}, dict_list)
- # self.AlignCollate_normal = AlignCollate(imgH=imgH, imgW=imgW, keep_ratio_with_pad=True)
- # except Exception as ee:
- # self.__logger.exception("模型加载异常:{}, requestId:{}", ee, requestId)
- # raise ServiceException(ExceptionType.MODEL_LOADING_EXCEPTION.value[0],
- # ExceptionType.MODEL_LOADING_EXCEPTION.value[1])
- #
- # def process(self, frame):
- # try:
- # gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- # par = [gray_frame, self.engine, self.context, self.converter, self.AlignCollate_normal, self.__device]
- # return ocr_process(par)
- # except ServiceException as s:
- # raise s
- # except Exception as ee:
- # self.__logger.exception("ocr坐标识别异常:{}, requestId:{}", ee, self.__requestId)
- # raise ServiceException(ExceptionType.COORDINATE_ACQUISITION_FAILED.value[0],
- # ExceptionType.COORDINATE_ACQUISITION_FAILED.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):
- try:
- logger.info("########################加载{}########################, requestId:{}", modeType.value[2],
- requestId)
- aipBodyAnalysisClient = AipBodyAnalysisClient(base_dir)
- aipImageClassifyClient = AipImageClassifyClient(base_dir)
- rainbows = COLOR
- """
- [target, url, aipImageClassifyClient, aipBodyAnalysisClient, requestId]
- """
- model_param = [None, None, aipImageClassifyClient, aipBodyAnalysisClient, requestId]
- self.model_conf = (modeType, allowedList, model_param, 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(param):
- try:
- # [target, url, aipImageClassifyClient, aipBodyAnalysisClient, requestId]
- baiduEnum = BAIDU_MODEL_TARGET_CONFIG.get(param[0])
- 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: " + param[0])
- return baiduEnum.value[2](param[2], param[3], param[1], param[4])
- except ServiceException as s:
- raise s
- except Exception:
- logger.error("算法模型分析异常:{}, requestId:{}", format_exc(), param[4])
- raise ServiceException(ExceptionType.MODEL_ANALYSE_EXCEPTION.value[0],
- ExceptionType.MODEL_ANALYSE_EXCEPTION.value[1])
-
-
- def river_label(width, model_param):
- names = model_param[3]
- rainbows = model_param[5]
- digitFont, label_arraylist = get_label_arraylist(width, names, rainbows)
- """
- frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
- """
- model_param[4] = label_arraylist
- model_param[7] = digitFont
-
-
- def river2_label(width, model_param):
- names = model_param[3]
- rainbows = model_param[5]
- digitFont, label_arraylist = get_label_arraylist(width, names, rainbows)
- """
- frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
- """
- model_param[4] = label_arraylist
- model_param[7] = digitFont
-
-
- def high_label(width, model_param):
- names = model_param[3]
- rainbows = model_param[5]
- digitFont, label_arraylist = get_label_arraylist(width, names, rainbows)
- """
- frame, model, segmodel, names, label_arraylist, rainbows, objectPar, font, segPar, mode, postPar, requestId
- """
- model_param[4] = label_arraylist
- model_param[7] = digitFont
-
-
- def forest_label(width, model_param):
- names = model_param[3]
- rainbows = model_param[5]
- digitFont, label_arraylist = get_label_arraylist(width, names, rainbows)
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param[4] = label_arraylist
- model_param[11] = digitFont
-
-
- def vehicle_label(width, model_param):
- names = model_param[3]
- rainbows = model_param[5]
- digitFont, label_arraylist = get_label_arraylist_1(width, names, rainbows)
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param[4] = label_arraylist
- model_param[11] = digitFont
-
-
- def pedestrian_label(width, model_param):
- names = model_param[3]
- rainbows = model_param[5]
- digitFont, label_arraylist = get_label_arraylist_1(width, names, rainbows)
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param[4] = label_arraylist
- model_param[11] = digitFont
-
-
- def channel_emergency_label(width, model_param):
- names = model_param[3]
- rainbows = model_param[5]
- digitFont, label_arraylist = get_label_arraylist_1(width, names, rainbows)
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param[4] = label_arraylist
- model_param[11] = digitFont
-
-
- def ship_label(width, model_param):
- # [None, par, model, names, None, rainbows, requestId]
- par = model_param[1]
- names = model_param[3]
- rainbows = model_param[5]
- get_label_arraylist_2(width, par, names, rainbows)
- model_param[4] = par["label_array"]
-
-
- def countryroad_label(width, model_param):
- names = model_param[3]
- rainbows = model_param[5]
- digitFont, label_arraylist = get_label_arraylist_1(width, names, rainbows)
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param[4] = label_arraylist
- model_param[11] = digitFont
-
-
- def anglerswimmer_label(width, model_param):
- names = model_param[3]
- rainbows = model_param[5]
- digitFont, label_arraylist = get_label_arraylist_1(width, names, rainbows)
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param[4] = label_arraylist
- model_param[11] = digitFont
-
-
- def smogfire_label(width, model_param):
- names = model_param[3]
- rainbows = model_param[5]
- digitFont, label_arraylist = get_label_arraylist_1(width, names, rainbows)
- """
- frame, model, segmodel, names, label_arraylist, rainbows, half, device, conf_thres, iou_thres,
- allowedList, digitFont, trtFlag_det, requestId
- """
- model_param[4] = label_arraylist
- model_param[11] = digitFont
-
-
- MODEL_CONFIG = {
- # 加载河道模型
- ModelType.WATER_SURFACE_MODEL.value[1]: (
- lambda x, y, r, t, z : RiverModel(x, y, r, ModelType.WATER_SURFACE_MODEL, t, z),
- ModelType.WATER_SURFACE_MODEL,
- lambda x, y: river_label(x, y),
- lambda x: model_process(x)
- ),
- # 加载森林模型
- ModelType.FOREST_FARM_MODEL.value[1]: (
- lambda x, y, r, t, z: ForestModel(x, y, r, ModelType.FOREST_FARM_MODEL, t, z),
- ModelType.FOREST_FARM_MODEL,
- lambda x, y: forest_label(x, y),
- lambda x: forest_process(x)
- ),
- # 加载交通模型
- ModelType.TRAFFIC_FARM_MODEL.value[1]: (
- lambda x, y, r, t, z: HighWayModel(x, y, r, ModelType.TRAFFIC_FARM_MODEL, t, z),
- ModelType.TRAFFIC_FARM_MODEL,
- lambda x, y: high_label(x, y),
- lambda x: high_process(x)
- ),
- # 加载防疫模型
- ModelType.EPIDEMIC_PREVENTION_MODEL.value[1]: (
- lambda x, y, r, t, z: IMModel(x, y, r, ModelType.EPIDEMIC_PREVENTION_MODEL, t, z),
- ModelType.EPIDEMIC_PREVENTION_MODEL,
- None,
- lambda x: im_process(x)),
- # 加载车牌模型
- ModelType.PLATE_MODEL.value[1]: (
- lambda x, y, r, t, z: IMModel(x, y, r, ModelType.PLATE_MODEL, t, z),
- ModelType.PLATE_MODEL,
- None,
- lambda x: im_process(x)),
- # 加载车辆模型
- ModelType.VEHICLE_MODEL.value[1]: (
- lambda x, y, r, t, z: VehicleModel(x, y, r, ModelType.VEHICLE_MODEL, t, z),
- ModelType.VEHICLE_MODEL,
- lambda x, y: vehicle_label(x, y),
- lambda x: forest_process(x)
- ),
- # 加载行人模型
- ModelType.PEDESTRIAN_MODEL.value[1]: (
- lambda x, y, r, t, z: PedestrianModel(x, y, r, ModelType.PEDESTRIAN_MODEL, t, z),
- ModelType.PEDESTRIAN_MODEL,
- lambda x, y: pedestrian_label(x, y),
- lambda x: forest_process(x)),
- # 加载烟火模型
- ModelType.SMOGFIRE_MODEL.value[1]: (
- lambda x, y, r, t, z: SmogfireModel(x, y, r, ModelType.SMOGFIRE_MODEL, t, z),
- ModelType.SMOGFIRE_MODEL,
- lambda x, y: smogfire_label(x, y),
- lambda x: forest_process(x)),
- # 加载钓鱼游泳模型
- ModelType.ANGLERSWIMMER_MODEL.value[1]: (
- lambda x, y, r, t, z: AnglerSwimmerModel(x, y, r, ModelType.ANGLERSWIMMER_MODEL, t, z),
- ModelType.ANGLERSWIMMER_MODEL,
- lambda x, y: anglerswimmer_label(x, y),
- lambda x: forest_process(x)),
- # 加载乡村模型
- ModelType.COUNTRYROAD_MODEL.value[1]: (
- lambda x, y, r, t, z: CountryRoadModel(x, y, r, ModelType.COUNTRYROAD_MODEL, t, z),
- ModelType.COUNTRYROAD_MODEL,
- lambda x, y: countryroad_label(x, y),
- lambda x: forest_process(x)),
- # 加载船只模型
- ModelType.SHIP_MODEL.value[1]: (
- lambda x, y, r, t, z: ShipModel(x, y, r, ModelType.SHIP_MODEL, t, z),
- ModelType.SHIP_MODEL,
- lambda x, y: ship_label(x, y),
- lambda x: obb_process(x)),
- # 百度AI图片识别模型
- ModelType.BAIDU_MODEL.value[1]: (
- lambda x, y, r, t, z: BaiduAiImageModel(x, y, r, ModelType.BAIDU_MODEL, t, z),
- ModelType.BAIDU_MODEL,
- None,
- lambda x: baidu_process(x)),
- # 航道模型
- ModelType.CHANNEL_EMERGENCY_MODEL.value[1]: (
- lambda x, y, r, t, z: ChannelEmergencyModel(x, y, r, ModelType.CHANNEL_EMERGENCY_MODEL, t, z),
- ModelType.CHANNEL_EMERGENCY_MODEL,
- lambda x, y: channel_emergency_label(x, y),
- lambda x: forest_process(x)),
- # 河道检测模型
- ModelType.RIVER2_MODEL.value[1]: (
- lambda x, y, r, t, z: River2Model(x, y, r, ModelType.RIVER2_MODEL, t, z),
- ModelType.RIVER2_MODEL,
- lambda x, y: river2_label(x, y),
- lambda x: model_process(x)
- )
- }
- # ModelConfig = namedtuple('ModelConfig', ('x', 'y', 'z'))
|