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
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.
@nikogamulin, please attach the image is used in your sample.
@nikogamulin. Where is link for raspberry pi...how to install openvino?
@supra56, https://software.intel.com/articles/O...
@dkurt, thank.
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 -- 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 !
how to install opencv with inference engine...i cant see the answer above..
https://software.intel.com/articles/O...
(but if you read the small print there, you'll need hardware, like movidius, to do the inference)
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..?