Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to run pretrained model with OpenVINO on RPi

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.

click to hide/show revision 2
retagged

updated 2018-12-21 12:17:34 -0600

berak gravatar image

How to run pretrained model with OpenVINO on RPi

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.

How to run pretrained model with OpenVINO on RPi

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

How to run pretrained model with OpenVINO on RPi

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

How to run pretrained model with OpenVINO on RPi

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.