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
366 stars 127 forks source link

MultiStickWithPiCamera example using custom mobile net ssd model results error #28

Open DogukanAltay opened 5 years ago

DogukanAltay commented 5 years ago

Device: Raspberry Pi 3 B+

CPU Arch.: armv7l

OS: Raspbian

I have trained a custom 1 class mobile net ssd v2 network using Tensorflow Object Detection API and successfully converted to to IR model using OpenVino 2019 R1.1. Then I substituted the model files in the MultiStickWithPiCamera.py example with my custom model. The predict_async thread raises an error.

Error message:

line 174, in predict_async cnt, dev = heapq.heappop(self.heap_request) IndexError: index out of range

DogukanAltay commented 5 years ago

Update: I have resolved the problem. The reason is that, I am using a tensorflow implementation of Mobilenet SSDv2. Therefore after the conversion with the openvino model optimizer, the input layers and output layers are actually different from the model here.

In my case, I have changed the lines above in the MultiStickSSDwithUSBCamera_OpenVINO_NCS2.py

# Lines 147-154
def image_preprocessing(self, color_image):

    prepimg = cv2.resize(color_image, (300, 300))
    # Commented out the below lines to match the input format of my model. Edit yours accordingly.
    # prepimg = prepimg - 127.5
    # prepimg = prepimg * 0.007843
    prepimg = prepimg[np.newaxis, :, :, :]  # Batch size axis add
    prepimg = prepimg.transpose((0, 3, 1, 2))  # NHWC to NCHW
    return prepimg

and

# Line 179
# For my model, output dict returns with "DetectionOutput" key. You can find yours and replace accordingly.
out = self.exec_net.requests[dev].outputs["DetectionOutput"].flatten()