|
- import sys, yaml
- from easydict import EasyDict as edict
- from concurrent.futures import ThreadPoolExecutor
-
- sys.path.extend(['..','../AIlib2' ])
-
- from AI import AI_process,AI_process_forest,get_postProcess_para,get_postProcess_para_dic,ocr_process,AI_det_track,AI_det_track_batch,AI_det_track_batch_N,get_images_videos,default_mix
- import cv2,os,time
- from segutils.segmodel import SegModel
- from yolov5 import yolov5Model
- from stdc import stdcModel
- from segutils.trafficUtils import tracfficAccidentMixFunction
- 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,riverDetSegMixProcess,draw_painting_joint
- from ocrUtils.ocrUtils import CTCLabelConverter,AlignCollate
- from trackUtils.sort import Sort,track_draw_boxAndTrace,track_draw_trace_boxes,moving_average_wang,drawBoxTraceSimplied
- from trackUtils.sort_obb import OBB_Sort,obbTohbb,track_draw_all_boxes,track_draw_trace
- from obbUtils.shipUtils import OBB_infer,OBB_tracker,draw_obb,OBB_tracker_batch
- from utilsK.noParkingUtils import mixNoParking_road_postprocess
- from obbUtils.load_obb_model import load_model_decoder_OBB
- import numpy as np
- import torch,glob
- import tensorrt as trt
- from utilsK.masterUtils import get_needed_objectsIndex
- from copy import deepcopy
- from scipy import interpolate
- from utilsK.drownUtils import mixDrowing_water_postprocess
- #import warnings
- #warnings.filterwarnings("error")
- rainbows=[ [0,0,255],[0,255,0],[255,0,0],[255,0,255],[255,255,0],[255,129,0],[255,0,127],[127,255,0],[0,255,127],[0,127,255],[127,0,255],[255,127,255],[255,255,127],[127,255,255],[0,255,255],[255,127,255],[127,255,255], [0,127,0],[0,0,127],[0,255,255]]
- def drawAllBox(preds,imgDraw,label_arraylist,rainbows,font):
- for box in preds:
- #cls,conf,xyxy = box[0],box[5], box[1:5]
- #print('#'*20,'line47',box)
- cls,conf,xyxy = box[5],box[4], box[0:4] ##2023.08.03,修改了格式
- #print('#####line46 demo.py:', cls,conf,xyxy, len(label_arraylist),len(rainbows) )
- imgDraw = draw_painting_joint(xyxy,imgDraw,label_arraylist[int(cls)],score=conf,color=rainbows[int(cls)%20],font=font,socre_location="leftBottom")
- return imgDraw
- def get_drawPar(par):
- labelnames = par['labelnames']
- names=get_labelnames(labelnames)
- mode_paras=par['detModelpara']
- allowedList,allowedList_string=get_needed_objectsIndex(mode_paras)
- outfontsize=int(1080/1920*40);###
- label_arraylist = get_label_arrays(names,rainbows,outfontsize=par['txtFontSize'],fontpath="../AIlib2/conf/platech.ttf")
- drawPar={'names':names,'label_arraylist':label_arraylist,'rainbows':rainbows,'font': par['digitFont'],'allowedList':allowedList}
- return drawPar
- def view_bar(num, total,time1,prefix='prefix'):
- rate = num / total
- time_n=time.time()
- rate_num = int(rate * 30)
- rate_nums = np.round(rate * 100)
- r = '\r %s %d / %d [%s%s] %.2f s'%(prefix,num,total, ">" * rate_num, " " * (30 - rate_num), time_n-time1 )
- sys.stdout.write(r)
- sys.stdout.flush()
-
-
- '''
- 多线程
- '''
-
- def process_v1(frame):
- #try:
- print('demo.py beging to :',frame[8])
- time00 = time.time()
- H,W,C = frame[0][0].shape
-
- p_result,timeOut = AI_process(frame[0],frame[1],frame[2],frame[3],frame[4],frame[5],objectPar=frame[6],font=frame[7],segPar=frame[9],mode=frame[10],postPar=frame[11])
-
- time11 = time.time()
- image_array = p_result[1]
-
- cv2.imwrite(os.path.join('images/results/',frame[8] ) ,image_array)
- bname = frame[8].split('.')[0]
- if len(p_result)==5:
- image_mask = p_result[4]
- cv2.imwrite(os.path.join('images/results/',bname+'_mask.png' ) , (image_mask).astype(np.uint8))
-
- boxes=p_result[2]
- with open( os.path.join('images/results/',bname+'.txt' ),'w' ) as fp:
- for box in boxes:
- box_str=[str(x) for x in box]
- out_str=','.join(box_str)+'\n'
- fp.write(out_str)
- time22 = time.time()
- print('%s,%d*%d,AI-process: %.1f,image save:%.1f , %s'%(frame[8],H,W, (time11 - time00) * 1000.0, (time22-time11)*1000.0,timeOut), boxes)
- return 'success'
- #except Exception as e:
- # return 'failed:'+str(e)
- def process_video(video,par0,mode='detSeg'):
- cap=cv2.VideoCapture(video)
- if not cap.isOpened():
- print('#####error url:',video)
- return False
- bname=os.path.basename(video).split('.')[0]
- fps = int(cap.get(cv2.CAP_PROP_FPS)+0.5)
- width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH )+0.5)
- height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)+0.5)
- framecnt=int(cap.get(7)+0.5)
- save_path_AI = os.path.join(par0['outpth'],os.path.basename(video))
- problem_image_dir= os.path.join( par0['outpth'], 'probleImages' )
- os.makedirs(problem_image_dir,exist_ok=True)
- vid_writer_AI = cv2.VideoWriter(save_path_AI, cv2.VideoWriter_fourcc(*'mp4v'), fps, (width,height))
- num=0
- iframe=0;post_results=[];fpsample=30*10
-
- imgarray_list = []; iframe_list = []
-
- patch_cnt = par0['trackPar']['patchCnt']
- ##windowsize 对逐帧插值后的结果做平滑,windowsize为平滑的长度,没隔det_cnt帧做一次跟踪。
- trackPar={'det_cnt':10,'windowsize':29 }
-
-
- ##track_det_result_update= np.empty((0,8)) ###每100帧跑出来的结果,放在track_det_result_update,只保留当前100帧里有的tracker Id.
- while cap.isOpened():
- ret, imgarray = cap.read() #读取摄像头画面
- iframe +=1
- if not ret:break
- if mode=='detSeg':
- p_result,timeOut = AI_process([imgarray],par0['model'],par0['segmodel'],par0['names'],par0['label_arraylist'],par0['rainbows'],objectPar=par0['objectPar'],font=par0['digitFont'],segPar=par0['segPar'])
- elif mode == 'track':
- #sampleCount=10
- imgarray_list.append( imgarray )
- iframe_list.append(iframe )
- if iframe%patch_cnt==0:
- time_patch0 = time.time()
- #retResults,timeInfos = AI_det_track_batch(imgarray_list, iframe_list ,par0['modelPar'],par0['processPar'],par0['sort_tracker'] ,par0['trackPar'],segPar=par0['segPar'])
- retResults,timeInfos = AI_det_track_batch_N(imgarray_list, iframe_list ,par0['modelList'],par0['postProcess'],par0['sort_tracker'],par0['trackPar'])
- print('###line111:',retResults[2])
- ###需要保存成一个二维list,每一个list是一帧检测结果。
- ###track_det_result 内容格式:x1, y1, x2, y2, conf, cls,iframe,trackId
- time_patch2 = time.time()
- frame_min = iframe_list[0];frame_max=iframe_list[-1]
- for iiframe in range(frame_min,frame_max+1):
- img_draw = imgarray_list[ iiframe- frame_min ]
- img_draw = drawBoxTraceSimplied(retResults[1] ,iiframe, img_draw,rainbows=par0['drawPar']['rainbows'],boxFlag=True,traceFlag=True,names=par0['drawPar']['names'] )
- ret = vid_writer_AI.write(img_draw)
- view_bar(iiframe, framecnt,time.time(),prefix=os.path.basename(video))
- imgarray_list=[];iframe_list=[]
- elif mode =='obbTrack':
- imgarray_list.append( imgarray )
- iframe_list.append(iframe )
- if iframe%patch_cnt==0:
- time_patch0 = time.time()
-
- track_det_results, timeInfos = OBB_tracker_batch(imgarray_list,iframe_list,par0['modelPar'],par0['obbModelPar'],par0['sort_tracker'],par0['trackPar'],segPar=None)
- print( timeInfos )
-
- #对结果画图
- track_det_np = track_det_results[1]
- frame_min = iframe_list[0];frame_max=iframe_list[-1]
- for iiframe in range(frame_min,frame_max+1):
- img_draw = imgarray_list[ iiframe- frame_min ]
-
- if len( track_det_results[2][ iiframe- frame_min]) > 0:
- img_draw = draw_obb( track_det_results[2][iiframe- frame_min ] ,img_draw,par0['drawPar'])
- if True:
- frameIdex=12;trackIdex=13;
- boxes_oneFrame = track_det_np[ track_det_np[:,frameIdex]==iiframe ]
-
- ###在某一帧上,画上轨迹
- track_ids = boxes_oneFrame[:,trackIdex].tolist()
- boxes_before_oneFrame = track_det_np[ track_det_np[:,frameIdex]<=iiframe ]
- for trackId in track_ids:
- boxes_before_oneFrame_oneId = boxes_before_oneFrame[boxes_before_oneFrame[:,trackIdex]==trackId]
- xcs = boxes_before_oneFrame_oneId[:,8]
- ycs = boxes_before_oneFrame_oneId[:,9]
- [cv2.line(img_draw, ( int(xcs[i]) , int(ycs[i]) ),
- ( int(xcs[i+1]),int(ycs[i+1]) ),(255,0,0), thickness=2)
- for i,_ in enumerate(xcs) if i < len(xcs)-1 ]
-
- ret = vid_writer_AI.write(img_draw)
-
- #sys.exit(0)
- #print('vide writer ret:',ret)
- imgarray_list=[];iframe_list=[]
-
- view_bar(iframe, framecnt,time.time(),prefix=os.path.basename(video))
-
- else:
- p_result,timeOut = AI_process_forest([imgarray],par0['model'],par0['segmodel'],par0['names'],par0['label_arraylist'],par0['rainbows'],par0['half'],par0['device'],par0['conf_thres'], par0['iou_thres'],par0['allowedList'],font=par0['digitFont'],trtFlag_det=par0['trtFlag_det'])
-
-
- if mode not in [ 'track','obbTrack']:
- image_array = p_result[1];num+=1
- ret = vid_writer_AI.write(image_array)
- view_bar(num, framecnt,time.time(),prefix=os.path.basename(video))
- ##每隔 fpsample帧处理一次,如果有问题就保存图片
- if (iframe % fpsample == 0) and (len(post_results)>0) :
- parImage=save_problem_images(post_results,iframe,par0['names'],streamName=bname,outImaDir=problem_image_dir,imageTxtFile=False)
- post_results=[]
-
- if len(p_result[2] )>0:
- post_results.append(p_result)
-
- vid_writer_AI.release();
-
- def det_track_demo_N(business ):
- ####河道巡检的跟踪模型参数
- if opt['business'] == 'river' or opt['business'] == 'river2' or opt['business'] == 'riverT':
- from utilsK.queRiver import riverDetSegMixProcess_N
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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 } },
- },
- {
- 'weight':"../weights/%s/AIlib2/%s/stdc_360X640_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'weight':'../AIlib2/weights/conf/%s/stdc_360X640.pth'%(opt['business'] ),
- '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': '../AIlib2/weights/conf/%s/para.json'%( opt['business'] ),###后处理参数文件
- 'txtFontSize':80,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':3},###显示框、线设置
- #'testImgPath':'images/videos/river',###测试图像的位置
- 'testImgPath':'images/%s'%(opt['business']),###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
-
- }
-
- if opt['business'] == 'highWay2':
- from segutils.trafficUtils import tracfficAccidentMixFunction_N
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%( opt['business'] ), ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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': 10, 'vehicleFactor': 0.1,'cls':9, 'confThres':0.25,'roadIou':0.6,'vehicleFlag':False,'distanceFlag': False }
- },
- 'models':
- [
- {
- 'weight':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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 } },
- },
- {
- #'weight':"../weights/%s/AIlib2/%s/dmpr_%s.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- 'weight':'../AIlib2/weights/conf/%s/stdc_360X640.pth'%(opt['business'] ),
- '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': '../AIlib2/weights/conf/%s/para.json'%(opt['business'] ),###后处理参数文件
- 'txtFontSize':20,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':0.5,'waterLineColor':(0,255,255),'segLineShow':True,'waterLineWidth':2},###显示框、线设置
- #'testImgPath':'images/trafficAccident/8.png',###测试图像的位置
- #'testImgPath':'/home/chenyukun/777-7-42.mp4',###测试图像的位置
- 'testImgPath':'/mnt/thsw2/DSP2/weights/highWay2/images/',
- 'testOutPath':'images/results/',###输出测试图像位置
- }
- par['postProcess']['pars']['modelSize'] = par['models'][1]['par']['modelSize']
-
- if opt['business'] == 'noParking':
- from utilsK.noParkingUtils import mixNoParking_road_postprocess_N
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%( opt['business'] ), ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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}
- } ,
- 'models':
- [
- {
- 'weight':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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 } },
- },
- {
- #'weight':"../weights/%s/AIlib2/%s/dmpr_%s.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- 'weight':'../AIlib2/weights/conf/%s/stdc_360X640.pth'%(opt['business'] ),
- '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': '../AIlib2/weights/conf/%s/para.json'%('highWay2' ),###后处理参数文件
- 'txtFontSize':20,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'segLineShow':True,'waterLineWidth':2},###显示框、线设置
- 'testImgPath':'images/noParking/',###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
- par['postProcess']['pars']['modelSize'] = par['models'][1]['par']['modelSize']
-
- if opt['business'] == 'drowning':
- from utilsK.drownUtils import mixDrowing_water_postprocess_N
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%( opt['business'] ), ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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 } },
- },
- {
- #'weight':"../weights/%s/AIlib2/%s/dmpr_%s.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- 'weight':'../AIlib2/weights/conf/%s/stdc_360X640.pth'%(opt['business'] ),
- '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': '../AIlib2/weights/conf/%s/para.json'%('highWay2' ),###后处理参数文件
- 'txtFontSize':20,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'segLineShow':True,'waterLineWidth':2},###显示框、线设置
- 'testImgPath':'images/drowning/',###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
- par['postProcess']['pars']['modelSize'] = par['models'][1]['par']['modelSize']
-
- if opt['business'] == 'cityMangement2':
- from DMPR import DMPRModel
- from DMPRUtils.jointUtil import dmpr_yolo_stdc
-
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
- 'max_workers':1, ###并行线程数
- 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
- 'postProcess':{
- 'function':dmpr_yolo_stdc,
- 'pars':{'carCls':0 ,'illCls':3,'scaleRatio':0.5,'border':80}
- },
- 'models':
- [
- {
- #'weight':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- '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 } }
-
- },
- {
- #'weight':"../weights/%s/AIlib2/%s/dmpr_%s.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- 'weight':'../AIlib2/weights/conf/%s/dmpr.pth'%(opt['business'] ),
- 'par':{
- 'depth_factor':32,'NUM_FEATURE_MAP_CHANNEL':6,'dmpr_thresh':0.3, 'dmprimg_size':640,
- 'name':'dmpr'
- },
- 'model':DMPRModel,
- 'name':'dmpr'
- }
- ] ,
- 'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出
- 'postFile': '../AIlib2/weights/conf/%s/para.json'%(opt['business'] ),###后处理参数文件
- 'txtFontSize':20,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'segLineShow':True,'waterLineWidth':2},###显示框、线设置
- #'testImgPath':'/mnt/thsw2/DSP2/demoImages/illParking',###测试图像的位置
- 'testImgPath':'/mnt/thsw2/DSP2/weights/cityMangement2_0916/images/input',
- #'testImgPath':'images/cityMangement/',
- 'testOutPath':'images/results/',###输出测试图像位置
- }
-
- if opt['business'] == 'cityMangement3':
- from DMPR import DMPRModel
- from DMPRUtils.jointUtil import dmpr_yolo_stdc
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
- 'max_workers':1, ###并行线程数
- 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
- 'postProcess':{
- 'function':dmpr_yolo_stdc,
- 'pars':{'carCls':0 ,'illCls':3,'scaleRatio':0.5,'border':80}
- },
- 'models':[
- {
- 'weight':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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 } }
-
- },
- {
- 'weight':"../weights/%s/AIlib2/%s/dmpr_%s.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###DMPR模型路径
- #'weight':'../AIlib2/weights/conf/%s/dmpr.pth'%(opt['business'] ),
- 'par':{
- 'depth_factor':32,'NUM_FEATURE_MAP_CHANNEL':6,'dmpr_thresh':0.1, 'dmprimg_size':640,
- 'name':'dmpr'
- },
- 'model':DMPRModel,
- 'name':'dmpr'
- },
- {
- 'weight':"../weights/%s/AIlib2/%s/stdc_360X640_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###分割模型路径
-
- #'weight':'../AIlib2/weights/conf/%s/stdc_360X640.pth'%(opt['business'] ),
- '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': '../AIlib2/weights/conf/%s/para.json'%(opt['business'] ),###后处理参数文件
- 'txtFontSize':20,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'segLineShow':True,'waterLineWidth':2},###显示框、线设置
- 'testImgPath':'images/%s/'%(opt['business']),
- #'testImgPath':'/mnt/thsw2/DSP2/weights/cityMangement3/images/',
- 'testOutPath':'images/results/',###输出测试图像位置
- }
-
- if opt['business'] == 'forest2':
-
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/forest2/labelnames.json", ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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': '../AIlib2/weights/conf/forest/para.json',###后处理参数文件
- 'txtFontSize':80,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':3},###显示框、线设置
- 'testImgPath':'../AIdemo2/images/forest2/',###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
- ###车辆巡检参数
- if opt['business'] == 'vehicle':
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/vehicle/labelnames.json", ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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': '../AIlib2/weights/conf/vehicle/para.json',###后处理参数文件
- 'txtFontSize':40,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':3},###显示框、线设置
- 'testImgPath':'images/vehicle/',###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
- ###行人检测模型
- if opt['business'] == 'pedestrian':
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/pedestrian/labelnames.json", ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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': '../AIlib2/weights/conf/pedestrian/para.json',###后处理参数文件
- 'txtFontSize':40,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':3},###显示框、线设置
- 'testImgPath':'../AIdemo2/images/pedestrian/',###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
- if opt['business'] == 'smogfire':
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/smogfire/labelnames.json", ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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': '../AIlib2/weights/conf/smogfire/para.json',###后处理参数文件
- 'txtFontSize':40,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':3},###显示框、线设置
- 'testImgPath':'../AIdemo2/images/smogfire/',###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
- ###钓鱼游泳检测
- if opt['business'] == 'AnglerSwimmer':
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/AnglerSwimmer/labelnames.json", ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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': '../AIlib2/weights/conf/AnglerSwimmer/para.json',###后处理参数文件
- 'txtFontSize':40,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':3},###显示框、线设置
- 'testImgPath':'../AIdemo2/images/AnglerSwimmer/',###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
- #单独的“坑槽”检测
- if opt['business'] == 'pothole':
-
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/pothole/labelnames.json", ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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': '../AIlib2/weights/conf/forest/para.json',###后处理参数文件
- 'txtFontSize':80,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':3},###显示框、线设置
- 'testImgPath':'../AIdemo2/images/pothole/',###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
-
- ###航道应急,做落水人员检测, channelEmergency
- if opt['business'] == 'channelEmergency':
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/channelEmergency/labelnames.json", ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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': '../AIlib2/weights/conf/channelEmergency/para.json',###后处理参数文件
- 'txtFontSize':40,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':3},###显示框、线设置
- 'testImgPath':'../AIdemo2/images/channelEmergency/',###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
-
- ###乡村路违法种植
- if opt['business'] == 'countryRoad':
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/countryRoad/labelnames.json", ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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': '../AIlib2/weights/conf/countryRoad/para.json',###后处理参数文件
- 'txtFontSize':40,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':3},###显示框、线设置
- 'testImgPath':'../AIdemo2/images/countryRoad/',###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
-
- ###城管项目,检测城市垃圾和车辆
- if opt['business'] == 'cityMangement':
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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': '../AIlib2/weights/conf/%s/para.json'%(opt['business']),###后处理参数文件
- 'txtFontSize':40,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':3},###显示框、线设置
- 'testImgPath':'images/cityMangement',###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
- ###城管项目,检测道路情况,输入类别为五个:"护栏","交通标志","非交通标志","施工","施工“(第4,第5类别合并,名称相同)
- ###实际模型检测输出的类别为:"护栏","交通标志","非交通标志","锥桶","水马"
- if opt['business'] == 'cityRoad':
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
- 'max_workers':1, ###并行线程数
- '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':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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': '../AIlib2/weights/conf/%s/para.json'%(opt['business']),###后处理参数文件
- 'txtFontSize':40,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':3},###显示框、线设置
- 'testImgPath':'images/%s'%(opt['business']),###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
- if opt['business'] == 'illParking':
- from utilsK.illParkingUtils import illParking_postprocess_N
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
- 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
- 'postProcess':{'function':illParking_postprocess_N, 'pars':{ }},
- 'models':
- [
- {
- 'weight':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- #'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,5,6,7,8,9] ],###控制哪些检测类别显示、输出
- 'postFile': '../AIlib2/weights/conf/%s/para.json'%(opt['business'] ),###后处理参数文件
- 'txtFontSize':20,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':2},###显示框、线设置
- 'testImgPath':'images/cityMangement',###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
- }
-
- #第一步加载模型
- 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'])
-
- #第三步准备画图字体
- drawPar = get_drawPar(par)
-
- #第四步获取图像测试及视频
- imgpaths,videopaths = get_images_videos( par['testImgPath'])
-
- #第五步开始测试
- for i in range(len(imgpaths)):
- imgpath = imgpaths[i]
- bname = os.path.basename(imgpath )
- im0s=[cv2.imread(imgpath)]
- time00 = time.time()
-
- retResults,timeOut = AI_det_track_batch_N(im0s, [i] ,modelList,par['postProcess'],sort_tracker ,trackPar)
- '''
- 返回值retResults[2] --list,其中每一个元素为一个list,表示每一帧的检测结果,每一个结果是由多个list构成,每个list表示一个框,格式为[ x0 ,y0 ,x1 ,y1 ,conf,cls ,ifrmae,trackId ]
- --etc. retResults[2][j][k]表示第j帧的第k个框。
- '''
- time11 = time.time()
- if len(retResults[1])>0:
- retResults[0][0] = drawBoxTraceSimplied(retResults[1],i, retResults[0][0],rainbows=rainbows,boxFlag=True,traceFlag=False,names=drawPar['names'])
-
- image_array = retResults[0][0]
-
- cv2.imwrite( os.path.join( par['testOutPath'],bname ) ,image_array )
- print('----image:%s, Allprocess:%s %s ,save:%s , objcnt:%d'%(bname,(time11-time00) * 1000, timeOut,(time.time() - time11) * 1000 ,len(retResults[2])) )
- ##第五步开始测试视频
- print('##begin to process videos, total %d videos'%( len(videopaths)))
- for i,video in enumerate(videopaths):
- print('process video%d :%s '%(i,video))
-
- par0={'modelList':modelList,'postProcess':par['postProcess'],'drawPar':drawPar,'outpth':par['testOutPath'], 'sort_tracker':sort_tracker,'trackPar':trackPar}
-
- process_video(video,par0,mode='track')
- def OCR_demo2(opt):
- from ocrUtils2 import crnn_model
- from ocrUtils2.ocrUtils import get_cfg,recognition_ocr,strLabelConverter
-
- if opt['business'] == 'ocr2':
- par={
- 'image_dir':'images/ocr_en',
- 'outtxt':'images/results',
- 'weights':'../AIlib2/weights/conf/ocr2/crnn_448X32.pth',
-
- #'weights':'../weights/2080Ti/AIlib2/ocr2/crnn_2080Ti_fp16_448X32.engine',
- 'device':'cuda:0',
- 'cfg':'../AIlib2/weights/conf/ocr2/360CC_config.yaml',
-
- 'char_file':'../AIlib2/weights/conf/ocr2/chars.txt',
- 'imgH':32,
- 'imgW':448,
- 'workers':1
-
-
- }
- image_dir=par['image_dir']
- outtxt=par['outtxt']
- workers=par['workers']
- weights= par['weights']
- device=par['device']
-
- char_file=par['char_file']
- imgH=par['imgH']
- imgW=par['imgW']
- cfg = par['cfg']
-
-
-
- config = get_cfg(cfg, char_file)
-
-
- par['contextFlag']=False
- device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')
- if weights.endswith('.pth'):
- model = crnn_model.get_crnn(config,weights=weights).to(device)
- par['model_mode']='pth'
- else:
- logger = trt.Logger(trt.Logger.ERROR)
- with open(weights, "rb") as f, trt.Runtime(logger) as runtime:
- model = runtime.deserialize_cuda_engine(f.read())# 输入trt本地文件,返回ICudaEngine对象
- print('#####load TRT file:',weights,'success #####')
- context = model.create_execution_context()
- par['model_mode']='trt';par['contextFlag']=context
-
- converter = strLabelConverter(config.DATASET.ALPHABETS)
-
- img_urls=glob.glob('%s/*.jpg'%( image_dir ))
- img_urls.extend( glob.glob('%s/*.png'%( image_dir )) )
- cnt=len(img_urls)
- print('%s has %d images'%(image_dir ,len(img_urls) ) )
- # 准备数据
- parList=[]
- for i in range(cnt):
- img_patch=cv2.imread( img_urls[i] , cv2.IMREAD_GRAYSCALE)
- started = time.time()
- img = cv2.imread(img_urls[i])
- sim_pred = recognition_ocr(config, img, model, converter, device,par=par)
- finished = time.time()
- print('{0}: elapsed time: {1} prd:{2} '.format( os.path.basename( img_urls[i] ), finished - started, sim_pred ))
-
- def customization_demo(opt):
- from AI import AI_process_C
-
- if opt['business'] == 'channel2':
-
- from ocr import ocrModel
-
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
- 'max_workers':1, ###并行线程数
- 'postProcess':{'function':default_mix,'pars':{'objs':[2] },'name':'channel2',},
- 'models':[
- {
- #'weight':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- 'weight':'../AIlib2/weights/conf/%s/yolov5.pt'%(opt['business'] ),
- #'weight':'/mnt/thsw2/DSP2/weights/channel2/yolov5.pt',
- #'weight':'/mnt/thsw2/DSP2/weights/channel2/yolov5_2080Ti_fp16.engine',
- '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":{str(x):0.1 for x in range(20) } }
-
- },
-
- {
- 'weight' : '../weights/%s/AIlib2/ocr2/crnn_ch_%s_fp16_192X32.engine'%(opt['gpu'], opt['gpu']),
- 'name':'ocr',
- 'model':ocrModel,
- 'par':{
- 'char_file':'../AIlib2/weights/conf/ocr2/chars.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,5,6,7,8,9] ],###控制哪些检测类别显示、输出
- 'postFile': '../AIlib2/weights/conf/%s/para.json'%(opt['business'] ),###后处理参数文件
- 'txtFontSize':20,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'segLineShow':True,'waterLineWidth':2},###显示框、线设置
- 'testImgPath':'images/%s/'%(opt['business']),
- #'testImgPath':'/home/thsw2/WJ/src/OCR/shipNames',
- 'testOutPath':'images/results/',###输出测试图像位置
- }
-
- if opt['business'] == 'crackMeasurement':
- from utilsK.crackUtils import Crack_measure
- print( '%s 只能测试图像,不能测试视频%s'%('#'*20,'#'*20))
- par={
- 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
- 'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
- 'max_workers':1, ###并行线程数
- 'postProcess':{
- 'name':'crackMeasurement',
- 'function':Crack_measure,
- 'pars':{'dsx':(123-30)*1000/35*0.004387636 ,'objs':[0,1,2]}
- },
- 'models':[
- {
- #'weight':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- 'weight':'../AIlib2/weights/conf/%s/yolov5.pt'%(opt['business'] ),
- 'name':'yolov5',
- 'model':yolov5Model,
- 'par':{ 'half':True,'device':'cuda:0' ,'conf_thres':0.1,'iou_thres':0.45,'allowedList':[0,1,2,3],'segRegionCnt':1, 'trtFlag_det':False,'trtFlag_seg':False, "score_byClass":{"0":0.1,"1":0.1,"2":0.1 } }
-
- },
-
- {
- #'weight':"../weights/%s/AIlib2/%s/stdc_360X640_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- 'weight':'../AIlib2/weights/conf/%s/stdc_360X640.pth'%(opt['business'] ),
- 'par':{
- #'modelSize':(640,360),
- 'modelSize':(1920,1080),
- 'dynamic':True,
- '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': '../AIlib2/weights/conf/%s/para.json'%(opt['business'] ),###后处理参数文件
- 'txtFontSize':20,###文本字符的大小
- 'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'segLineShow':True,'waterLineWidth':2},###显示框、线设置
- 'testImgPath':'images/%s/'%(opt['business']),
- #'testImgPath':'/mnt/thsw2/DSP2/weights/cityMangement2_1102/images/debug',
- 'testOutPath':'images/results/',###输出测试图像位置
- }
-
- #第一步加载模型
- modelList=[ modelPar['model'](weights=modelPar['weight'],par=modelPar['par']) for modelPar in par['models'] ]
- print(' load moder over')
-
- #准备画图字体
- labelnames = par['labelnames'] ##对应类别表
- names=get_labelnames(labelnames)
- label_arraylist = get_label_arrays(names,rainbows,outfontsize=par['txtFontSize'],fontpath="../AIlib2/conf/platech.ttf")
-
- #图像测试
- imgpaths,videopaths = get_images_videos( par['testImgPath'])
-
-
- #开始测试
- for imgUrl in imgpaths[0:]:
- img = cv2.imread(imgUrl);bname = os.path.basename(imgUrl)
- if opt['business'] == 'crackMeasurement':
- ret,timeInfos = AI_process_C([img],modelList,par['postProcess'])
- #返回类型ret-list,[[ x0,y0,x1,y1,score,class,裂缝长度,平均宽度,最大宽度,最小宽度],[...],[...]]
- for re in ret:
- print('Summarized Cracklength = %.1f mm Mean crack width = %.1f mm Max crack width = %.1f mm Min crack width = %.1f mm '%( re[6], re[7],re[8],re[9] ) )
- elif opt['business'] == 'channel2':
- ret,timeInfos = AI_process_C([img],modelList,par['postProcess'])
-
- timeInfos=bname+':'+timeInfos
- print(timeInfos,ret )
- if len(ret)>0:
- img0 = drawAllBox(ret,img,label_arraylist,rainbows,par['digitFont'])
- else: img0= img
- cv2.imwrite(os.path.join('images/results/',bname ) ,img0)
-
-
-
-
-
-
- def OBB_track_demo(opt):
- ###倾斜框(OBB)的ship目标检测
- par={
-
- 'obbModelPar':{
- '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,'decoder':None,
- 'weights':'../weights/%s/AIlib2/%s/obb_608X608_%s_fp16.engine'%(opt['gpu'],opt['business'],opt['gpu']),
-
- },
- 'outpth': 'images/results',
- 'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
- 'device':"cuda:0",
-
- #'test_dir': '/mnt/thsw2/DSP2/videos/obbShips/DJI_20230208110806_0001_W_6M.MP4',
- 'test_dir':'/mnt/thsw2/DSP2/videos/obbShips/freighter2.mp4',
-
- 'test_flag':True,
- 'postFile': '../AIlib2/weights/conf/%s/para.json'%(opt['business'] ),###后处理参数文件
- 'drawBox':True,#####是否画框
- 'drawPar': { 'digitWordFont' :{'line_thickness':2,'boxLine_thickness':1,'wordSize':40, 'fontSize':1.0,'label_location':'leftTop'}} ,
- 'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business'] ), ###检测类别对照表
- }
- #par['model_size'],par['mean'],par['std'],par['half'],par['saveType'],par['heads'],par['labelnames'],par['decoder'],par['down_ratio'],par['drawBox']
- #par['rainbows'],par['label_array'],par['digitWordFont']
-
- obbModelPar = par['obbModelPar']
- ####加载模型
- model,decoder2=load_model_decoder_OBB(obbModelPar)
- obbModelPar['decoder']=decoder2
-
- names=get_labelnames(par['labelnames']);obbModelPar['labelnames']=names
-
- _,_,_,rainbows=get_postProcess_para(par['postFile']);par['drawPar']['rainbows']=rainbows
-
-
- label_arraylist = get_label_arrays(names,rainbows,outfontsize=par['drawPar']['digitWordFont']['wordSize'],fontpath="../AIlib2/conf/platech.ttf")
- #par['label_array']=label_arraylist
-
- 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'])
-
-
- ##图像测试和视频
- impth = par['test_dir']
- img_urls=[]###获取文件里所有的图像
- video_urls=[]###获取文件里所有的视频
- img_postfixs = ['.jpg','.JPG','.PNG','.png'];
- vides_postfixs= ['.MP4','.mp4','.avi']
- if os.path.isdir(impth):
- for postfix in img_postfixs:
- img_urls.extend(glob.glob('%s/*%s'%(impth,postfix )) )
- for postfix in ['.MP4','.mp4','.avi']:
- video_urls.extend(glob.glob('%s/*%s'%(impth,postfix )) )
- else:
- postfix = os.path.splitext(impth)[-1]
- if postfix in img_postfixs: img_urls=[ impth ]
- if postfix in vides_postfixs: video_urls = [impth ]
-
- parIn = {'obbModelPar':obbModelPar,'modelPar':{'obbmodel': model},'sort_tracker':sort_tracker,'outpth':par['outpth'],'trackPar':trackPar,'drawPar':par['drawPar']}
- par['drawPar']['label_array']=label_arraylist
- for img_url in img_urls:
- #print(img_url)
- ori_image=cv2.imread(img_url)
-
- #ori_image_list,infos = OBB_infer(model,ori_image,obbModelPar)
-
- ori_image_list,infos = OBB_tracker_batch([ori_image],[0],parIn['modelPar'],parIn['obbModelPar'],None,parIn['trackPar'],None)
-
- ori_image_list[1] = draw_obb(ori_image_list[2] ,ori_image_list[1],par['drawPar'])
-
- imgName = os.path.basename(img_url)
- saveFile = os.path.join(par['outpth'], imgName)
- ret=cv2.imwrite(saveFile, ori_image_list[1])
- if not ret:
- print(saveFile, ' not created ')
- print( os.path.basename(img_url),':',infos,ori_image_list[2])
-
- ###处理视频
-
- for video_url in video_urls:
- process_video(video_url, parIn ,mode='obbTrack')
-
- def crowd_demo(opt):
- if opt['business']=='crowdCounting':
-
- from crowd import crowdModel as Model
- par={
- 'mean':[0.485, 0.456, 0.406], 'std':[0.229, 0.224, 0.225],'threshold':0.5,
- 'input_profile_shapes':[(1,3,256,256),(1,3,1024,1024),(1,3,2048,2048)],
- 'modelPar':{'backbone':'vgg16_bn', 'gpu_id':0,'anchorFlag':False, 'width':None,'height':None ,'line':2, 'row':2},
-
- 'weights':"../weights/%s/AIlib2/%s/crowdCounting_%s_dynamic.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
- 'testImgPath':'images/%s'%(opt['business'] ),###测试图像的位置
- 'testOutPath':'images/results/',###输出测试图像位置
-
- }
-
-
- #weights='weights/best_mae.pth'
- cmodel = Model(par['weights'],par)
-
- img_path = par['testImgPath']
- File = os.listdir(img_path)
- targetList = []
- for file in File[0:]:
- COORlist = []
- imgPath = img_path + os.sep + file
-
-
- img_raw = cv2.cvtColor(cv2.imread(imgPath),cv2.COLOR_BGR2RGB)
- # cmodel.eval---
- # 输入读取的RGB数组
- # 输出:list,0--原图,1-人头坐标list,2-对接OBB的格式数据,其中4个坐标均相同,2-格式如下:
- # [ [ [ (x0,y0),(x1,y1),(x2,y2),(x3,y3) ],score, cls ], [ [ (x0,y0),(x1,y1),(x2,y2),(x3,y3) ],score ,cls ],........ ]
-
- prets, infos = cmodel.eval(img_raw)
-
-
- print(file,infos,' 人数:',len(prets[1]))
-
-
- img_to_draw = cv2.cvtColor(np.array(img_raw), cv2.COLOR_RGB2BGR)
- # 打印预测图像中人头的个数
- for p in prets[1]:
- img_to_draw = cv2.circle(img_to_draw, (int(p[0]), int(p[1])), 2, (0, 255, 0), -1)
- COORlist.append((int(p[0]), int(p[1])))
- # 将各测试图像中的人头坐标存储在targetList中, 格式:[[(x1, y1),(x2, y2),...], [(X1, Y1),(X2, Y2),..], ...]
- targetList.append(COORlist)
- #time.sleep(2)
- # 保存预测图片
- cv2.imwrite(os.path.join(par['testOutPath'], file), img_to_draw)
-
- if __name__=="__main__":
-
- #jkm_demo()
- businessAll=['river', 'river2','highWay2','noParking','drowning','forest2','vehicle','pedestrian','smogfire' , 'AnglerSwimmer','channelEmergency', 'countryRoad','cityMangement','ship2','cityMangement2','cityRoad','illParking',"crowdCounting",'cityMangement3','crackMeasurement','pothole','channel2','riverT']
- businessAll = [ 'forest2' ]
-
- for busi in businessAll:
- print('-'*40,'beg to test:',busi,'-'*40)
- opt={'gpu':'2080Ti','business':busi}
- if busi in ['ship2']:
- OBB_track_demo(opt)
- elif opt['business'] in ['crowdCounting'] :
- crowd_demo(opt)
- elif opt['business'] in ['crackMeasurement','channel2'] :
- customization_demo(opt)
- else:
- #if opt['business'] in ['river','highWay2','noParking','drowning','']:
- det_track_demo_N(opt )
-
-
-
|