|
|
@@ -5,6 +5,8 @@ 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 stdc import stdcModel
|
|
|
|
|
|
|
|
import cv2,os,time
|
|
|
|
from segutils.segmodel import SegModel
|
|
|
|
|
|
|
@@ -69,7 +71,9 @@ def process_v1(frame): |
|
|
|
if frame[2]:
|
|
|
|
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))
|
|
|
|
if isinstance(image_mask,np.ndarray) and image_mask.shape[0]>0:
|
|
|
|
|
|
|
|
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:
|
|
|
@@ -286,16 +290,46 @@ def detSeg_demo(opt): |
|
|
|
'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
}
|
|
|
|
|
|
|
|
if opt['business'] == 'cityMangement2':
|
|
|
|
from DMPR import DMPRModel
|
|
|
|
from DMPRUtils.jointUtil import dmpr_yolo
|
|
|
|
|
|
|
|
par={
|
|
|
|
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
|
|
|
|
'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'] ),###检测模型路径
|
|
|
|
#'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}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
#'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'] ),###检测模型路径
|
|
|
|
'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/images/input',
|
|
|
|
'testImgPath':'/mnt/thsw2/DSP2/videos/hightWay2/',
|
|
|
|
'testOutPath':'images/results/',###输出测试图像位置
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if par['Segweights']:
|
|
|
|
par['trtFlag_seg']=True if par['Segweights'].endswith('.engine') else False
|
|
|
|
else:
|
|
|
|
par['trtFlag_seg']=False
|
|
|
|
|
|
|
|
par['trtFlag_det']=True if par['Detweights'].endswith('.engine') else False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mode = par['mode'] if 'mode' in par.keys() else 'others'
|
|
|
|
postPar = par['postPar'] if 'postPar' in par.keys() else None
|
|
|
|
|
|
|
@@ -322,20 +356,13 @@ def detSeg_demo(opt): |
|
|
|
if half: model.half()
|
|
|
|
|
|
|
|
|
|
|
|
seg_nclass = par['seg_nclass']
|
|
|
|
par['segPar']['seg_nclass'] = par['seg_nclass']
|
|
|
|
segPar=par['segPar']
|
|
|
|
if par['Segweights']:
|
|
|
|
if 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)
|
|
|
|
if opt['business'] == 'cityMangement2':
|
|
|
|
segmodel = DMPRModel(weights=par['Segweights'], par = par['segPar'])
|
|
|
|
else:
|
|
|
|
Segweights = par['Segweights']
|
|
|
|
print('####line293:',seg_nclass, Segweights)
|
|
|
|
segmodel = SegModel(nclass=seg_nclass,weights=Segweights,device=device)
|
|
|
|
print('############locad seg model pth success:',Segweights,segmodel,seg_nclass )
|
|
|
|
segmodel = stdcModel(weights=par['Segweights'], par = par['segPar'])
|
|
|
|
else:
|
|
|
|
segmodel= None
|
|
|
|
print('############None seg model is loaded###########:' )
|
|
|
@@ -382,10 +409,11 @@ def detSeg_demo(opt): |
|
|
|
t1=time.time()
|
|
|
|
if max_workers==1:
|
|
|
|
for i in range(len(imgpaths)):
|
|
|
|
print('-'*20,imgpaths[i],'-'*20)
|
|
|
|
t5=time.time()
|
|
|
|
process_v1(frames[i])
|
|
|
|
t6=time.time()
|
|
|
|
print('#######%s, ms:%.1f , accumetate time:%.1f, avage:%1.f '%(os.path.basename(imgpaths[i]), (t6-t5)*1000.0,(t6-t1)*1000.0, (t6-t1)*1000.0/(i+1)))
|
|
|
|
#print('#######%s, ms:%.1f , accumetate time:%.1f, avage:%1.f '%(os.path.basename(imgpaths[i]), (t6-t5)*1000.0,(t6-t1)*1000.0, (t6-t1)*1000.0/(i+1)))
|
|
|
|
else:
|
|
|
|
with ThreadPoolExecutor(max_workers=max_workers) as t:
|
|
|
|
for result in t.map(process_v1, frames):
|
|
|
@@ -650,7 +678,7 @@ def det_demo(business ): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
segRegionCnt=par['segRegionCnt']
|
|
|
|
#segRegionCnt=par['segRegionCnt']
|
|
|
|
trtFlag_seg = par['trtFlag_seg'];segPar=par['segPar']
|
|
|
|
##使用森林,道路模型,business 控制['forest','road']
|
|
|
|
##预先设置的参数
|
|
|
@@ -905,16 +933,16 @@ def jkm_demo(): |
|
|
|
if __name__=="__main__":
|
|
|
|
|
|
|
|
#jkm_demo()
|
|
|
|
businessAll=['river2','AnglerSwimmer', 'countryRoad','forest2', 'pedestrian' , 'smogfire' , 'vehicle','ship2',"highWay2","channelEmergency","cityMangement","drowning","noParking","illParking"]
|
|
|
|
businessAll=['river2','AnglerSwimmer', 'countryRoad','forest2', 'pedestrian' , 'smogfire' , 'vehicle','ship2',"highWay2","channelEmergency","cityMangement","drowning","noParking","illParking",'cityMangement2']
|
|
|
|
|
|
|
|
businessAll = ['noParking']
|
|
|
|
businessAll = ['highWay2']
|
|
|
|
|
|
|
|
# forest 、 ocr2 、ocr_en 、 river 、 road 、 ship ,目前都没有在用
|
|
|
|
|
|
|
|
for busi in businessAll:
|
|
|
|
print('-'*40,'beg to test ',busi,'-'*40)
|
|
|
|
opt={'gpu':'2080Ti','business':busi}
|
|
|
|
if opt['business'] in ['highWay2','river2','drowning','noParking','river',"illParking"]:
|
|
|
|
if opt['business'] in ['highWay2','river2','drowning','noParking','river',"illParking","cityMangement2"]:
|
|
|
|
detSeg_demo(opt)
|
|
|
|
elif opt['business'] in ['ship2']:
|
|
|
|
OBB_demo(opt)
|