|
|
@@ -4,10 +4,10 @@ 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
|
|
|
|
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
|
|
|
@@ -28,7 +28,16 @@ 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 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()
|
|
|
@@ -108,7 +117,8 @@ def process_video(video,par0,mode='detSeg'): |
|
|
|
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(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
|
|
|
@@ -177,71 +187,78 @@ def process_video(video,par0,mode='detSeg'): |
|
|
|
post_results.append(p_result)
|
|
|
|
|
|
|
|
vid_writer_AI.release();
|
|
|
|
|
|
|
|
def det_track_demo(business ):
|
|
|
|
'''
|
|
|
|
跟踪参数说明:
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100}
|
|
|
|
sort_max_age--跟踪链断裂时允许目标消失最大的次数。超过之后,会认为是新的目标。
|
|
|
|
sort_min_hits--每隔目标连续出现的次数,超过这个次数才认为是一个目标。
|
|
|
|
sort_iou_thresh--检测最小的置信度。
|
|
|
|
det_cnt--每隔几次做一个跟踪和检测,默认10。
|
|
|
|
windowsize--轨迹平滑长度,一定是奇数,表示每隔几帧做一平滑,默认29。
|
|
|
|
patchCnt--每次送入图像的数量,不宜少于100帧。
|
|
|
|
'''
|
|
|
|
|
|
|
|
''' 以下是基于检测和分割的跟踪模型,分割用来修正检测的结果'''
|
|
|
|
|
|
|
|
def det_track_demo_N(business ):
|
|
|
|
####河道巡检的跟踪模型参数
|
|
|
|
if opt['business'] == 'river' or opt['business'] == 'river2' :
|
|
|
|
from utilsK.queRiver import riverDetSegMixProcess_N
|
|
|
|
par={
|
|
|
|
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
|
|
|
|
'gpuname':'2080Ti',###显卡名称
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'half':True,
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出
|
|
|
|
|
|
|
|
'seg_nclass':2,###分割模型类别数目,默认2类
|
|
|
|
'segRegionCnt':0,###分割模型结果需要保留的等值线数目
|
|
|
|
|
|
|
|
'segPar':{'modelSize':(640,360),'mean':(0.485, 0.456, 0.406),'std' :(0.229, 0.224, 0.225),'numpy':False, 'RGB_convert_first':True,#分割模型预处理参数
|
|
|
|
'mixFunction':{'function':riverDetSegMixProcess,'pars':{'slopeIndex':[1,3,4,7], 'riverIou':0.1}} #分割和检测混合处理的函数
|
|
|
|
},
|
|
|
|
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
|
|
|
|
'Segweights' : "../weights/%s/AIlib2/%s/stdc_360X640_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###分割模型权重位置
|
|
|
|
'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/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),'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/tt',###测试图像的位置
|
|
|
|
'testImgPath':'images/river2',###测试图像的位置
|
|
|
|
'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'] ), ###检测类别对照表
|
|
|
|
'half':True,
|
|
|
|
'gpuname':'3090',###显卡名称
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
#'Detweights':"../AIlib2/weights/conf/highWay2/yolov5.pt",
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出
|
|
|
|
'seg_nclass':3,###分割模型类别数目,默认2类
|
|
|
|
'segRegionCnt':2,###分割模型结果需要保留的等值线数目
|
|
|
|
'segPar':{'modelSize':(640,360),'mean':(0.485, 0.456, 0.406),'std' :(0.229, 0.224, 0.225),'predResize':True,'numpy':False, 'RGB_convert_first':True,###分割模型预处理参数
|
|
|
|
'mixFunction':{'function':tracfficAccidentMixFunction,
|
|
|
|
'pars':{ 'RoadArea': 16000, 'vehicleArea': 10, 'roadVehicleAngle': 15, 'speedRoadVehicleAngleMax': 75,'radius': 50 , 'roundness': 1.0, 'cls': 9, 'vehicleFactor': 0.1,'cls':9, 'confThres':0.25,'roadIou':0.6,'vehicleFlag':False,'distanceFlag': False }
|
|
|
|
}
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':5,'windowsize':29,'patchCnt':100},
|
|
|
|
'postProcess':{'function':tracfficAccidentMixFunction_N,
|
|
|
|
'pars':{ 'RoadArea': 16000, 'vehicleArea': 10, 'roadVehicleAngle': 15, 'speedRoadVehicleAngleMax': 75,'radius': 50 , 'roundness': 1.0, 'cls': 9, 'vehicleFactor': 0.1,'cls':9, 'confThres':0.25,'roadIou':0.6,'vehicleFlag':False,'distanceFlag': False }
|
|
|
|
},
|
|
|
|
'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'
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':5,'windowsize':29,'patchCnt':100},
|
|
|
|
'mode':'highWay3.0',
|
|
|
|
'Segweights' : "../weights/%s/AIlib2/%s/stdc_360X640_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###分割模型权重位置
|
|
|
|
'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},###显示框、线设置
|
|
|
@@ -249,61 +266,118 @@ def det_track_demo(business ): |
|
|
|
'testImgPath':'/home/chenyukun/777-7-42.mp4',###测试图像的位置
|
|
|
|
'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
}
|
|
|
|
par['segPar']['mixFunction']['pars']['modelSize'] = par['segPar']['modelSize']
|
|
|
|
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'] ), ###检测类别对照表
|
|
|
|
'half':True,
|
|
|
|
'gpuname':'3090',###显卡名称
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
#'Detweights':"../AIlib2/weights/conf/highWay2/yolov5.pt",
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出
|
|
|
|
'seg_nclass':4,###分割模型类别数目,默认2类
|
|
|
|
'segRegionCnt':2,###分割模型结果需要保留的等值线数目
|
|
|
|
'segPar':{'modelSize':(640,360),'mean':(0.485, 0.456, 0.406),'std' :(0.229, 0.224, 0.225),'predResize':True,'numpy':False, 'RGB_convert_first':True,###分割模型预处理参数
|
|
|
|
'mixFunction':{'function':mixNoParking_road_postprocess,
|
|
|
|
'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 } },
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'mode':'highWay3.0',
|
|
|
|
'Segweights' : "../weights/%s/AIlib2/%s/stdc_360X640_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###分割模型权重位置
|
|
|
|
{
|
|
|
|
#'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['segPar']['mixFunction']['pars']['modelSize'] = par['segPar']['modelSize']
|
|
|
|
|
|
|
|
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
|
|
|
|
from DMPRUtils.jointUtil import dmpr_yolo_stdc
|
|
|
|
|
|
|
|
par={
|
|
|
|
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'half':True,
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
#'Detweights':"/mnt/thsw2/DSP2/weights/cityMangement2/weights/urbanManagement/yolo/best.pt",
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出
|
|
|
|
'seg_nclass':4,###分割模型类别数目,默认2类
|
|
|
|
'segRegionCnt':2,###分割模型结果需要保留的等值线数目
|
|
|
|
|
|
|
|
'segPar':{ 'depth_factor':32,'NUM_FEATURE_MAP_CHANNEL':6,'dmpr_thresh':0.3, 'dmprimg_size':640,
|
|
|
|
'mixFunction':{'function':dmpr_yolo,
|
|
|
|
'pars':{'carCls':0 ,'illCls':3,'scaleRatio':0.5,'border':80}
|
|
|
|
}
|
|
|
|
'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 } }
|
|
|
|
|
|
|
|
},
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
#'Segweights' : '/mnt/thsw2/DSP2/weights/cityMangement2/weights/urbanManagement/DMPR/dp_detector_499.engine',###分割模型权重位置
|
|
|
|
'Segweights':"../weights/%s/AIlib2/%s/dmpr_%s.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
{
|
|
|
|
#'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},###显示框、线设置
|
|
|
@@ -312,100 +386,135 @@ def det_track_demo(business ): |
|
|
|
#'testImgPath':'images/cityMangement/',
|
|
|
|
'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
}
|
|
|
|
if opt['business'] == 'drowning':
|
|
|
|
|
|
|
|
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'] ), ###检测类别对照表
|
|
|
|
'half':True,
|
|
|
|
'gpuname':'3090',###显卡名称
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
#'Detweights':"../AIlib2/weights/conf/highWay2/yolov5.pt",
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出
|
|
|
|
'seg_nclass':2,###分割模型类别数目,默认2类
|
|
|
|
'segRegionCnt':2,###分割模型结果需要保留的等值线数目
|
|
|
|
'segPar':{'modelSize':(640,360),'mean':(0.485, 0.456, 0.406),'std' :(0.229, 0.224, 0.225),'predResize':True,'numpy':False, 'RGB_convert_first':True,###分割模型预处理参数
|
|
|
|
'mixFunction':{'function':mixDrowing_water_postprocess,
|
|
|
|
'pars':{ }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'Segweights' : "../weights/%s/AIlib2/%s/stdc_360X640_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###分割模型权重位置
|
|
|
|
'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['segPar']['mixFunction']['pars']['modelSize'] = par['segPar']['modelSize']
|
|
|
|
'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.3, '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/debug',
|
|
|
|
'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
''' 以下是基于检测的跟踪模型,只有检测没有分割 '''
|
|
|
|
if opt['business'] == 'forest2':
|
|
|
|
|
|
|
|
par={
|
|
|
|
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
'labelnames':"../AIlib2/weights/conf/forest2/labelnames.json", ###检测类别对照表
|
|
|
|
'gpuname':opt['gpu'],###显卡名称
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'half':True,
|
|
|
|
'trtFlag_det':True,###检测模型是否采用TRT
|
|
|
|
'trtFlag_seg':False,###分割模型是否采用TRT
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
#'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [] ],
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'seg_nclass':2,###分割模型类别数目,默认2类
|
|
|
|
'segRegionCnt':0,###分割模型结果需要保留的等值线数目
|
|
|
|
'segPar':None,###分割模型预处理参数
|
|
|
|
'Segweights' : None,###分割模型权重位置
|
|
|
|
'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", ###检测类别对照表
|
|
|
|
'gpuname':'2080T',###显卡名称
|
|
|
|
'half':True,
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'trtFlag_det':True,###检测模型是否采用TRT
|
|
|
|
'trtFlag_seg':False,###分割模型是否采用TRT
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'seg_nclass':2,###分割模型类别数目,默认2类
|
|
|
|
'segRegionCnt':0,###分割模型结果需要保留的等值线数目
|
|
|
|
'segPar':None,###分割模型预处理参数
|
|
|
|
'Segweights' : None,###分割模型权重位置
|
|
|
|
'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/videos/vehicle/',###测试图像的位置
|
|
|
|
'testImgPath':'images/vehicle/',###测试图像的位置
|
|
|
|
'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
}
|
|
|
|
###行人检测模型
|
|
|
|
}
|
|
|
|
###行人检测模型
|
|
|
|
if opt['business'] == 'pedestrian':
|
|
|
|
par={
|
|
|
|
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
'labelnames':"../AIlib2/weights/conf/pedestrian/labelnames.json", ###检测类别对照表
|
|
|
|
'gpuname':'2080T',###显卡名称
|
|
|
|
'half':True,
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'trtFlag_det':True,###检测模型是否采用TRT
|
|
|
|
'trtFlag_seg':False,###分割模型是否采用TRT
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'seg_nclass':2,###分割模型类别数目,默认2类
|
|
|
|
'segRegionCnt':0,###分割模型结果需要保留的等值线数目
|
|
|
|
'segPar':None,###分割模型预处理参数
|
|
|
|
'Segweights' : None,###分割模型权重位置
|
|
|
|
'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},###显示框、线设置
|
|
|
@@ -416,41 +525,45 @@ def det_track_demo(business ): |
|
|
|
par={
|
|
|
|
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
'labelnames':"../AIlib2/weights/conf/smogfire/labelnames.json", ###检测类别对照表
|
|
|
|
'gpuname':'2080T',###显卡名称
|
|
|
|
'half':True,
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'trtFlag_det':True,###检测模型是否采用TRT
|
|
|
|
'trtFlag_seg':False,###分割模型是否采用TRT
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'seg_nclass':2,###没有分割模型,此处不用
|
|
|
|
'segRegionCnt':0,###没有分割模型,此处不用
|
|
|
|
'segPar':None,###分割模型预处理参数
|
|
|
|
'Segweights' : None,###分割模型权重位置
|
|
|
|
'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", ###检测类别对照表
|
|
|
|
'gpuname':'2080T',###显卡名称
|
|
|
|
'half':True,
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'trtFlag_det':True,###检测模型是否采用TRT
|
|
|
|
'trtFlag_seg':False,###分割模型是否采用TRT
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'seg_nclass':2,###没有分割模型,此处不用
|
|
|
|
'segRegionCnt':0,###没有分割模型,此处不用
|
|
|
|
'segPar':None,###分割模型预处理参数
|
|
|
|
'Segweights' : None,###分割模型权重位置
|
|
|
|
'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},###显示框、线设置
|
|
|
@@ -462,19 +575,22 @@ def det_track_demo(business ): |
|
|
|
par={
|
|
|
|
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
'labelnames':"../AIlib2/weights/conf/channelEmergency/labelnames.json", ###检测类别对照表
|
|
|
|
'gpuname':'2080T',###显卡名称
|
|
|
|
'half':True,
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'trtFlag_det':True,###检测模型是否采用TRT
|
|
|
|
'trtFlag_seg':False,###分割模型是否采用TRT
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
#'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [] ],###控制哪些检测类别显示、输出
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'seg_nclass':2,###没有分割模型,此处不用
|
|
|
|
'segRegionCnt':0,###没有分割模型,此处不用
|
|
|
|
'segPar':None,###分割模型预处理参数
|
|
|
|
'Segweights' : None,###分割模型权重位置
|
|
|
|
'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},###显示框、线设置
|
|
|
@@ -482,23 +598,25 @@ def det_track_demo(business ): |
|
|
|
'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
}
|
|
|
|
|
|
|
|
###乡村路违法种植
|
|
|
|
###乡村路违法种植
|
|
|
|
if opt['business'] == 'countryRoad':
|
|
|
|
par={
|
|
|
|
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
'labelnames':"../AIlib2/weights/conf/countryRoad/labelnames.json", ###检测类别对照表
|
|
|
|
'gpuname':'2080T',###显卡名称
|
|
|
|
'half':True,
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'trtFlag_det':True,###检测模型是否采用TRT
|
|
|
|
'trtFlag_seg':False,###分割模型是否采用TRT
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'seg_nclass':2,###没有分割模型,此处不用
|
|
|
|
'segRegionCnt':0,###没有分割模型,此处不用
|
|
|
|
'segPar':None,###分割模型预处理参数
|
|
|
|
'Segweights' : None,###分割模型权重位置
|
|
|
|
'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},###显示框、线设置
|
|
|
@@ -511,18 +629,20 @@ def det_track_demo(business ): |
|
|
|
par={
|
|
|
|
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
|
|
|
|
'gpuname':'2080Ti',###显卡名称
|
|
|
|
'half':True,
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'trtFlag_det':True,###检测模型是否采用TRT
|
|
|
|
'trtFlag_seg':False,###分割模型是否采用TRT
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'seg_nclass':2,###没有分割模型,此处不用
|
|
|
|
'segRegionCnt':0,###没有分割模型,此处不用
|
|
|
|
'segPar':None,###分割模型预处理参数
|
|
|
|
'Segweights' : None,###分割模型权重位置
|
|
|
|
'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},###显示框、线设置
|
|
|
@@ -535,45 +655,44 @@ def det_track_demo(business ): |
|
|
|
par={
|
|
|
|
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
|
|
|
|
'gpuname':'2080Ti',###显卡名称
|
|
|
|
'half':True,
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'trtFlag_det':True,###检测模型是否采用TRT
|
|
|
|
'trtFlag_seg':False,###分割模型是否采用TRT
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,4,5,6] ],###控制哪些检测类别显示、输出
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'seg_nclass':2,###没有分割模型,此处不用
|
|
|
|
'segRegionCnt':0,###没有分割模型,此处不用
|
|
|
|
'segPar':None,###分割模型预处理参数
|
|
|
|
'Segweights' : None,###分割模型权重位置
|
|
|
|
'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
|
|
|
|
from utilsK.illParkingUtils import illParking_postprocess_N
|
|
|
|
par={
|
|
|
|
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
'half':True,
|
|
|
|
'labelnames':"../AIlib2/weights/conf/%s/labelnames.json"%(opt['business']), ###检测类别对照表
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'Detweights':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
'detModelpara':[{"id":str(x),"config":{"k1":"v1","k2":"v2"}} for x in [0,1,2,3,5,6,7,8,9] ],###控制哪些检测类别显示、输出
|
|
|
|
'trackPar':{'sort_max_age':2,'sort_min_hits':3,'sort_iou_thresh':0.2,'det_cnt':10,'windowsize':29,'patchCnt':100},
|
|
|
|
'seg_nclass':4,###没有分割模型,此处不用
|
|
|
|
'segRegionCnt':2,###没有分割模型,此处不用
|
|
|
|
|
|
|
|
'segPar':{
|
|
|
|
'mixFunction':{'function':illParking_postprocess,
|
|
|
|
'pars':{ }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'Segweights' : None,###分割模型权重位置
|
|
|
|
'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},###显示框、线设置
|
|
|
@@ -581,159 +700,47 @@ def det_track_demo(business ): |
|
|
|
'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
par['trtFlag_det']=True if par['Detweights'].endswith('.engine') else False
|
|
|
|
if par['Segweights']:
|
|
|
|
par['segPar']['trtFlag_seg']=True if par['Segweights'].endswith('.engine') else False
|
|
|
|
|
|
|
|
##使用森林,道路模型,business 控制['forest','road']
|
|
|
|
##预先设置的参数
|
|
|
|
#gpuname=par['gpuname']#如果用trt就需要此参数,只能是"3090" "2080Ti"
|
|
|
|
device_=par['device'] ##选定模型,可选 cpu,'0','1'
|
|
|
|
|
|
|
|
|
|
|
|
device = select_device(device_)
|
|
|
|
half = device.type != 'cpu' # half precision only supported on CUDA
|
|
|
|
trtFlag_det=par['trtFlag_det'] ###是否采用TRT模型加速
|
|
|
|
|
|
|
|
##以下参数目前不可改
|
|
|
|
imageW=1080 ####道路模型
|
|
|
|
digitFont= par['digitFont']
|
|
|
|
|
|
|
|
|
|
|
|
####加载检测模型
|
|
|
|
if trtFlag_det:
|
|
|
|
Detweights=par['Detweights']
|
|
|
|
logger = trt.Logger(trt.Logger.ERROR)
|
|
|
|
with open(Detweights, "rb") as f, trt.Runtime(logger) as runtime:
|
|
|
|
model=runtime.deserialize_cuda_engine(f.read())# 输入trt本地文件,返回ICudaEngine对象
|
|
|
|
print('####load TRT model :%s'%(Detweights))
|
|
|
|
else:
|
|
|
|
Detweights=par['Detweights']
|
|
|
|
model = attempt_load(Detweights, map_location=device) # load FP32 model
|
|
|
|
if half: model.half()
|
|
|
|
|
|
|
|
####加载分割模型
|
|
|
|
seg_nclass = par['seg_nclass']
|
|
|
|
segPar=par['segPar']
|
|
|
|
if par['Segweights']:
|
|
|
|
if opt['business'] == 'cityMangement2':
|
|
|
|
segmodel = DMPRModel(weights=par['Segweights'], par = par['segPar'])
|
|
|
|
else:
|
|
|
|
segmodel = stdcModel(weights=par['Segweights'], par = par['segPar'])
|
|
|
|
'''
|
|
|
|
if par['segPar']['trtFlag_seg']:
|
|
|
|
Segweights = par['Segweights']
|
|
|
|
logger = trt.Logger(trt.Logger.ERROR)
|
|
|
|
with open(Segweights, "rb") as f, trt.Runtime(logger) as runtime:
|
|
|
|
segmodel=runtime.deserialize_cuda_engine(f.read())# 输入trt本地文件,返回ICudaEngine对象
|
|
|
|
print('############locad seg model trt success: ',Segweights)
|
|
|
|
else:
|
|
|
|
Segweights = par['Segweights']
|
|
|
|
segmodel = SegModel(nclass=seg_nclass,weights=Segweights,device=device)
|
|
|
|
print('############locad seg model pth success:',Segweights)
|
|
|
|
'''
|
|
|
|
else:
|
|
|
|
segmodel=None
|
|
|
|
|
|
|
|
|
|
|
|
#第一步加载模型
|
|
|
|
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'])
|
|
|
|
|
|
|
|
|
|
|
|
labelnames = par['labelnames']
|
|
|
|
postFile= par['postFile']
|
|
|
|
print( Detweights,labelnames )
|
|
|
|
conf_thres,iou_thres,classes,rainbows=get_postProcess_para(postFile)
|
|
|
|
|
|
|
|
detPostPar = get_postProcess_para_dic(postFile)
|
|
|
|
conf_thres,iou_thres,classes,rainbows = detPostPar["conf_thres"],detPostPar["iou_thres"],detPostPar["classes"],detPostPar["rainbows"]
|
|
|
|
if 'ovlap_thres_crossCategory' in detPostPar.keys(): iou2nd=detPostPar['ovlap_thres_crossCategory']
|
|
|
|
else:iou2nd = None
|
|
|
|
if 'score_byClass' in detPostPar.keys(): score_byClass=detPostPar['score_byClass']
|
|
|
|
else: score_byClass = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
####模型选择参数用如下:
|
|
|
|
mode_paras=par['detModelpara']
|
|
|
|
|
|
|
|
allowedList,allowedList_string=get_needed_objectsIndex(mode_paras)
|
|
|
|
#slopeIndex = par['slopeIndex']
|
|
|
|
##只加载检测模型,准备好显示字符
|
|
|
|
|
|
|
|
names=get_labelnames(labelnames)
|
|
|
|
#imageW=4915;###默认是1920,在森林巡检的高清图像中是4920
|
|
|
|
outfontsize=int(imageW/1920*40);###
|
|
|
|
label_arraylist = get_label_arrays(names,rainbows,outfontsize=par['txtFontSize'],fontpath="../AIlib2/conf/platech.ttf")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##图像测试和视频
|
|
|
|
outpth = par['testOutPath']
|
|
|
|
impth = par['testImgPath']
|
|
|
|
imgpaths=[]###获取文件里所有的图像
|
|
|
|
videopaths=[]###获取文件里所有的视频
|
|
|
|
img_postfixs = ['.jpg','.JPG','.PNG','.png'];
|
|
|
|
vides_postfixs= ['.MP4','.mp4','.avi']
|
|
|
|
if os.path.isdir(impth):
|
|
|
|
for postfix in img_postfixs:
|
|
|
|
imgpaths.extend(glob.glob('%s/*%s'%(impth,postfix )) )
|
|
|
|
for postfix in ['.MP4','.mp4','.avi']:
|
|
|
|
videopaths.extend(glob.glob('%s/*%s'%(impth,postfix )) )
|
|
|
|
else:
|
|
|
|
postfix = os.path.splitext(impth)[-1]
|
|
|
|
if postfix in img_postfixs: imgpaths=[ impth ]
|
|
|
|
if postfix in vides_postfixs: videopaths = [impth ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imgpaths.sort()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modelPar={ 'det_Model': model,'seg_Model':segmodel }
|
|
|
|
|
|
|
|
processPar={'half':par['half'],'device':device,'conf_thres':conf_thres,'iou_thres':iou_thres,'trtFlag_det':trtFlag_det,'iou2nd':iou2nd,'score_byClass':score_byClass}
|
|
|
|
drawPar={'names':names,'label_arraylist':label_arraylist,'rainbows':rainbows,'font': par['digitFont'],'allowedList':allowedList}
|
|
|
|
|
|
|
|
#第三步准备画图字体
|
|
|
|
drawPar = get_drawPar(par)
|
|
|
|
|
|
|
|
#第四步获取图像测试及视频
|
|
|
|
imgpaths,videopaths = get_images_videos( par['testImgPath'])
|
|
|
|
|
|
|
|
#第五步开始测试
|
|
|
|
for i in range(len(imgpaths)):
|
|
|
|
#for i in range(2):
|
|
|
|
#imgpath = os.path.join(impth, folders[i])
|
|
|
|
imgpath = imgpaths[i]
|
|
|
|
bname = os.path.basename(imgpath )
|
|
|
|
im0s=[cv2.imread(imgpath)]
|
|
|
|
time00 = time.time()
|
|
|
|
retResults,timeOut = AI_det_track_batch(im0s, [i] ,modelPar,processPar,sort_tracker ,trackPar,segPar)
|
|
|
|
#print('###line627:',retResults[2])
|
|
|
|
#retResults,timeInfos = AI_det_track_batch(imgarray_list, iframe_list ,par0['modelPar'],par0['processPar'],par0['sort_tracker'] ,par0['trackPar'],segPar=par0['segPar'])
|
|
|
|
|
|
|
|
retResults,timeOut = AI_det_track_batch_N(im0s, [i] ,modelList,par['postProcess'],sort_tracker ,trackPar)
|
|
|
|
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'])
|
|
|
|
time11 = time.time()
|
|
|
|
|
|
|
|
image_array = retResults[0][0]
|
|
|
|
'''
|
|
|
|
|
|
|
|
返回值retResults[2] --list,其中每一个元素为一个list,表示每一帧的检测结果,每一个结果是由多个list构成,每个list表示一个框,格式为[ cls , x0 ,y0 ,x1 ,y1 ,conf,ifrmae,trackId ]
|
|
|
|
返回值retResults[2] --list,其中每一个元素为一个list,表示每一帧的检测结果,每一个结果是由多个list构成,每个list表示一个框,格式为[ x0 ,y0 ,x1 ,y1 ,conf,cls ,ifrmae,trackId ]
|
|
|
|
--etc. retResults[2][j][k]表示第j帧的第k个框。
|
|
|
|
'''
|
|
|
|
cv2.imwrite( os.path.join( outpth,bname ) ,image_array )
|
|
|
|
|
|
|
|
print('----image:%s, process:%s ( %s ),save:%s'%(bname,(time11-time00) * 1000, timeOut,(time.time() - time11) * 1000) )
|
|
|
|
|
|
|
|
##process video
|
|
|
|
|
|
|
|
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={'modelPar':modelPar,'processPar':processPar,'drawPar':drawPar,'outpth':par['testOutPath'], 'sort_tracker':sort_tracker,'trackPar':trackPar,'segPar':segPar}
|
|
|
|
process_video(video,par0,mode='track')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
@@ -943,8 +950,8 @@ def crowd_demo(opt): |
|
|
|
if __name__=="__main__":
|
|
|
|
|
|
|
|
#jkm_demo()
|
|
|
|
businessAll=['river', 'river2','highWay2','noParking','drowning','forest2','vehicle','pedestrian','smogfire' , 'AnglerSwimmer','channelEmergency', 'countryRoad','cityMangement','ship2','cityMangement2','cityRoad','illParking',"crowdCounting"]
|
|
|
|
businessAll = ['crowdCounting']
|
|
|
|
businessAll=['river', 'river2','highWay2','noParking','drowning','forest2','vehicle','pedestrian','smogfire' , 'AnglerSwimmer','channelEmergency', 'countryRoad','cityMangement','ship2','cityMangement2','cityRoad','illParking',"crowdCounting",'cityMangement3']
|
|
|
|
businessAll = [ 'cityMangement3' ]
|
|
|
|
|
|
|
|
for busi in businessAll:
|
|
|
|
print('-'*40,'beg to test:',busi,'-'*40)
|
|
|
@@ -955,7 +962,7 @@ if __name__=="__main__": |
|
|
|
crowd_demo(opt)
|
|
|
|
else:
|
|
|
|
#if opt['business'] in ['river','highWay2','noParking','drowning','']:
|
|
|
|
det_track_demo(opt )
|
|
|
|
det_track_demo_N(opt )
|
|
|
|
|
|
|
|
|
|
|
|
|