- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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))
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page