Ask Your Question
2

How to run pretrained model with OpenVINO on RPi

asked 2018-12-21 12:14:59 -0600

nikogamulin gravatar image

updated 2018-12-22 03:48:50 -0600

Hi,

After successfully running python face detection example, I tried to modify the code in order to run vehicle and licence plate detection, but the model didn't detect anything. As I haven't figured out what's the issue, I would appreciate any suggestion regarding the problem.

The script I wrote looks as follows:

import cv2

def predict(frame, net):
    # Prepare input blob and perform an inference
    blob = cv2.dnn.blobFromImage(frame, size=(300, 300), ddepth=cv2.CV_8U)
    net.setInput(blob)
    out = net.forward()

    predictions = []

    # The net outputs a blob with the shape: [1, 1, N, 7], where N is the number of detected bounding boxes.
    # For each detection, the description has the format: [image_id, label, conf, x_min, y_min, x_max, y_max]

    # Draw detected faces on the frame
    for detection in out.reshape(-1, 7):
        image_id, label, conf, x_min, y_min, x_max, y_max = detection

        if conf > 0.5:
            predictions.append(detection)

    # return the list of predictions to the calling function
    return predictions

# Load the model
net = cv2.dnn.readNet('models/vehicle-license-plate-detection-barrier-0106.xml', 'models/vehicle-license-plate-detection-barrier-0106.bin')

# Specify target device
net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)

# Read an image
frame = cv2.imread('screenshots/mercedes.jpg')

predictions = predict(frame, net)

# Draw detected faces on the frame
for prediction in predictions:
    confidence = float(detection[2])
    xmin = int(detection[3] * frame.shape[1])
    ymin = int(detection[4] * frame.shape[0])
    xmax = int(detection[5] * frame.shape[1])
    ymax = int(detection[6] * frame.shape[0])

    cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))

# Save the frame to an image file
cv2.imwrite('out.png', frame)

Basically, I have downloaded the model files from this adddress and then modified input dimensions according to specifications.

To test the detection, I used the image attached below

image description

The model I wanted to test is described here

Update

Now I tried to use vehicle-detection-adas-0002 model and it works. The differences I noticed are in the models:

  • vehicle-license-plate-detection-barrier-0106 is a MobileNetV2 + SSD-based vehicle and license plate detector for the "Barrier" use case

  • vehicle-detection-adas-0002 is a vehicle detection network based on an SSD framework with tuned MobileNet v1 as a feature extractor

So I guess these models might have to be initialized differently.

edit retag flag offensive close merge delete

Comments

@nikogamulin, please attach the image is used in your sample.

dkurt gravatar imagedkurt ( 2018-12-21 12:57:00 -0600 )edit

@nikogamulin. Where is link for raspberry pi...how to install openvino?

supra56 gravatar imagesupra56 ( 2018-12-21 13:40:26 -0600 )edit
1

@dkurt, thank.

supra56 gravatar imagesupra56 ( 2018-12-21 13:55:45 -0600 )edit

hello there... am using openVINO with raspbian and NCS and its working fine..but i cannot able to use opencv withit...

it shows error:

cv2.error: OpenCV(4.0.0) /home/pi/opencv/modules/dnn/src/dnn.cpp:2538: error: (-2:Unspecified error) Build OpenCV with Inference Engine to enable loading models from Model Optimizer. in function 'readFromModelOptimizer'

will you tell me..how to build opencv with inference engine.

Thanking you

dilli24 gravatar imagedilli24 ( 2019-01-10 05:54:18 -0600 )edit

@dilli24 -- please do not post answers here, if you have a question or a comment, thank you !

also please look at the links above ... imho, yoour question is already answered there !

berak gravatar imageberak ( 2019-01-10 05:59:32 -0600 )edit

how to install opencv with inference engine...i cant see the answer above..

dilli24 gravatar imagedilli24 ( 2019-01-10 06:07:13 -0600 )edit

https://software.intel.com/articles/O...

(but if you read the small print there, you'll need hardware, like movidius, to do the inference)

berak gravatar imageberak ( 2019-01-10 06:17:49 -0600 )edit

yes i followed the article... openVINO is working with NCS in raspbian...but when i try the second demo using opencv its showing the error..i installed opencv separately...do i need to do few extra steps..?

dilli24 gravatar imagedilli24 ( 2019-01-10 23:53:34 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-12-22 04:09:12 -0600

dkurt gravatar image

@nikogamulin, using your sample without any changes (except typo in drawing loop at the end) can give me a single license plate detection (check that you use FP16 model but not FP32 one):

image description

edit flag offensive delete link more

Comments

Thanks! Why isn't there another bounding box for a car, same as in the example, provided here

nikogamulin gravatar imagenikogamulin ( 2018-12-22 08:37:44 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-12-21 12:14:59 -0600

Seen: 1,454 times

Last updated: Dec 22 '18