Pytorch 不适用于训练模型+预训练模型(Intel Open Vino)

问题描述 投票:0回答:1
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 将模型转换为 IR (https://docs.openvino.ai/2022.3/openvino_docs_MO_DG_prepare_model_convert_model_Convert_Model_From_PyTorch.html) 之后,我将预训练的行人模型(https://docs.openvino.ai/2021.4/omz_models_model_pedestrian_detection_adas_0002.html)和我的模型结合在一起(对象检测+识别,如车牌识别/检测)。 但是,组合模型无法正常工作...我检查了模型的准确性,接近 96%。因此,我不确定是什么导致了这个问题。我已经被这个问题困扰了很长时间了。

我在下面上传了我的 colab,我用来训练我的模型 在此输入链接描述

python opencv deep-learning pytorch openvino
1个回答
0
投票

我将您的模型与 OpenVINO 预训练模型行人检测-adas-0002 进行了测试和比较,因为您提到这是您的 DL 模型开发的参考。

我通过对象检测 Python 演示推断了这两个模型(我从 OMZ 存储库得到了这个)

我的发现是,你的模型没有 OV 模型那样的正确包装器。行人检测-adas-0002 使用基于 SSD 框架的网络,并使用经过调整的 MobileNet v1 作为特征提取器。

也许这是您需要满足您的定制模型的部分。

© www.soinside.com 2019 - 2024. All rights reserved.