open_model_zoo
open_model_zoo copied to clipboard
Dynamic Open Model Zoo as Python module
Current state
Adding to OpenVino
- Create a symbolic link:
ln -s /opt/intel/openvino_2021/deployment_tools/open_model_zoo/libs/python/open_model_zoo.py /opt/intel/openvino_2021/python/python3.X/openvino/open_model_zoo.py - Add path to downloader to python path
export PYTHONPATH=$PYTHONPATH:/opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader - Initialize openvino enviroment variable :
source /opt/intel/openvino_2021/bin/setupvars.sh
Model's downloading
import openvino.open_model_zoo as omz
ssd = omz.Model('mobilenet-ssd')
################|| Downloading models ||################
========== Downloading /user/models/public/mobilenet-ssd/mobilenet-ssd.prototxt
... 100%, 28 KB, 38894 KB/s, 0 seconds passed
========== Downloading /user/models/public/mobilenet-ssd/mobilenet-ssd.caffemodel
... 100%, 22605 KB, 3760 KB/s, 6 seconds passed
################|| Post-processing ||################
Documentation
import openvino.open_model_zoo as omz
ssd = omz.Model('mobilenet-ssd', precision='FP32')
print('Model task type: ' + ssd.task_type)
print(ssd.description)
Model task type: detection
The "mobilenet-ssd" model is a Single-Shot multibox Detection (SSD) network intended to perform object detection. This model is implemented using the Caffe* framework. For details about this model, check out the repository <https://github.com/chuanqi305/MobileNet-SSD>.
The model input is a blob that consists of a single image of 1x3x300x300 in BGR order, also like the "densenet-121" model. The BGR mean values need to be subtracted as follows: [127.5, 127.5, 127.5] before passing the image blob into the network. In addition, values must be divided by 0.007843.
The model output is a typical vector containing the tracked object data, as previously described.
License: https://raw.githubusercontent.com/chuanqi305/MobileNet-SSD/master/LICENSE
Usage example
import os
import numpy as np
import cv2 as cv
import openvino.open_model_zoo as omz
from openvino.inference_engine import IECore
ssd = omz.Model('mobilenet-ssd', precision='FP32')
xml_path, bin_path = ssd.xml_path, ssd.bin_path
ie = IECore()
net = ie.read_network(xml_path, bin_path)
exec_net = ie.load_network(net, 'CPU')
image = cv.imread('example.jpeg')
predictions = detect(net, image)
rows = image.shape[0]
cols = image.shape[1]
for detection in predictions.reshape(-1, 7):
image_id = detection[0]
if image_id < 0:
break
if detection[2] > 0.6:
xmin = int(detection[3] * cols)
ymin = int(detection[4] * rows)
xmax = int(detection[5] * cols)
ymax = int(detection[6] * rows)
cv.rectangle(image, (xmin, ymin), (xmax, ymax), (0, 255, 0))
cv.imshow('out', image)
cv.waitKey()

- Tests To run tests use:
source /opt/intel/openvino_2021/bin/setupvars.sh
python3 /user/open_model_zoo/tools/downloader/open_model_zoo_test.py
Can one of the admins verify this patch?
Can one of the admins verify this patch?
Can one of the admins verify this patch?
Can one of the admins verify this patch?
Can one of the admins verify this patch?
@dkurt
Hi @likholat,
please make develop as target branch for your request,
thanks
import topologies as omz
face_detection = omz.Topology('face-detection-0102', precision='FP32')
xml_path, bin_path = face_detection.get_ir('FP16')
output:
################|| Downloading models ||################
========== Downloading /models/intel/face-detection-0102/FP32/face-detection-0102.xml
... 100%, 162 KB, 401520 KB/s, 0 seconds passed
========== Downloading /models/intel/face-detection-0102/FP32/face-detection-0102.bin
... 100%, 7098 KB, 4240 KB/s, 1 seconds passed
################|| Post-processing ||################
========== Skipping face-detection-0102 (no conversions defined)
@IRDonch, @ngaloppo, Please review this PR. This PR is a continuation of https://github.com/openvinotoolkit/open_model_zoo/pull/304
For topology.py, downloader.py and converter.py change imports: import common -> from . import common import downloader -> from . import downloader import converter -> from . import converter
- Is there a way to avoid changing these files?
- Can the procedure be simplified if we assume that file is named as
open_model_zoo.py?
You seem to be missing a block of hidden comments. Make sure to expand all comments.
@IRDonch, please, tell me, which directory is the best place to put the open_model_zoo.py?
@likholat I already made a suggestion above:
I would suggest
libs/python/open_model_zoo.py.
@likholat @dkurt @IRDonch May I know why has this PR stalled?
@druzhkov-paul, good question. @likholat, let's revise our latest progress. For Python demos such kind of feature would be very nice.
@IRDonch @eizamaliev, please review it again
Jenkins please retry a build
Jenkins please retry a build
@nignatovsky please look at this, some CI issue
Jenkins please retry a build
Jenkins please retry a build
Jenkins please retry a build
Jenkins please retry a build
Do you know if there is a way to have
openvino.model_zoo.open_model_zooandopenvino.model_zoo.model_api.modelsboth in editable mode at the same time throughpip -eorPYTHONPATH?
I believe it doesn't work because there is a demos/common/python/openvino/model_zoo/__init__.py file, which marks openvino.model_zoo as being a regular package. A regular package can only belong to a single project. The simplest way to fix this is to turn openvino.model_zoo into a namespace package by removing that __init__.py file (you might also need to adjust setup.py accordingly).
There are two ways of creating a namespace package. Omitting __init__.py or putting __path__ = __import__('pkgutil').extend_path(__path__, __name__) into it. We are forced to use the second option for openvino namespaces after the main openvino project. To be consistent for model_zoo namespace we should follow the same option. @jkamelin, please, add it
We are forced to use the second option for openvino namespaces after the main openvino project.
FWIW, I don't think you're actually forced to use this option, because native namespace packages are compatible with pkgutil-style ones. pkgutil.extend_path will locate all directories named after the package, regardless of whether they have an __init__.py file or not.
Yes, I realized that after I posted the message. But still, it feels reasonable to go with __path__ = __import__('pkgutil').extend_path(__path__, __name__) to stay aligned with root openvino init
@jkamelin there is merge conflict