Interactive Open Model Zoo as OpenCV module#272
Interactive Open Model Zoo as OpenCV module#272dkurt wants to merge 27 commits intoopenvinotoolkit:developfrom
Conversation
|
Can one of the admins verify this patch? |
1 similar comment
|
Can one of the admins verify this patch? |
0d73fbd to
9926897
Compare
|
@snosov1, For now it's a kind of bug in OpenCV's wrappers (related feature request opencv/opencv#14730). For now there is a workaround for it to define a method with proper name: class TextRecognitionPipelineImpl
{
//...
};
Ptr<TextRecognitionPipelineImpl> TextRecognitionPipeline(...) { return new TextRecognitionPipelineImpl(...); }corresponding Python code: from cv2.open_model_zoo import TextRecognitionPipeline
p = TextRecognitionPipeline()
It'd be nice. In example, add more Python demos for existing C++ ones. The only thing we have to decide is a code duplication: move C++ code from samples to the module and replace it to corresponding APIs. |
|
Not sure I understand the answers, Dmitry =)
Are you saying that it will look "normal" after the merge of the respective PR?
That's a different story. For starters we should have at least one to showcase this type of usage. |
from cv2.open_model_zoo import TextRecognitionPipeline
p = TextRecognitionPipeline()would be available :) I'll provide the code which do it in future commits. Maybe one of open questions is name scopes to differ "topologies" from "algorithms". In example, from cv2.open_model_zoo.topologies import text_detection, text_recognition
from cv2.open_model_zoo import TextRecognitionPipeline
p = TextRecognitionPipeline() |
09d5c37 to
eaec181
Compare
|
@dkurt This is a really amazing PR, incredible work! If you need help putting together examples of how to use it let me know and I'll publish some content on the PyImageSearch blog 😄 |
|
Adrian, thank you! That would be great! |
7553cb5 to
ce226b7
Compare
|
Absolutely! I'll keep an eye on this PR and once it's merged I'll put something together 😄 I was looking at the |
|
@jrosebr1, I think that next step is to enable these pipelines to with with different kind of models (it could be as EAST text detection as Intel's models). |
|
Without going into a detailed review, I have a few high level comments:
|
|
@IRDonch, thanks for review!
We can also build it as a part of OpenCV's binaries for OpenVINO. Just adding
Python code is based on OMZ's downloader and https://github.com/opencv/opencv_extra/blob/master/testdata/dnn/download_models.py. Binaries uses only default Python packages (
Most of postprocessing doesn't seem actual: postprocessing:
- $type: regex_replace
file: mtcnn-p.prototxt
pattern: 'dim: 12'
replacement: 'dim: 720'
count: 1
- $type: regex_replace
file: mtcnn-p.prototxt
pattern: 'dim: 12'
replacement: 'dim: 1280'
count: 1
model_optimizer_args:
- --framework=caffe
- --data_type=FP32
- --input_shape=[1,3,720,1280]
- --input=data
- --mean_values=data[127.5,127.5,127.5]
- --scale_values=data[128.0]
- --output=conv4-2,prob1
- --input_model=$dl_dir/mtcnn-p.caffemodel
- --input_proto=$dl_dir/mtcnn-p.prototxtI believe MO can ignore input dims at prototxt if I wanted to adapt this PR after changes proposed at #276. That shouldn't be a problem. |
This seems impractical. It means that the OpenCV team would have to rebuild their binaries after every update to the model configuration file(s). From past experience I can say the models tend to get updated close to the time of the release due to last-minute Model Optimizer bugfixes, so the chances of OpenCV shipping with an out-of-sync module are quite high.
I can see that, but it does nothing to address my concern. Also, it's not entirely true - when you're running Model Optimizer, you depend on all of its dependencies.
That's good, but I know at least one regex-based fix that cannot be skipped - the one in
They were merged recently. You might want to rebase.
I'm sure you can adapt to that specific change, but the problem is that you have to. Any new feature in the downloader/converter would require you (or someone else) to adapt the module to it. That's not sustainable. |
|
@IRDonch, Thanks! I agree that adding new module is a kind of overhead. There is another one option is to add it to regular OpenCV distribution. However the name of the package will be a bit different: from cv2.dnn.open_model_zoo import ...Or from cv2.dnn.zoo import ...This way we can use OMZ's topologies as optional ones and refactored https://github.com/opencv/opencv_extra/blob/master/testdata/dnn/download_models.py as a base. We can start with it and check it's stability first. |
Can we rely on downloader/converter API to minimize needs of changes in case of any new features in them? |
|
@vladimir-dudnik, Proposed changes use pure Python to download files by URL. The module depends only on |
810d387 to
85b2d34
Compare
Do not run MO for DLDT models. Create aliases for OpenVINO models by highest version.
Move topologies to cv2.open_model_zoo.topologies Enable cv2.open_model_zoo.TextRecognitionPipeline
Add DnnClassificationModel. Add some docs.
85b2d34 to
f7e8462
Compare
That's what I'm suggesting... |
|
@IRDonch, I'd like to propose the following solution: the package is still generated by OMZ structure ( Then, at |
|
On the other hand - there is a lightweight solution with just Python module which can only download and convert models without demos. I'll propose a separate PR with it. |
99230a9 to
c0ae5f3
Compare
mmphego
left a comment
There was a problem hiding this comment.
Some suggestions
Overral great PR can't wait for it to be merged.
Less is more!!!
| @@ -0,0 +1,108 @@ | |||
| # Open Model Zoo | |||
|
|
|||
| This is OpenCV module which let you have interactive Open Model Zoo in Python. | |||
There was a problem hiding this comment.
This could be reworded as:
| This is OpenCV module which let you have interactive Open Model Zoo in Python. | |
| This is OpenCV module which lets you interact Open Model Zoo in Python. |
| ``` | ||
|
|
||
|
|
||
| If you already have modules such opencv_contrib, you can combine it. In example, |
There was a problem hiding this comment.
| If you already have modules such opencv_contrib, you can combine it. In example, | |
| If you already have modules such `opencv_contrib`, you can combine it. In example, |
| topology = squeezenet1_0() | ||
| ``` | ||
|
|
||
| To infer network you can use as just paths downloaded files: |
There was a problem hiding this comment.
| To infer network you can use as just paths downloaded files: | |
| To infer a network you can just use paths to the downloaded files: |
| Some of networks may have pretty complicated pre- or post- processing procedures. | ||
| Another models can be combined to solve interesting problems. For these kind of | ||
| topologies you can use ready Algorithms. In example, to recognize text: |
There was a problem hiding this comment.
| Some of networks may have pretty complicated pre- or post- processing procedures. | |
| Another models can be combined to solve interesting problems. For these kind of | |
| topologies you can use ready Algorithms. In example, to recognize text: | |
| Some networks may have pretty complicated pre- or post-processing procedures. | |
| Other models can be combined to solve interesting problems. For this kind of | |
| topologies you can use ready Algorithms. This example shows how to recognize text: |
| if len(files) > 1: | ||
| config['model_url'], config['model_sha256'], config['model_path'] = getSource(files[1]) | ||
|
|
||
| s = ', '.join(['{"%s", "%s"}' % (key, value) for key, value in config.items()]) |
There was a problem hiding this comment.
No need to cast into a list.
| s = ', '.join(['{"%s", "%s"}' % (key, value) for key, value in config.items()]) | |
| s = ', '.join('{"%s", "%s"}' % (key, value) for key, value in config.items()) |
🐍 🐺 🦁 🙉 🐘 🐧 🐙 🦈 🐭 🐫 🐸 🐜 🐆 🦊 🐟 😼 🪲 🐳 🐨 🕷️ 🐉 🕊️ 🦉 🐰 🐔 🦀 🐝
WIP
1. Each topology is derived from OpenCV'sdnn::Model. Using downloaded modelsIENetworkcan be initialized separately.2. Each topology is just meta class which can be casted to
dnn::ModelorIENetworkOPENCV_OPEN_MODEL_ZOO_CACHE_DIRenvironment variable to change default caching location)related: opencv/opencv#14730
Pipelines
example with text recognition demo API: