|
|
@@ -485,8 +485,8 @@ def detSeg_demo2(opt): |
|
|
|
},
|
|
|
|
'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':"../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 } }
|
|
|
@@ -521,11 +521,38 @@ def detSeg_demo2(opt): |
|
|
|
'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',
|
|
|
|
'testImgPath':'images/%s/'%(opt['business']),
|
|
|
|
#'testImgPath':'/mnt/thsw2/DSP2/weights/cityMangement2_1102/images/debug',
|
|
|
|
'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
}
|
|
|
|
|
|
|
|
if opt['business'] == 'forest2':
|
|
|
|
from utilsK.crowdGather import gather_post_process
|
|
|
|
par={
|
|
|
|
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
'labelnames':"../AIlib2/weights/conf/forest2/labelnames.json", ###检测类别对照表
|
|
|
|
'max_workers':1, ###并行线程数
|
|
|
|
'postProcess':{'function':gather_post_process,'pars':{'pedestrianId':2,'crowdThreshold':4,'gatherId':6,'distancePersonScale':2.0}},
|
|
|
|
'models':
|
|
|
|
[
|
|
|
|
{
|
|
|
|
#'weight':"../weights/%s/AIlib2/forest2/yolov5_%s_fp16.engine"%(opt['gpu'], opt['gpu'] ),###检测模型路径
|
|
|
|
'weight':'/mnt/thsw2/DSP2/weights/forest2/yolov5.pt',###检测模型路径
|
|
|
|
#'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':5,###文本字符的大小
|
|
|
|
'digitFont': { 'line_thickness':1,'boxLine_thickness':1, 'fontSize':0.5,'waterLineColor':(0,255,255),'waterLineWidth':1},###显示框、线设置
|
|
|
|
#'testImgPath':'../AIdemo2/images/forest2/',###测试图像的位置
|
|
|
|
'testImgPath':'/mnt/thsw2/DSP2/weights/forest2/images_visdrone',
|
|
|
|
'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
}
|
|
|
|
#第一步加载模型
|
|
|
|
modelList=[ modelPar['model'](weights=modelPar['weight'],par=modelPar['par']) for modelPar in par['models'] ]
|
|
|
|
print(' load moder over')
|
|
|
@@ -573,32 +600,34 @@ def det_demo(business ): |
|
|
|
'txtFontSize':80,###文本字符的大小
|
|
|
|
'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'waterLineWidth':3},###显示框、线设置
|
|
|
|
'testImgPath':'../AIdemo2/images/forest/',###测试图像的位置
|
|
|
|
#'testImgPath':'/mnt/thsw2/DSP2/weights/forest2/',
|
|
|
|
'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, ###并行线程数
|
|
|
|
'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 [] ],
|
|
|
|
# if opt['business'] == 'forest2':
|
|
|
|
# par={
|
|
|
|
# 'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
# 'labelnames':"../AIlib2/weights/conf/forest2/labelnames.json", ###检测类别对照表
|
|
|
|
# 'gpuname':opt['gpu'],###显卡名称
|
|
|
|
# '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 [] ],
|
|
|
|
|
|
|
|
'slopeIndex':[],###岸坡类别(或者其它业务里的类别),不与河道(分割的前景区域)计算交并比,即不论是否在河道内都显示。
|
|
|
|
'seg_nclass':2,###分割模型类别数目,默认2类
|
|
|
|
'segRegionCnt':0,###分割模型结果需要保留的等值线数目
|
|
|
|
'segPar':None,###分割模型预处理参数
|
|
|
|
'Segweights' : None,###分割模型权重位置
|
|
|
|
'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/',###输出测试图像位置
|
|
|
|
}
|
|
|
|
# 'slopeIndex':[],###岸坡类别(或者其它业务里的类别),不与河道(分割的前景区域)计算交并比,即不论是否在河道内都显示。
|
|
|
|
# 'seg_nclass':2,###分割模型类别数目,默认2类
|
|
|
|
# 'segRegionCnt':0,###分割模型结果需要保留的等值线数目
|
|
|
|
# 'segPar':None,###分割模型预处理参数
|
|
|
|
# 'Segweights' : None,###分割模型权重位置
|
|
|
|
# '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/',###测试图像的位置
|
|
|
|
# 'testImgPath':'/mnt/thsw2/DSP2/weights/forest2/images_cloud_FP',
|
|
|
|
# 'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
###车辆巡检参数
|
|
|
@@ -1129,9 +1158,9 @@ def customization_demo(opt): |
|
|
|
'postProcess':{'function':channel2_post_process,'name':'channel2','pars':{'objs':[2],'wRation':1/6.0,'hRation':1/6.0,'smallId':0,'bigId':3,'newId':4,'recScale':1.2}},
|
|
|
|
'models':[
|
|
|
|
{
|
|
|
|
'weight':"../weights/%s/AIlib2/%s/yolov5_%s_fp16.engine"%(opt['gpu'], opt['business'] ,opt['gpu'] ),###检测模型路径
|
|
|
|
#'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.pt',
|
|
|
|
#'weight':'/mnt/thsw2/DSP2/weights/channel2/yolov5_2080Ti_fp16.engine',
|
|
|
|
'name':'yolov5',
|
|
|
|
'model':yolov5Model,
|
|
|
@@ -1165,6 +1194,7 @@ def customization_demo(opt): |
|
|
|
'digitFont': { 'line_thickness':2,'boxLine_thickness':1, 'fontSize':1.0,'waterLineColor':(0,255,255),'segLineShow':True,'waterLineWidth':2},###显示框、线设置
|
|
|
|
'testImgPath':'/mnt/thsw2/DSP2/weights/channel2/video_for_sales/',
|
|
|
|
#'testImgPath':'/home/thsw2/WJ/src/OCR/shipNames',
|
|
|
|
#'testImgPath':'images/tt/',
|
|
|
|
'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
}
|
|
|
|
|
|
|
@@ -1264,6 +1294,7 @@ def customization_demo(opt): |
|
|
|
#测试视频
|
|
|
|
|
|
|
|
###如果是视频文件
|
|
|
|
'''
|
|
|
|
for video in videopaths:
|
|
|
|
cap=cv2.VideoCapture(video)
|
|
|
|
fps,width,height,framecnt = get_video_para(cap)
|
|
|
@@ -1296,13 +1327,39 @@ def customization_demo(opt): |
|
|
|
ret = vid_writer_AI.write(img0)
|
|
|
|
view_bar(iframe, framecnt,time.time(),prefix=os.path.basename(video))
|
|
|
|
vid_writer_AI.release();
|
|
|
|
'''
|
|
|
|
def AI_process_C_multi( ps ):
|
|
|
|
return AI_process_C( ps[0] ,ps[1],ps[2] )
|
|
|
|
|
|
|
|
###用视频文件做一个多线程测试
|
|
|
|
max_workers=4
|
|
|
|
bs=4
|
|
|
|
for video in videopaths:
|
|
|
|
cap=cv2.VideoCapture(video)
|
|
|
|
fps,width,height,framecnt = get_video_para(cap)
|
|
|
|
print('-'*10,' line1307 fps:{}, width:{},height:{},framecnt:{} '.format( fps,width,height,framecnt) )
|
|
|
|
iframe =0
|
|
|
|
parsIns=[]
|
|
|
|
while cap.isOpened():
|
|
|
|
ret, img = cap.read() #读取摄像头画面
|
|
|
|
if not ret:break
|
|
|
|
parsIns.append( [ [img],modelList,par['postProcess'] ] )
|
|
|
|
iframe+=1
|
|
|
|
if iframe%bs==0:
|
|
|
|
with ThreadPoolExecutor(max_workers=max_workers) as t:
|
|
|
|
results = t.map(AI_process_C_multi, parsIns)
|
|
|
|
results = list(results)
|
|
|
|
print(iframe,len( parsIns ))
|
|
|
|
parsIns=[]
|
|
|
|
|
|
|
|
view_bar(iframe, framecnt,time.time(),prefix=os.path.basename(video))
|
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
|
|
|
|
#jkm_demo()
|
|
|
|
businessAll=['river2','AnglerSwimmer', 'countryRoad','forest2', 'pedestrian' , 'smogfire' , 'vehicle','ship2',"highWay2","channelEmergency","cityMangement","drowning","noParking","illParking",'cityMangement2',"cityRoad","crowdCounting",'cityMangement3','ocr_en','ocr_ch','pothole','crackMeasurement','channel2','riverT']
|
|
|
|
businessAll=['river2','AnglerSwimmer', 'countryRoad','forest2', 'pedestrian' , 'smogfire' , 'vehicle','ship2',"highWay2","channelEmergency","cityMangement","drowning","noParking","illParking",'cityMangement2',"cityRoad","crowdCounting",'cityMangement3','ocr_en','ocr_ch','pothole','crackMeasurement','channel2','riverT']
|
|
|
|
|
|
|
|
businessAll = ['channel2']
|
|
|
|
businessAll = ['forest2']
|
|
|
|
|
|
|
|
# forest 、 ocr2 、ocr_en 、 river 、 road 、 ship ,目前都没有在用
|
|
|
|
for busi in businessAll:
|
|
|
@@ -1310,7 +1367,7 @@ if __name__=="__main__": |
|
|
|
opt={'gpu':'2080Ti','business':busi}
|
|
|
|
if opt['business'] in ['highWay2','river2','drowning','noParking','river',"illParking","cityMangement2","riverT"]:
|
|
|
|
detSeg_demo(opt)
|
|
|
|
elif opt['business'] in ['cityMangement3'] :
|
|
|
|
elif opt['business'] in ['cityMangement3','forest2'] :
|
|
|
|
detSeg_demo2(opt)
|
|
|
|
elif opt['business'] in ['crowdCounting'] :
|
|
|
|
crowd_demo(opt)
|