PINTO0309 / MobileNet-SSD-RealSense

[High Performance / MAX 30 FPS] RaspberryPi3(RaspberryPi/Raspbian Stretch) or Ubuntu + Multi Neural Compute Stick(NCS/NCS2) + RealSense D435(or USB Camera or PiCamera) + MobileNet-SSD(MobileNetSSD) + Background Multi-transparent(Simple multi-class segmentation) + FaceDetection + MultiGraph + MultiProcessing + MultiClustering
https://qiita.com/PINTO
MIT License
364 stars 126 forks source link

MobileNet-SSD + NCS1 + my own datasets #25

Open libingyang0 opened 5 years ago

libingyang0 commented 5 years ago

Hello,PINTO0309! When I trained MobileNet-SSD on my own datasets(20 different classes, 400 images per class), I found the results of FP32 and FP16 be completely different(the caffe model test detection_eval is 0.91). And the same problem also happend when I trained YOLOv3 on my own datasets(follow your other github program). Are you trying to train the model with your own data? I doubted if the openvino and ncsdk can only convert the specific model perfectly. Could you give me some advices? Thank you!

cfdcfc commented 5 years ago

I also suffer from this issue, I train on my own dataset based on https://github.com/chuanqi305/MobileNet-SSD and generate caffe model.

The output is different run with CPU and NCS2 , 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))