Community
cancel
Showing results for 
Search instead for 
Did you mean: 
fu__cfu
Beginner
99 Views

incorrect detection output with MobileNet-SSD

Hi,

 

I trained a caffe MobileNet-SSD model with my own dataset based on https://github.com/chuanqi305/MobileNet-SSD .

The model works perfect if I load it with cv2.dnn.readNetFromCaffe and CPU.

However, when I load it with cv2.dnn.readNetFromCaffe and MYRIAD, the results are different and less accurate. Any suggestion?

 

 

The below codes are run on Raspberry Pi stretch with opencv '4.1.0-openvino' and NCS2:

#!/usr/bin/env python3
import json
import cv2

def decode_out(out):
    detections = []

    for data in out[0,0,:,:]:
        if float(data[2]) > 0.3:
            detections.append({
                "bbox": [float(x) for x in data[3:]],
                "score": float(data[2]),
                "class_id": int(data[1])
            })
    
    return sorted(detections,key=lambda x:x['score'], reverse=True)

image = cv2.imread("/home/pi/test.jpg")
image = cv2.resize(image, (300,300))
input_blob = cv2.dnn.blobFromImage(image, 1.0/127.5, (300,300), (127.5, 127.5, 127.5), False, False)

model = "/home/pi/no_bn.caffemodel"
prototxt = "/home/pi/no_bn.prototxt"
net = cv2.dnn.readNetFromCaffe(prototxt, model)

# wiht CPU
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV)
net.setInput(input_blob)
out1 = net.forward()
print(json.dumps(decode_out(out1),indent=2))

# with NCS2
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
net.setInput(input_blob)
out2 = net.forward()
print(json.dumps(decode_out(out2),indent=2))

 

 

0 Kudos
3 Replies
Shubha_R_Intel
Employee
99 Views

Dear fu, cfu,

Did you use the "--input_shape" command-line parameter in your model optimizer command ? Usually when detection is off, that is the reason. Please make sure you pass in a proper value which exactly matches the image size the model was trained on.

Also, did you do any pre-processing on your images before training ? Please see my detailed answer to this post

Thanks,

Shubha

 

fu__cfu
Beginner
99 Views

Hi Shubha,

Thanks for the response. In fact, I am not using the model optimizer in this case, instead I am using the caffe model only. 

The issue is that the outputs are different with CPU and MYRIAD(NCS2), and the CPU one is way better. 

 

Shubha_R_Intel
Employee
99 Views

Dear fu, cfu,

OK I see.

The model works perfect if I load it with cv2.dnn.readNetFromCaffe and CPU.

However, when I load it with cv2.dnn.readNetFromCaffe and MYRIAD, the results are different and less accurate. Any suggestion?

This forum is meant for Model Optimizer and Inference Engine, which forms the core of OpenVino. For OpenCV questions, please post your questions here :

https://github.com/opencv/opencv/issues

https://answers.opencv.org/questions/

Thanks !

Shubha

Reply