def PeopleBox(PeopleNet,frame):
frameHeight=frame.shape[0]
frameWidth=frame.shape[1]
blob=cv2.dnn.blobFromImage(frame, 1.0, (672,384), swapRB=False, crop=True)
PeopleNet.setInput(blob)
detection=PeopleNet.forward()
bboxs=[]
for i in range(detection.shape[2]):
confidence=detection[0,0,i,2]
if confidence>0.7:
x1=int(detection[0,0,i,3]*frameWidth)
y1=int(detection[0,0,i,4]*frameHeight)
x2=int(detection[0,0,i,5]*frameWidth)
y2=int(detection[0,0,i,6]*frameHeight)
bboxs.append([x1,y1,x2,y2])
cv2.rectangle(frame, (x1,y1),(x2,y2),(0,255,0), 8)
return frame, bboxs
PeopleBin = (r"C:\Users\dc\T1\pedestrian-detection-adas-0002.bin")
PeopleXml = (r"C:\Users\dc\T1\pedestrian-detection-adas-0002.xml")
RifleBin = (r"C:\Users\dc\StructVGGV1_output\VGG16_V1_40epohc_LR0_00008_batch4_A96_V77.bin")
RifleXml = (r"C:\Users\dc\StructVGGV1_output\VGG16_V1_40epohc_LR0_00008_batch4_A96_V77.xml")
PeopleNet=cv2.dnn.readNet(PeopleXml, PeopleBin)
RifleNet=cv2.dnn.readNet(RifleXml,RifleBin)
List = ['NoPersonHoldingRifle', 'PersonHoldingRifle']
video=cv2.VideoCapture(0)
while True:
ret,frame=video.read()
framee,bboxs=PeopleBox(PeopleNet,frame)
for bbox in bboxs:
########check
blob=cv2.dnn.blobFromImage(framee, 1.0, (224,224), swapRB=False, crop = True)
RifleNet.setInput(blob)
###########
RiflePred=RifleNet.forward()
Rifle=List[RiflePred[0].argmax()]
#label="{},{}".format(Rifle,RiflePred)
label="{}".format(Rifle)
if label=="NoPersonHoldingRifle":
cv2.rectangle(framee, (bbox[0], bbox[1]), (bbox[2],bbox[3]), (255,0,255), 8)
if label == "PersonHoldingRifle":
cv2.rectangle(framee, (bbox[0], bbox[1]), (bbox[2],bbox[3]), (255,255,0), 8)
cv2.putText(framee, label, (bbox[0]-70, bbox[1]-10), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255,255,255), 2,cv2.LINE_AA)
cv2.imshow("Rifle_Vs_NoRifle",framee)
cv2.imshow("Rifle_Vs_NoRifle",framee)
k=cv2.waitKey(1)
if k==ord('q'):
break
video.release()
cv2.destroyAllWindows()
字符串
我使用Google Colab用Pytorch训练了我的模型。在我训练了我的模型之后,我使用Intel Open Vino(https://docs.openvino.ai/2022.3/openvino_docs_MO_DG_prepare_model_convert_model_Convert_Model_From_PyTorch.html)将我的模型转换为IR。之后,我将预训练的行人模型(https://docs.openvino.ai/2021.4/omz_models_model_pedestrian_detection_adas_0002.html)和我的模型结合在一起(物体检测+识别,如车牌识别/检测)。但是,组合模型不能正常工作...我检查了我的模型的准确性,它接近96%。因此,我不确定是什么导致了这个问题。我已经被困在这很长一段时间。
我上传了我的colab下面我用来训练我的模型enter link description here
1条答案
按热度按时间eeq64g8w1#
我测试并比较了您的模型与OpenVINO预训练模型pedestrian-detection-adas-0002,因为您提到这是您的DL模型开发的参考。
我用Object Detection Python Demo推断了这两个模型(我从OMZ repo得到的)
我的发现是你的模型没有像OV模型那样有正确的 Package 器。行人检测-adas-0002使用基于SSD框架的网络,并使用调优的MobileNet v1作为特征提取器。
也许这是你需要迎合你的自定义模型的一部分。
x1c 0d1x的数据