Browse Source

add cityMangement2 model

master
wangjin0928 1 year ago
parent
commit
39f71bb863
17 changed files with 92 additions and 28 deletions
  1. +48
    -20
      demo.py
  2. +44
    -8
      demo3.0.py
  3. BIN
      images/cityMangement2/DJI_0005_15.jpg
  4. BIN
      images/cityMangement2/DJI_0970_6.jpg
  5. BIN
      images/cityMangement2/DJI_0974_15.jpg
  6. BIN
      images/cityMangement2/DJI_0975_20.jpg
  7. BIN
      images/cityMangement2/DJI_0979_83.jpg
  8. BIN
      images/cityMangement2/DJI_0981_82.jpg
  9. BIN
      images/cityMangement2/DJI_0988_20.jpg
  10. BIN
      images/cityMangement2/DJI_0994_105.jpg
  11. BIN
      images/cityMangement2/DJI_0996_104.jpg
  12. BIN
      images/cityMangement2/DJI_0997_3.jpg
  13. BIN
      images/cityMangement2/DJI_20230626103222_0008_Z_13.jpg
  14. BIN
      images/cityMangement2/DJI_20230626104206_0011_S_7.jpg
  15. BIN
      images/cityMangement2/DJI_20230626104738_0013_Z_23.jpg
  16. BIN
      images/cityMangement2/DJI_20230626104930_0014_S_11.jpg
  17. BIN
      images/cityMangement2/DJI_20230626104930_0014_Z_33.jpg

+ 48
- 20
demo.py View File

@@ -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)

+ 44
- 8
demo3.0.py View File

@@ -7,7 +7,8 @@ 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
import cv2,os,time
from segutils.segmodel import SegModel
from segutils.segmodel import SegModel
from stdc import stdcModel
from segutils.trafficUtils import tracfficAccidentMixFunction
from models.experimental import attempt_load
from utils.torch_utils import select_device
@@ -263,10 +264,7 @@ def det_track_demo(business ):
'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,
'pars':
#{ 'roundness': 0.3, 'cls': 9, 'laneArea': 10, 'laneAngleCha': 5 ,'RoadArea': 16000, }
{ 'roundness': 0.3, 'cls': 9, 'laneArea': 10, 'laneAngleCha': 5 ,'RoadArea': 16000}
'pars': { 'roundness': 0.3, 'cls': 9, 'laneArea': 10, 'laneAngleCha': 5 ,'RoadArea': 16000}
}
},
@@ -282,6 +280,38 @@ def det_track_demo(business ):
'testOutPath':'images/results/',###输出测试图像位置
}
par['segPar']['mixFunction']['pars']['modelSize'] = par['segPar']['modelSize']
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, ###并行线程数
'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}
}
},
'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'] ),###检测模型路径
'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':'images/cityMangement/',
'testOutPath':'images/results/',###输出测试图像位置
}
if opt['business'] == 'drowning':
par={
'device':'0', ###显卡号,如果用TRT模型,只支持0(单显卡)
@@ -508,7 +538,7 @@ def det_track_demo(business ):
##使用森林,道路模型,business 控制['forest','road']
##预先设置的参数
gpuname=par['gpuname']#如果用trt就需要此参数,只能是"3090" "2080Ti"
#gpuname=par['gpuname']#如果用trt就需要此参数,只能是"3090" "2080Ti"
device_=par['device'] ##选定模型,可选 cpu,'0','1'
@@ -537,6 +567,11 @@ def det_track_demo(business ):
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)
@@ -547,6 +582,7 @@ def det_track_demo(business ):
Segweights = par['Segweights']
segmodel = SegModel(nclass=seg_nclass,weights=Segweights,device=device)
print('############locad seg model pth success:',Segweights)
'''
else:
segmodel=None
@@ -830,8 +866,8 @@ def OBB_track_demo(opt):
if __name__=="__main__":
#jkm_demo()
#businessAll=['river', 'river2','highWay2','noParking','drowning','forest2','vehicle','pedestrian','smogfire' , 'AnglerSwimmer','channelEmergency', 'countryRoad','cityMangement','ship2']
businessAll = ['noParking']
businessAll=['river', 'river2','highWay2','noParking','drowning','forest2','vehicle','pedestrian','smogfire' , 'AnglerSwimmer','channelEmergency', 'countryRoad','cityMangement','ship2','cityMangement2']
businessAll = ['cityMangement2']
for busi in businessAll:
print('-'*40,'beg to test:',busi,'-'*40)

BIN
images/cityMangement2/DJI_0005_15.jpg View File

Before After
Width: 3840  |  Height: 2160  |  Size: 2.1MB

BIN
images/cityMangement2/DJI_0970_6.jpg View File

Before After
Width: 3840  |  Height: 2160  |  Size: 3.1MB

BIN
images/cityMangement2/DJI_0974_15.jpg View File

Before After
Width: 3840  |  Height: 2160  |  Size: 2.7MB

BIN
images/cityMangement2/DJI_0975_20.jpg View File

Before After
Width: 3840  |  Height: 2160  |  Size: 2.8MB

BIN
images/cityMangement2/DJI_0979_83.jpg View File

Before After
Width: 3840  |  Height: 2160  |  Size: 2.4MB

BIN
images/cityMangement2/DJI_0981_82.jpg View File

Before After
Width: 3840  |  Height: 2160  |  Size: 2.5MB

BIN
images/cityMangement2/DJI_0988_20.jpg View File

Before After
Width: 3840  |  Height: 2160  |  Size: 1.9MB

BIN
images/cityMangement2/DJI_0994_105.jpg View File

Before After
Width: 3840  |  Height: 2160  |  Size: 2.8MB

BIN
images/cityMangement2/DJI_0996_104.jpg View File

Before After
Width: 3840  |  Height: 2160  |  Size: 2.7MB

BIN
images/cityMangement2/DJI_0997_3.jpg View File

Before After
Width: 3840  |  Height: 2160  |  Size: 2.9MB

BIN
images/cityMangement2/DJI_20230626103222_0008_Z_13.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 1.1MB

BIN
images/cityMangement2/DJI_20230626104206_0011_S_7.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 937KB

BIN
images/cityMangement2/DJI_20230626104738_0013_Z_23.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 909KB

BIN
images/cityMangement2/DJI_20230626104930_0014_S_11.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 814KB

BIN
images/cityMangement2/DJI_20230626104930_0014_Z_33.jpg View File

Before After
Width: 1920  |  Height: 1080  |  Size: 879KB

Loading…
Cancel
Save