Spaces:
Sleeping
Sleeping
oliver9523
commited on
Commit
·
21fd656
1
Parent(s):
0d798b8
Upload 23 files
Browse files- .gitattributes +2 -0
- LICENSE +201 -0
- README.md +227 -13
- deployment/Instance segmentation task/README.md +168 -0
- deployment/Instance segmentation task/model.json +37 -0
- deployment/Instance segmentation task/model/config.json +96 -0
- deployment/Instance segmentation task/model/model.bin +3 -0
- deployment/Instance segmentation task/model/model.xml +0 -0
- deployment/Instance segmentation task/python/LICENSE +201 -0
- deployment/Instance segmentation task/python/demo.py +132 -0
- deployment/Instance segmentation task/python/model_wrappers/__init__.py +19 -0
- deployment/Instance segmentation task/python/model_wrappers/__pycache__/__init__.cpython-38.pyc +0 -0
- deployment/Instance segmentation task/python/model_wrappers/__pycache__/openvino_models.cpython-38.pyc +0 -0
- deployment/Instance segmentation task/python/model_wrappers/openvino_models.py +194 -0
- deployment/Instance segmentation task/python/requirements.txt +4 -0
- deployment/project.json +67 -0
- eggsample1.png +3 -0
- eggsample2.png +3 -0
- example_code/demo.py +34 -0
- example_code/demo_notebook.ipynb +156 -0
- example_code/demo_ovms.ipynb +421 -0
- example_code/requirements-notebook.txt +6 -0
- example_code/requirements.txt +3 -0
- sample_image.jpg +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
eggsample1.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
eggsample2.png filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Apache License
|
2 |
+
Version 2.0, January 2004
|
3 |
+
http://www.apache.org/licenses/
|
4 |
+
|
5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6 |
+
|
7 |
+
1. Definitions.
|
8 |
+
|
9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
11 |
+
|
12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13 |
+
the copyright owner that is granting the License.
|
14 |
+
|
15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
16 |
+
other entities that control, are controlled by, or are under common
|
17 |
+
control with that entity. For the purposes of this definition,
|
18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
19 |
+
direction or management of such entity, whether by contract or
|
20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22 |
+
|
23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24 |
+
exercising permissions granted by this License.
|
25 |
+
|
26 |
+
"Source" form shall mean the preferred form for making modifications,
|
27 |
+
including but not limited to software source code, documentation
|
28 |
+
source, and configuration files.
|
29 |
+
|
30 |
+
"Object" form shall mean any form resulting from mechanical
|
31 |
+
transformation or translation of a Source form, including but
|
32 |
+
not limited to compiled object code, generated documentation,
|
33 |
+
and conversions to other media types.
|
34 |
+
|
35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
36 |
+
Object form, made available under the License, as indicated by a
|
37 |
+
copyright notice that is included in or attached to the work
|
38 |
+
(an example is provided in the Appendix below).
|
39 |
+
|
40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41 |
+
form, that is based on (or derived from) the Work and for which the
|
42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
44 |
+
of this License, Derivative Works shall not include works that remain
|
45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46 |
+
the Work and Derivative Works thereof.
|
47 |
+
|
48 |
+
"Contribution" shall mean any work of authorship, including
|
49 |
+
the original version of the Work and any modifications or additions
|
50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
54 |
+
means any form of electronic, verbal, or written communication sent
|
55 |
+
to the Licensor or its representatives, including but not limited to
|
56 |
+
communication on electronic mailing lists, source code control systems,
|
57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
59 |
+
excluding communication that is conspicuously marked or otherwise
|
60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
61 |
+
|
62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
64 |
+
subsequently incorporated within the Work.
|
65 |
+
|
66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
71 |
+
Work and such Derivative Works in Source or Object form.
|
72 |
+
|
73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76 |
+
(except as stated in this section) patent license to make, have made,
|
77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78 |
+
where such license applies only to those patent claims licensable
|
79 |
+
by such Contributor that are necessarily infringed by their
|
80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
82 |
+
institute patent litigation against any entity (including a
|
83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84 |
+
or a Contribution incorporated within the Work constitutes direct
|
85 |
+
or contributory patent infringement, then any patent licenses
|
86 |
+
granted to You under this License for that Work shall terminate
|
87 |
+
as of the date such litigation is filed.
|
88 |
+
|
89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
90 |
+
Work or Derivative Works thereof in any medium, with or without
|
91 |
+
modifications, and in Source or Object form, provided that You
|
92 |
+
meet the following conditions:
|
93 |
+
|
94 |
+
(a) You must give any other recipients of the Work or
|
95 |
+
Derivative Works a copy of this License; and
|
96 |
+
|
97 |
+
(b) You must cause any modified files to carry prominent notices
|
98 |
+
stating that You changed the files; and
|
99 |
+
|
100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
101 |
+
that You distribute, all copyright, patent, trademark, and
|
102 |
+
attribution notices from the Source form of the Work,
|
103 |
+
excluding those notices that do not pertain to any part of
|
104 |
+
the Derivative Works; and
|
105 |
+
|
106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107 |
+
distribution, then any Derivative Works that You distribute must
|
108 |
+
include a readable copy of the attribution notices contained
|
109 |
+
within such NOTICE file, excluding those notices that do not
|
110 |
+
pertain to any part of the Derivative Works, in at least one
|
111 |
+
of the following places: within a NOTICE text file distributed
|
112 |
+
as part of the Derivative Works; within the Source form or
|
113 |
+
documentation, if provided along with the Derivative Works; or,
|
114 |
+
within a display generated by the Derivative Works, if and
|
115 |
+
wherever such third-party notices normally appear. The contents
|
116 |
+
of the NOTICE file are for informational purposes only and
|
117 |
+
do not modify the License. You may add Your own attribution
|
118 |
+
notices within Derivative Works that You distribute, alongside
|
119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
120 |
+
that such additional attribution notices cannot be construed
|
121 |
+
as modifying the License.
|
122 |
+
|
123 |
+
You may add Your own copyright statement to Your modifications and
|
124 |
+
may provide additional or different license terms and conditions
|
125 |
+
for use, reproduction, or distribution of Your modifications, or
|
126 |
+
for any such Derivative Works as a whole, provided Your use,
|
127 |
+
reproduction, and distribution of the Work otherwise complies with
|
128 |
+
the conditions stated in this License.
|
129 |
+
|
130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
132 |
+
by You to the Licensor shall be under the terms and conditions of
|
133 |
+
this License, without any additional terms or conditions.
|
134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135 |
+
the terms of any separate license agreement you may have executed
|
136 |
+
with Licensor regarding such Contributions.
|
137 |
+
|
138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
140 |
+
except as required for reasonable and customary use in describing the
|
141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
142 |
+
|
143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144 |
+
agreed to in writing, Licensor provides the Work (and each
|
145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147 |
+
implied, including, without limitation, any warranties or conditions
|
148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150 |
+
appropriateness of using or redistributing the Work and assume any
|
151 |
+
risks associated with Your exercise of permissions under this License.
|
152 |
+
|
153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
154 |
+
whether in tort (including negligence), contract, or otherwise,
|
155 |
+
unless required by applicable law (such as deliberate and grossly
|
156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157 |
+
liable to You for damages, including any direct, indirect, special,
|
158 |
+
incidental, or consequential damages of any character arising as a
|
159 |
+
result of this License or out of the use or inability to use the
|
160 |
+
Work (including but not limited to damages for loss of goodwill,
|
161 |
+
work stoppage, computer failure or malfunction, or any and all
|
162 |
+
other commercial damages or losses), even if such Contributor
|
163 |
+
has been advised of the possibility of such damages.
|
164 |
+
|
165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168 |
+
or other liability obligations and/or rights consistent with this
|
169 |
+
License. However, in accepting such obligations, You may act only
|
170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171 |
+
of any other Contributor, and only if You agree to indemnify,
|
172 |
+
defend, and hold each Contributor harmless for any liability
|
173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
174 |
+
of your accepting any such warranty or additional liability.
|
175 |
+
|
176 |
+
END OF TERMS AND CONDITIONS
|
177 |
+
|
178 |
+
APPENDIX: How to apply the Apache License to your work.
|
179 |
+
|
180 |
+
To apply the Apache License to your work, attach the following
|
181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182 |
+
replaced with your own identifying information. (Don't include
|
183 |
+
the brackets!) The text should be enclosed in the appropriate
|
184 |
+
comment syntax for the file format. We also recommend that a
|
185 |
+
file or class name and description of purpose be included on the
|
186 |
+
same "printed page" as the copyright notice for easier
|
187 |
+
identification within third-party archives.
|
188 |
+
|
189 |
+
Copyright (C) 2018-2021 Intel Corporation
|
190 |
+
|
191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192 |
+
you may not use this file except in compliance with the License.
|
193 |
+
You may obtain a copy of the License at
|
194 |
+
|
195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
196 |
+
|
197 |
+
Unless required by applicable law or agreed to in writing, software
|
198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200 |
+
See the License for the specific language governing permissions and
|
201 |
+
limitations under the License.
|
README.md
CHANGED
@@ -1,13 +1,227 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Code deployment
|
2 |
+
## Table of contents
|
3 |
+
- [Introduction](#introduction)
|
4 |
+
- [Prerequisites](#prerequisites)
|
5 |
+
- [Installation](#Installation)
|
6 |
+
- [Usage](#usage)
|
7 |
+
- [Troubleshooting](#troubleshooting)
|
8 |
+
- [Package contents](#package-contents)
|
9 |
+
|
10 |
+
|
11 |
+
## Introduction
|
12 |
+
|
13 |
+
This code deployment .zip archive contains:
|
14 |
+
|
15 |
+
1. Inference model(s) for your Intel® Geti™ project.
|
16 |
+
|
17 |
+
2. A sample image or video frame, exported from your project.
|
18 |
+
|
19 |
+
3. A very simple code example to get and visualize the result of inference for your
|
20 |
+
project, on the sample image.
|
21 |
+
|
22 |
+
4. Jupyter notebooks with instructions and code for running inference for your project,
|
23 |
+
either locally or via the OpenVINO Model Server (OVMS).
|
24 |
+
|
25 |
+
The deployment holds one model for each task in your project, so if for example
|
26 |
+
you created a deployment for a `Detection -> Classification` project, it will consist of
|
27 |
+
both a detection, and a classification model. The Intel® Geti™ SDK is used to run
|
28 |
+
inference for all models in the project's task chain.
|
29 |
+
|
30 |
+
This README describes the steps required to get the code sample up and running on your
|
31 |
+
machine.
|
32 |
+
|
33 |
+
## Prerequisites
|
34 |
+
|
35 |
+
- [Python 3.8](https://www.python.org/downloads/)
|
36 |
+
- [*Optional, only for OVMS notebook*] [Docker](https://docs.docker.com/get-docker/)
|
37 |
+
|
38 |
+
## Installation
|
39 |
+
|
40 |
+
1. Install [prerequisites](#prerequisites). You may also need to
|
41 |
+
[install pip](https://pip.pypa.io/en/stable/installation/). For example, on Ubuntu
|
42 |
+
execute the following command to install Python and pip:
|
43 |
+
|
44 |
+
```
|
45 |
+
sudo apt install python3-dev python3-pip
|
46 |
+
```
|
47 |
+
If you already have installed pip before, make sure it is up to date by doing:
|
48 |
+
|
49 |
+
```
|
50 |
+
pip install --upgrade pip
|
51 |
+
```
|
52 |
+
|
53 |
+
2. Create a clean virtual environment: <a name="virtual-env-creation"></a>
|
54 |
+
|
55 |
+
One of the possible ways for creating a virtual environment is to use `virtualenv`:
|
56 |
+
|
57 |
+
```
|
58 |
+
python -m pip install virtualenv
|
59 |
+
python -m virtualenv <directory_for_environment>
|
60 |
+
```
|
61 |
+
|
62 |
+
Before starting to work inside the virtual environment, it should be activated:
|
63 |
+
|
64 |
+
On Linux and macOS:
|
65 |
+
|
66 |
+
```
|
67 |
+
source <directory_for_environment>/bin/activate
|
68 |
+
```
|
69 |
+
|
70 |
+
On Windows:
|
71 |
+
|
72 |
+
```
|
73 |
+
.\<directory_for_environment>\Scripts\activate
|
74 |
+
```
|
75 |
+
|
76 |
+
Please make sure that the environment contains
|
77 |
+
[wheel](https://pypi.org/project/wheel/) by calling the following command:
|
78 |
+
|
79 |
+
```
|
80 |
+
python -m pip install wheel
|
81 |
+
```
|
82 |
+
|
83 |
+
> **NOTE**: On Linux and macOS, you may need to type `python3` instead of `python`.
|
84 |
+
|
85 |
+
3. In your terminal, navigate to the `example_code` directory in the code deployment
|
86 |
+
package.
|
87 |
+
|
88 |
+
4. Install requirements in the environment:
|
89 |
+
|
90 |
+
```
|
91 |
+
python -m pip install -r requirements.txt
|
92 |
+
```
|
93 |
+
|
94 |
+
5. (Optional) Install the requirements for running the `demo_notebook.ipynb` or
|
95 |
+
`demo_ovms.ipynb` Juypter notebooks:
|
96 |
+
|
97 |
+
```
|
98 |
+
python -m pip install -r requirements-notebook.txt
|
99 |
+
```
|
100 |
+
|
101 |
+
## Usage
|
102 |
+
### Local inference
|
103 |
+
Both `demo.py` script and the `demo_notebook.ipynb` notebook contain a code sample for:
|
104 |
+
|
105 |
+
1. Loading the code deployment (and the models it contains) into memory.
|
106 |
+
|
107 |
+
2. Loading the `sample_image.jpg`, which is a random image taken from the project you
|
108 |
+
deployed.
|
109 |
+
|
110 |
+
3. Running inference on the sample image.
|
111 |
+
|
112 |
+
4. Visualizing the inference results.
|
113 |
+
|
114 |
+
### Inference with OpenVINO Model Server
|
115 |
+
The additional demo notebook `demo_ovms.ipynb` shows how to set up and run an OpenVINO
|
116 |
+
Model Server for your deployment, and make inference requests to it. The notebook
|
117 |
+
contains instructions and code to:
|
118 |
+
|
119 |
+
1. Generate a configuration file for OVMS.
|
120 |
+
|
121 |
+
2. Launch an OVMS docker container with the proper configuration.
|
122 |
+
|
123 |
+
3. Load the image `sample_image.jpg`, as an example image to run inference on.
|
124 |
+
|
125 |
+
4. Make an inference request to OVMS.
|
126 |
+
|
127 |
+
5. Visualize the inference results.
|
128 |
+
|
129 |
+
### Running the demo script
|
130 |
+
|
131 |
+
In your terminal:
|
132 |
+
|
133 |
+
1. Make sure the virtual environment created [above](#virtual-env-creation) is activated.
|
134 |
+
|
135 |
+
2. Make sure you are in the `example_code` directory in your terminal.
|
136 |
+
|
137 |
+
3. Run the demo using:
|
138 |
+
|
139 |
+
```
|
140 |
+
python demo.py
|
141 |
+
```
|
142 |
+
|
143 |
+
The script will run inference on the `sample_image.jpg`. A window will pop up that
|
144 |
+
displays the image, and the results of the inference visualized on top of it.
|
145 |
+
|
146 |
+
### Running the demo notebooks
|
147 |
+
|
148 |
+
In your terminal:
|
149 |
+
|
150 |
+
1. Make sure the virtual environment created [above](#virtual-env-creation) is activated.
|
151 |
+
|
152 |
+
2. Make sure you are in the `example_code` directory in your terminal.
|
153 |
+
|
154 |
+
3. Start JupyterLab using:
|
155 |
+
|
156 |
+
```
|
157 |
+
jupyter lab
|
158 |
+
```
|
159 |
+
|
160 |
+
4. This should launch your web browser and take you to the main page of JupyterLab.
|
161 |
+
|
162 |
+
Inside JuypterLab:
|
163 |
+
|
164 |
+
5. In the sidebar of the JupyterLab interface, double-click on `demo_notebook.ipynb` or
|
165 |
+
`demo_ovms.ipynb` to open one of the notebooks.
|
166 |
+
|
167 |
+
6. Execute the notebook cell by cell to view the inference results.
|
168 |
+
|
169 |
+
|
170 |
+
> **NOTE** The `demo_notebook.ipynb` is a great way to explore the `AnnotationScene`
|
171 |
+
> object that is returned by the inference. The demo code only has very basic
|
172 |
+
> visualization functionality, which may not be sufficient for all use case. For
|
173 |
+
> example if your project contains many labels, it may not be able to visualize the
|
174 |
+
> results very well. In that case, you should build your own visualization logic
|
175 |
+
> based on the `AnnotationScene` returned by the `deployment.infer()` method.
|
176 |
+
|
177 |
+
## Troubleshooting
|
178 |
+
|
179 |
+
1. If you have access to the Internet through a proxy server only, please use pip
|
180 |
+
with a proxy call as demonstrated by the command below:
|
181 |
+
|
182 |
+
```
|
183 |
+
python -m pip install --proxy http://<usr_name>:<password>@<proxyserver_name>:<port#> <pkg_name>
|
184 |
+
```
|
185 |
+
|
186 |
+
2. If you use Anaconda as environment manager, please consider that OpenVINO has
|
187 |
+
limited [Conda support](https://docs.openvino.ai/2021.4/openvino_docs_install_guides_installing_openvino_conda.html).
|
188 |
+
It is still possible to use `conda` to create and activate your python environment,
|
189 |
+
but in that case please use only `pip` (rather than `conda`) as a package manager
|
190 |
+
for installing packages in your environment.
|
191 |
+
|
192 |
+
3. If you have problems when you try to use the `pip install` command, please update
|
193 |
+
pip version as per the following command:
|
194 |
+
```
|
195 |
+
python -m pip install --upgrade pip
|
196 |
+
```
|
197 |
+
|
198 |
+
## Package contents
|
199 |
+
|
200 |
+
The code deployment files are structured as follows:
|
201 |
+
|
202 |
+
- deployment
|
203 |
+
- `project.json`
|
204 |
+
- "<title of task 1>"
|
205 |
+
- model
|
206 |
+
- `model.xml`
|
207 |
+
- `model.bin`
|
208 |
+
- `config.json`
|
209 |
+
- python
|
210 |
+
- model_wrappers
|
211 |
+
- `__init__.py`
|
212 |
+
- model_wrappers required to run demo
|
213 |
+
- `README.md`
|
214 |
+
- `LICENSE`
|
215 |
+
- `demo.py`
|
216 |
+
- `requirements.txt`
|
217 |
+
- "<title of task 2>" (Optional)
|
218 |
+
- ...
|
219 |
+
- example_code
|
220 |
+
- `demo.py`
|
221 |
+
- `demo_notebook.ipynb`
|
222 |
+
- `demo_ovms.ipynb`
|
223 |
+
- `README.md`
|
224 |
+
- `requirements.txt`
|
225 |
+
- `requirements-notebook.txt`
|
226 |
+
- `sample_image.jpg`
|
227 |
+
- `LICENSE`
|
deployment/Instance segmentation task/README.md
ADDED
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Exportable code
|
2 |
+
|
3 |
+
Exportable code is a .zip archive that contains simple demo to get and visualize result of model inference.
|
4 |
+
|
5 |
+
## Structure of generated zip
|
6 |
+
|
7 |
+
- model
|
8 |
+
- `model.xml`
|
9 |
+
- `model.bin`
|
10 |
+
- `config.json`
|
11 |
+
- python
|
12 |
+
- model_wrappers (Optional)
|
13 |
+
- `__init__.py`
|
14 |
+
- model_wrappers required to run demo
|
15 |
+
- `README.md`
|
16 |
+
- `LICENSE`
|
17 |
+
- `demo.py`
|
18 |
+
- `requirements.txt`
|
19 |
+
|
20 |
+
> **NOTE**: Zip archive contains model_wrappers when [ModelAPI](https://github.com/openvinotoolkit/open_model_zoo/tree/master/demos/common/python/openvino/model_zoo/model_api) has no appropriate standard model wrapper for the model.
|
21 |
+
|
22 |
+
## Prerequisites
|
23 |
+
|
24 |
+
- [Python 3.8](https://www.python.org/downloads/)
|
25 |
+
- [Git](https://git-scm.com/)
|
26 |
+
|
27 |
+
## Install requirements to run demo
|
28 |
+
|
29 |
+
1. Install [prerequisites](#prerequisites). You may also need to [install pip](https://pip.pypa.io/en/stable/installation/). For example, on Ubuntu execute the following command to get pip installed:
|
30 |
+
|
31 |
+
```bash
|
32 |
+
sudo apt install python3-pip
|
33 |
+
```
|
34 |
+
|
35 |
+
1. Create clean virtual environment:
|
36 |
+
|
37 |
+
One of the possible ways for creating a virtual environment is to use `virtualenv`:
|
38 |
+
|
39 |
+
```bash
|
40 |
+
python -m pip install virtualenv
|
41 |
+
python -m virtualenv <directory_for_environment>
|
42 |
+
```
|
43 |
+
|
44 |
+
Before starting to work inside virtual environment, it should be activated:
|
45 |
+
|
46 |
+
On Linux and macOS:
|
47 |
+
|
48 |
+
```bash
|
49 |
+
source <directory_for_environment>/bin/activate
|
50 |
+
```
|
51 |
+
|
52 |
+
On Windows:
|
53 |
+
|
54 |
+
```bash
|
55 |
+
.\<directory_for_environment>\Scripts\activate
|
56 |
+
```
|
57 |
+
|
58 |
+
Please make sure that the environment contains [wheel](https://pypi.org/project/wheel/) by calling the following command:
|
59 |
+
|
60 |
+
```bash
|
61 |
+
python -m pip install wheel
|
62 |
+
```
|
63 |
+
|
64 |
+
> **NOTE**: On Linux and macOS, you may need to type `python3` instead of `python`.
|
65 |
+
|
66 |
+
1. Install requirements in the environment:
|
67 |
+
|
68 |
+
```bash
|
69 |
+
python -m pip install -r requirements.txt
|
70 |
+
```
|
71 |
+
|
72 |
+
1. Add `model_wrappers` package to PYTHONPATH:
|
73 |
+
|
74 |
+
On Linux and macOS:
|
75 |
+
|
76 |
+
```bash
|
77 |
+
export PYTHONPATH=$PYTHONPATH:/path/to/model_wrappers
|
78 |
+
```
|
79 |
+
|
80 |
+
On Windows:
|
81 |
+
|
82 |
+
```bash
|
83 |
+
set PYTHONPATH=%PYTHONPATH%;/path/to/model_wrappers
|
84 |
+
```
|
85 |
+
|
86 |
+
## Usecase
|
87 |
+
|
88 |
+
1. Running the `demo.py` application with the `-h` option yields the following usage message:
|
89 |
+
|
90 |
+
```bash
|
91 |
+
usage: demo.py [-h] -i INPUT -m MODELS [MODELS ...] [-it {sync,async}] [-l] [--no_show] [-d {CPU,GPU}] [--output OUTPUT]
|
92 |
+
|
93 |
+
Options:
|
94 |
+
-h, --help Show this help message and exit.
|
95 |
+
-i INPUT, --input INPUT
|
96 |
+
Required. An input to process. The input must be a single image, a folder of images, video file or camera id.
|
97 |
+
-m MODELS [MODELS ...], --models MODELS [MODELS ...]
|
98 |
+
Required. Path to directory with trained model and configuration file. If you provide several models you will start the task chain pipeline with the provided models in the order in
|
99 |
+
which they were specified.
|
100 |
+
-it {sync,async}, --inference_type {sync,async}
|
101 |
+
Optional. Type of inference for single model.
|
102 |
+
-l, --loop Optional. Enable reading the input in a loop.
|
103 |
+
--no_show Optional. Disables showing inference results on UI.
|
104 |
+
-d {CPU,GPU}, --device {CPU,GPU}
|
105 |
+
Optional. Device to infer the model.
|
106 |
+
--output OUTPUT Optional. Output path to save input data with predictions.
|
107 |
+
```
|
108 |
+
|
109 |
+
2. As a `model`, you can use path to model directory from generated zip. You can pass as `input` a single image, a folder of images, a video file, or a web camera id. So you can use the following command to do inference with a pre-trained model:
|
110 |
+
|
111 |
+
```bash
|
112 |
+
python3 demo.py \
|
113 |
+
-i <path_to_video>/inputVideo.mp4 \
|
114 |
+
-m <path_to_model_directory>
|
115 |
+
```
|
116 |
+
|
117 |
+
You can press `Q` to stop inference during demo running.
|
118 |
+
|
119 |
+
> **NOTE**: If you provide a single image as input, the demo processes and renders it quickly, then exits. To continuously
|
120 |
+
> visualize inference results on the screen, apply the `--loop` option, which enforces processing a single image in a loop.
|
121 |
+
> In this case, you can stop the demo by pressing `Q` button or killing the process in the terminal (`Ctrl+C` for Linux).
|
122 |
+
>
|
123 |
+
> **NOTE**: Default configuration contains info about pre- and post processing for inference and is guaranteed to be correct.
|
124 |
+
> Also you can change `config.json` that specifies the confidence threshold and color for each class visualization, but any
|
125 |
+
> changes should be made with caution.
|
126 |
+
|
127 |
+
3. To save inferenced results with predictions on it, you can specify the folder path, using `--output`.
|
128 |
+
It works for images, videos, image folders and web cameras. To prevent issues, do not specify it together with a `--loop` parameter.
|
129 |
+
|
130 |
+
```bash
|
131 |
+
python3 demo.py \
|
132 |
+
--input <path_to_image>/inputImage.jpg \
|
133 |
+
--models ../model \
|
134 |
+
--output resulted_images
|
135 |
+
```
|
136 |
+
|
137 |
+
4. To run a demo on a web camera, you need to know its ID.
|
138 |
+
You can check a list of camera devices by running this command line on Linux system:
|
139 |
+
|
140 |
+
```bash
|
141 |
+
sudo apt-get install v4l-utils
|
142 |
+
v4l2-ctl --list-devices
|
143 |
+
```
|
144 |
+
|
145 |
+
The output will look like this:
|
146 |
+
|
147 |
+
```bash
|
148 |
+
Integrated Camera (usb-0000:00:1a.0-1.6):
|
149 |
+
/dev/video0
|
150 |
+
```
|
151 |
+
|
152 |
+
After that, you can use this `/dev/video0` as a camera ID for `--input`.
|
153 |
+
|
154 |
+
## Troubleshooting
|
155 |
+
|
156 |
+
1. If you have access to the Internet through the proxy server only, please use pip with proxy call as demonstrated by command below:
|
157 |
+
|
158 |
+
```bash
|
159 |
+
python -m pip install --proxy http://<usr_name>:<password>@<proxyserver_name>:<port#> <pkg_name>
|
160 |
+
```
|
161 |
+
|
162 |
+
1. If you use Anaconda environment, you should consider that OpenVINO has limited [Conda support](https://docs.openvino.ai/2021.4/openvino_docs_install_guides_installing_openvino_conda.html) for Python 3.6 and 3.7 versions only. But the demo package requires python 3.8. So please use other tools to create the environment (like `venv` or `virtualenv`) and use `pip` as a package manager.
|
163 |
+
|
164 |
+
1. If you have problems when you try to use `pip install` command, please update pip version by following command:
|
165 |
+
|
166 |
+
```bash
|
167 |
+
python -m pip install --upgrade pip
|
168 |
+
```
|
deployment/Instance segmentation task/model.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"id": "6483248259c02bd70e8df1f4",
|
3 |
+
"name": "MaskRCNN-ResNet50 OpenVINO INT8",
|
4 |
+
"version": 1,
|
5 |
+
"creation_date": "2023-06-09T13:09:22.699000+00:00",
|
6 |
+
"model_format": "OpenVINO",
|
7 |
+
"precision": [
|
8 |
+
"INT8"
|
9 |
+
],
|
10 |
+
"has_xai_head": false,
|
11 |
+
"target_device": "CPU",
|
12 |
+
"target_device_type": null,
|
13 |
+
"performance": {
|
14 |
+
"score": 0.9397590361445782
|
15 |
+
},
|
16 |
+
"size": 247759204,
|
17 |
+
"latency": 0,
|
18 |
+
"fps_throughput": 0,
|
19 |
+
"optimization_type": "NNCF",
|
20 |
+
"optimization_objectives": {},
|
21 |
+
"model_status": "SUCCESS",
|
22 |
+
"configurations": [
|
23 |
+
{
|
24 |
+
"name": "max_accuracy_drop",
|
25 |
+
"value": 0.01
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"name": "filter_pruning",
|
29 |
+
"value": false
|
30 |
+
}
|
31 |
+
],
|
32 |
+
"previous_revision_id": "6483248259c02bd70e8df1f5",
|
33 |
+
"previous_trained_revision_id": "648311e459c02bd70e8db073",
|
34 |
+
"optimization_methods": [
|
35 |
+
"QUANTIZATION"
|
36 |
+
]
|
37 |
+
}
|
deployment/Instance segmentation task/model/config.json
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"type_of_model": "OTX_MaskRCNN",
|
3 |
+
"converter_type": "INSTANCE_SEGMENTATION",
|
4 |
+
"model_parameters": {
|
5 |
+
"result_based_confidence_threshold": true,
|
6 |
+
"confidence_threshold": 0.8500000238418579,
|
7 |
+
"use_ellipse_shapes": false,
|
8 |
+
"resize_type": "fit_to_window",
|
9 |
+
"labels": {
|
10 |
+
"label_tree": {
|
11 |
+
"type": "tree",
|
12 |
+
"directed": true,
|
13 |
+
"nodes": [],
|
14 |
+
"edges": []
|
15 |
+
},
|
16 |
+
"label_groups": [
|
17 |
+
{
|
18 |
+
"_id": "6483114c18fb8c1c529bd153",
|
19 |
+
"name": "Instance segmentation labels",
|
20 |
+
"label_ids": [
|
21 |
+
"6483114c18fb8c1c529bd150"
|
22 |
+
],
|
23 |
+
"relation_type": "EXCLUSIVE"
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"_id": "6483114c18fb8c1c529bd155",
|
27 |
+
"name": "Empty",
|
28 |
+
"label_ids": [
|
29 |
+
"6483114c18fb8c1c529bd154"
|
30 |
+
],
|
31 |
+
"relation_type": "EMPTY_LABEL"
|
32 |
+
}
|
33 |
+
],
|
34 |
+
"all_labels": {
|
35 |
+
"6483114c18fb8c1c529bd150": {
|
36 |
+
"_id": "6483114c18fb8c1c529bd150",
|
37 |
+
"name": "egg",
|
38 |
+
"color": {
|
39 |
+
"red": 201,
|
40 |
+
"green": 230,
|
41 |
+
"blue": 73,
|
42 |
+
"alpha": 255
|
43 |
+
},
|
44 |
+
"hotkey": "",
|
45 |
+
"domain": "INSTANCE_SEGMENTATION",
|
46 |
+
"creation_date": "2023-06-09T11:47:24.779000",
|
47 |
+
"is_empty": false,
|
48 |
+
"is_anomalous": false
|
49 |
+
},
|
50 |
+
"6483114c18fb8c1c529bd154": {
|
51 |
+
"_id": "6483114c18fb8c1c529bd154",
|
52 |
+
"name": "Empty",
|
53 |
+
"color": {
|
54 |
+
"red": 0,
|
55 |
+
"green": 0,
|
56 |
+
"blue": 0,
|
57 |
+
"alpha": 255
|
58 |
+
},
|
59 |
+
"hotkey": "",
|
60 |
+
"domain": "INSTANCE_SEGMENTATION",
|
61 |
+
"creation_date": "2023-06-09T11:47:24.781000",
|
62 |
+
"is_empty": true,
|
63 |
+
"is_anomalous": false
|
64 |
+
}
|
65 |
+
}
|
66 |
+
}
|
67 |
+
},
|
68 |
+
"tiling_parameters": {
|
69 |
+
"visible_in_ui": true,
|
70 |
+
"type": "PARAMETER_GROUP",
|
71 |
+
"enable_tiling": false,
|
72 |
+
"enable_tile_classifier": false,
|
73 |
+
"enable_adaptive_params": true,
|
74 |
+
"tile_size": 400,
|
75 |
+
"tile_overlap": 0.2,
|
76 |
+
"tile_max_number": 1500,
|
77 |
+
"tile_ir_scale_factor": 2.0,
|
78 |
+
"tile_sampling_ratio": 1.0,
|
79 |
+
"object_tile_ratio": 0.03,
|
80 |
+
"header": "Tiling Parameters",
|
81 |
+
"description": "Tiling Parameters",
|
82 |
+
"_ParameterGroup__metadata_overrides": {},
|
83 |
+
"groups": [],
|
84 |
+
"parameters": [
|
85 |
+
"enable_adaptive_params",
|
86 |
+
"enable_tile_classifier",
|
87 |
+
"enable_tiling",
|
88 |
+
"object_tile_ratio",
|
89 |
+
"tile_ir_scale_factor",
|
90 |
+
"tile_max_number",
|
91 |
+
"tile_overlap",
|
92 |
+
"tile_sampling_ratio",
|
93 |
+
"tile_size"
|
94 |
+
]
|
95 |
+
}
|
96 |
+
}
|
deployment/Instance segmentation task/model/model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3128a90931c4b7b51ec0218fe952bac97d13b1763fc1f9cef1ecb620a22412e3
|
3 |
+
size 56328440
|
deployment/Instance segmentation task/model/model.xml
ADDED
The diff for this file is too large to render.
See raw diff
|
|
deployment/Instance segmentation task/python/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Apache License
|
2 |
+
Version 2.0, January 2004
|
3 |
+
http://www.apache.org/licenses/
|
4 |
+
|
5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6 |
+
|
7 |
+
1. Definitions.
|
8 |
+
|
9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
11 |
+
|
12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13 |
+
the copyright owner that is granting the License.
|
14 |
+
|
15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
16 |
+
other entities that control, are controlled by, or are under common
|
17 |
+
control with that entity. For the purposes of this definition,
|
18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
19 |
+
direction or management of such entity, whether by contract or
|
20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22 |
+
|
23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24 |
+
exercising permissions granted by this License.
|
25 |
+
|
26 |
+
"Source" form shall mean the preferred form for making modifications,
|
27 |
+
including but not limited to software source code, documentation
|
28 |
+
source, and configuration files.
|
29 |
+
|
30 |
+
"Object" form shall mean any form resulting from mechanical
|
31 |
+
transformation or translation of a Source form, including but
|
32 |
+
not limited to compiled object code, generated documentation,
|
33 |
+
and conversions to other media types.
|
34 |
+
|
35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
36 |
+
Object form, made available under the License, as indicated by a
|
37 |
+
copyright notice that is included in or attached to the work
|
38 |
+
(an example is provided in the Appendix below).
|
39 |
+
|
40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41 |
+
form, that is based on (or derived from) the Work and for which the
|
42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
44 |
+
of this License, Derivative Works shall not include works that remain
|
45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46 |
+
the Work and Derivative Works thereof.
|
47 |
+
|
48 |
+
"Contribution" shall mean any work of authorship, including
|
49 |
+
the original version of the Work and any modifications or additions
|
50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
54 |
+
means any form of electronic, verbal, or written communication sent
|
55 |
+
to the Licensor or its representatives, including but not limited to
|
56 |
+
communication on electronic mailing lists, source code control systems,
|
57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
59 |
+
excluding communication that is conspicuously marked or otherwise
|
60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
61 |
+
|
62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
64 |
+
subsequently incorporated within the Work.
|
65 |
+
|
66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
71 |
+
Work and such Derivative Works in Source or Object form.
|
72 |
+
|
73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76 |
+
(except as stated in this section) patent license to make, have made,
|
77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78 |
+
where such license applies only to those patent claims licensable
|
79 |
+
by such Contributor that are necessarily infringed by their
|
80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
82 |
+
institute patent litigation against any entity (including a
|
83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84 |
+
or a Contribution incorporated within the Work constitutes direct
|
85 |
+
or contributory patent infringement, then any patent licenses
|
86 |
+
granted to You under this License for that Work shall terminate
|
87 |
+
as of the date such litigation is filed.
|
88 |
+
|
89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
90 |
+
Work or Derivative Works thereof in any medium, with or without
|
91 |
+
modifications, and in Source or Object form, provided that You
|
92 |
+
meet the following conditions:
|
93 |
+
|
94 |
+
(a) You must give any other recipients of the Work or
|
95 |
+
Derivative Works a copy of this License; and
|
96 |
+
|
97 |
+
(b) You must cause any modified files to carry prominent notices
|
98 |
+
stating that You changed the files; and
|
99 |
+
|
100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
101 |
+
that You distribute, all copyright, patent, trademark, and
|
102 |
+
attribution notices from the Source form of the Work,
|
103 |
+
excluding those notices that do not pertain to any part of
|
104 |
+
the Derivative Works; and
|
105 |
+
|
106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107 |
+
distribution, then any Derivative Works that You distribute must
|
108 |
+
include a readable copy of the attribution notices contained
|
109 |
+
within such NOTICE file, excluding those notices that do not
|
110 |
+
pertain to any part of the Derivative Works, in at least one
|
111 |
+
of the following places: within a NOTICE text file distributed
|
112 |
+
as part of the Derivative Works; within the Source form or
|
113 |
+
documentation, if provided along with the Derivative Works; or,
|
114 |
+
within a display generated by the Derivative Works, if and
|
115 |
+
wherever such third-party notices normally appear. The contents
|
116 |
+
of the NOTICE file are for informational purposes only and
|
117 |
+
do not modify the License. You may add Your own attribution
|
118 |
+
notices within Derivative Works that You distribute, alongside
|
119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
120 |
+
that such additional attribution notices cannot be construed
|
121 |
+
as modifying the License.
|
122 |
+
|
123 |
+
You may add Your own copyright statement to Your modifications and
|
124 |
+
may provide additional or different license terms and conditions
|
125 |
+
for use, reproduction, or distribution of Your modifications, or
|
126 |
+
for any such Derivative Works as a whole, provided Your use,
|
127 |
+
reproduction, and distribution of the Work otherwise complies with
|
128 |
+
the conditions stated in this License.
|
129 |
+
|
130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
132 |
+
by You to the Licensor shall be under the terms and conditions of
|
133 |
+
this License, without any additional terms or conditions.
|
134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135 |
+
the terms of any separate license agreement you may have executed
|
136 |
+
with Licensor regarding such Contributions.
|
137 |
+
|
138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
140 |
+
except as required for reasonable and customary use in describing the
|
141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
142 |
+
|
143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144 |
+
agreed to in writing, Licensor provides the Work (and each
|
145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147 |
+
implied, including, without limitation, any warranties or conditions
|
148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150 |
+
appropriateness of using or redistributing the Work and assume any
|
151 |
+
risks associated with Your exercise of permissions under this License.
|
152 |
+
|
153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
154 |
+
whether in tort (including negligence), contract, or otherwise,
|
155 |
+
unless required by applicable law (such as deliberate and grossly
|
156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157 |
+
liable to You for damages, including any direct, indirect, special,
|
158 |
+
incidental, or consequential damages of any character arising as a
|
159 |
+
result of this License or out of the use or inability to use the
|
160 |
+
Work (including but not limited to damages for loss of goodwill,
|
161 |
+
work stoppage, computer failure or malfunction, or any and all
|
162 |
+
other commercial damages or losses), even if such Contributor
|
163 |
+
has been advised of the possibility of such damages.
|
164 |
+
|
165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168 |
+
or other liability obligations and/or rights consistent with this
|
169 |
+
License. However, in accepting such obligations, You may act only
|
170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171 |
+
of any other Contributor, and only if You agree to indemnify,
|
172 |
+
defend, and hold each Contributor harmless for any liability
|
173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
174 |
+
of your accepting any such warranty or additional liability.
|
175 |
+
|
176 |
+
END OF TERMS AND CONDITIONS
|
177 |
+
|
178 |
+
APPENDIX: How to apply the Apache License to your work.
|
179 |
+
|
180 |
+
To apply the Apache License to your work, attach the following
|
181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182 |
+
replaced with your own identifying information. (Don't include
|
183 |
+
the brackets!) The text should be enclosed in the appropriate
|
184 |
+
comment syntax for the file format. We also recommend that a
|
185 |
+
file or class name and description of purpose be included on the
|
186 |
+
same "printed page" as the copyright notice for easier
|
187 |
+
identification within third-party archives.
|
188 |
+
|
189 |
+
Copyright (C) 2018-2021 Intel Corporation
|
190 |
+
|
191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192 |
+
you may not use this file except in compliance with the License.
|
193 |
+
You may obtain a copy of the License at
|
194 |
+
|
195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
196 |
+
|
197 |
+
Unless required by applicable law or agreed to in writing, software
|
198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200 |
+
See the License for the specific language governing permissions and
|
201 |
+
limitations under the License.
|
deployment/Instance segmentation task/python/demo.py
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Demo based on ModelAPI."""
|
2 |
+
# Copyright (C) 2021-2022 Intel Corporation
|
3 |
+
# SPDX-License-Identifier: Apache-2.0
|
4 |
+
#
|
5 |
+
|
6 |
+
import os
|
7 |
+
import sys
|
8 |
+
from argparse import SUPPRESS, ArgumentParser
|
9 |
+
from pathlib import Path
|
10 |
+
|
11 |
+
os.environ["FEATURE_FLAGS_OTX_ACTION_TASKS"] = "1"
|
12 |
+
|
13 |
+
# pylint: disable=no-name-in-module, import-error
|
14 |
+
from otx.api.usecases.exportable_code.demo.demo_package import (
|
15 |
+
AsyncExecutor,
|
16 |
+
ChainExecutor,
|
17 |
+
ModelContainer,
|
18 |
+
SyncExecutor,
|
19 |
+
create_visualizer,
|
20 |
+
)
|
21 |
+
|
22 |
+
|
23 |
+
def build_argparser():
|
24 |
+
"""Parses command line arguments."""
|
25 |
+
parser = ArgumentParser(add_help=False)
|
26 |
+
args = parser.add_argument_group("Options")
|
27 |
+
args.add_argument(
|
28 |
+
"-h",
|
29 |
+
"--help",
|
30 |
+
action="help",
|
31 |
+
default=SUPPRESS,
|
32 |
+
help="Show this help message and exit.",
|
33 |
+
)
|
34 |
+
args.add_argument(
|
35 |
+
"-i",
|
36 |
+
"--input",
|
37 |
+
required=True,
|
38 |
+
help="Required. An input to process. The input must be a single image, "
|
39 |
+
"a folder of images, video file or camera id.",
|
40 |
+
)
|
41 |
+
args.add_argument(
|
42 |
+
"-m",
|
43 |
+
"--models",
|
44 |
+
help="Required. Path to directory with trained model and configuration file. "
|
45 |
+
"If you provide several models you will start the task chain pipeline with "
|
46 |
+
"the provided models in the order in which they were specified.",
|
47 |
+
nargs="+",
|
48 |
+
required=True,
|
49 |
+
type=Path,
|
50 |
+
)
|
51 |
+
args.add_argument(
|
52 |
+
"-it",
|
53 |
+
"--inference_type",
|
54 |
+
help="Optional. Type of inference for single model.",
|
55 |
+
choices=["sync", "async"],
|
56 |
+
default="sync",
|
57 |
+
type=str,
|
58 |
+
)
|
59 |
+
args.add_argument(
|
60 |
+
"-l",
|
61 |
+
"--loop",
|
62 |
+
help="Optional. Enable reading the input in a loop.",
|
63 |
+
default=False,
|
64 |
+
action="store_true",
|
65 |
+
)
|
66 |
+
args.add_argument(
|
67 |
+
"--no_show",
|
68 |
+
help="Optional. Disables showing inference results on UI.",
|
69 |
+
default=False,
|
70 |
+
action="store_true",
|
71 |
+
)
|
72 |
+
args.add_argument(
|
73 |
+
"-d",
|
74 |
+
"--device",
|
75 |
+
help="Optional. Device to infer the model.",
|
76 |
+
choices=["CPU", "GPU"],
|
77 |
+
default="CPU",
|
78 |
+
type=str,
|
79 |
+
)
|
80 |
+
args.add_argument(
|
81 |
+
"--output",
|
82 |
+
default=None,
|
83 |
+
type=str,
|
84 |
+
help="Optional. Output path to save input data with predictions.",
|
85 |
+
)
|
86 |
+
|
87 |
+
return parser
|
88 |
+
|
89 |
+
|
90 |
+
EXECUTORS = {
|
91 |
+
"sync": SyncExecutor,
|
92 |
+
"async": AsyncExecutor,
|
93 |
+
"chain": ChainExecutor,
|
94 |
+
}
|
95 |
+
|
96 |
+
|
97 |
+
def get_inferencer_class(type_inference, models):
|
98 |
+
"""Return class for inference of models."""
|
99 |
+
if len(models) > 1:
|
100 |
+
type_inference = "chain"
|
101 |
+
print("You started the task chain pipeline with the provided models in the order in which they were specified")
|
102 |
+
return EXECUTORS[type_inference]
|
103 |
+
|
104 |
+
|
105 |
+
def main():
|
106 |
+
"""Main function that is used to run demo."""
|
107 |
+
args = build_argparser().parse_args()
|
108 |
+
|
109 |
+
if args.loop and args.output:
|
110 |
+
raise ValueError("--loop and --output cannot be both specified")
|
111 |
+
|
112 |
+
# create models
|
113 |
+
models = []
|
114 |
+
for model_dir in args.models:
|
115 |
+
model = ModelContainer(model_dir, device=args.device)
|
116 |
+
models.append(model)
|
117 |
+
|
118 |
+
inferencer = get_inferencer_class(args.inference_type, models)
|
119 |
+
|
120 |
+
# create visualizer
|
121 |
+
visualizer = create_visualizer(models[-1].task_type, no_show=args.no_show, output=args.output)
|
122 |
+
|
123 |
+
if len(models) == 1:
|
124 |
+
models = models[0]
|
125 |
+
|
126 |
+
# create inferencer and run
|
127 |
+
demo = inferencer(models, visualizer)
|
128 |
+
demo.run(args.input, args.loop and not args.no_show)
|
129 |
+
|
130 |
+
|
131 |
+
if __name__ == "__main__":
|
132 |
+
sys.exit(main() or 0)
|
deployment/Instance segmentation task/python/model_wrappers/__init__.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Model Wrapper Initialization of OTX Detection."""
|
2 |
+
|
3 |
+
# Copyright (C) 2021 Intel Corporation
|
4 |
+
#
|
5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
# you may not use this file except in compliance with the License.
|
7 |
+
# You may obtain a copy of the License at
|
8 |
+
#
|
9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
#
|
11 |
+
# Unless required by applicable law or agreed to in writing,
|
12 |
+
# software distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
# See the License for the specific language governing permissions
|
15 |
+
# and limitations under the License.
|
16 |
+
|
17 |
+
from .openvino_models import OTXMaskRCNNModel, OTXSSDModel
|
18 |
+
|
19 |
+
__all__ = ["OTXMaskRCNNModel", "OTXSSDModel"]
|
deployment/Instance segmentation task/python/model_wrappers/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (363 Bytes). View file
|
|
deployment/Instance segmentation task/python/model_wrappers/__pycache__/openvino_models.cpython-38.pyc
ADDED
Binary file (6.64 kB). View file
|
|
deployment/Instance segmentation task/python/model_wrappers/openvino_models.py
ADDED
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""OTXMaskRCNNModel & OTXSSDModel of OTX Detection."""
|
2 |
+
|
3 |
+
# Copyright (C) 2022 Intel Corporation
|
4 |
+
#
|
5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
# you may not use this file except in compliance with the License.
|
7 |
+
# You may obtain a copy of the License at
|
8 |
+
#
|
9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
#
|
11 |
+
# Unless required by applicable law or agreed to in writing,
|
12 |
+
# software distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
# See the License for the specific language governing permissions
|
15 |
+
# and limitations under the License.
|
16 |
+
|
17 |
+
from typing import Dict
|
18 |
+
|
19 |
+
import numpy as np
|
20 |
+
|
21 |
+
try:
|
22 |
+
from openvino.model_zoo.model_api.models.instance_segmentation import MaskRCNNModel
|
23 |
+
from openvino.model_zoo.model_api.models.ssd import SSD, find_layer_by_name
|
24 |
+
from openvino.model_zoo.model_api.models.utils import Detection
|
25 |
+
except ImportError as e:
|
26 |
+
import warnings
|
27 |
+
|
28 |
+
warnings.warn(f"{e}: ModelAPI was not found.")
|
29 |
+
|
30 |
+
|
31 |
+
class OTXMaskRCNNModel(MaskRCNNModel):
|
32 |
+
"""OpenVINO model wrapper for OTX MaskRCNN model."""
|
33 |
+
|
34 |
+
__model__ = "OTX_MaskRCNN"
|
35 |
+
|
36 |
+
def __init__(self, model_adapter, configuration, preload=False):
|
37 |
+
super().__init__(model_adapter, configuration, preload)
|
38 |
+
self.resize_mask = True
|
39 |
+
|
40 |
+
def _check_io_number(self, number_of_inputs, number_of_outputs):
|
41 |
+
"""Checks whether the number of model inputs/outputs is supported.
|
42 |
+
|
43 |
+
Args:
|
44 |
+
number_of_inputs (int, Tuple(int)): number of inputs supported by wrapper.
|
45 |
+
Use -1 to omit the check
|
46 |
+
number_of_outputs (int, Tuple(int)): number of outputs supported by wrapper.
|
47 |
+
Use -1 to omit the check
|
48 |
+
|
49 |
+
Raises:
|
50 |
+
WrapperError: if the model has unsupported number of inputs/outputs
|
51 |
+
"""
|
52 |
+
super()._check_io_number(number_of_inputs, -1)
|
53 |
+
|
54 |
+
def _get_outputs(self):
|
55 |
+
output_match_dict = {}
|
56 |
+
output_names = ["boxes", "labels", "masks", "feature_vector", "saliency_map"]
|
57 |
+
for output_name in output_names:
|
58 |
+
for node_name, node_meta in self.outputs.items():
|
59 |
+
if output_name in node_meta.names:
|
60 |
+
output_match_dict[output_name] = node_name
|
61 |
+
break
|
62 |
+
return output_match_dict
|
63 |
+
|
64 |
+
def postprocess(self, outputs, meta):
|
65 |
+
"""Post process function for OTX MaskRCNN model."""
|
66 |
+
|
67 |
+
# pylint: disable-msg=too-many-locals
|
68 |
+
# FIXME: here, batch dim of IR must be 1
|
69 |
+
boxes = outputs[self.output_blob_name["boxes"]]
|
70 |
+
if boxes.shape[0] == 1:
|
71 |
+
boxes = boxes.squeeze(0)
|
72 |
+
assert boxes.ndim == 2
|
73 |
+
masks = outputs[self.output_blob_name["masks"]]
|
74 |
+
if masks.shape[0] == 1:
|
75 |
+
masks = masks.squeeze(0)
|
76 |
+
assert masks.ndim == 3
|
77 |
+
classes = outputs[self.output_blob_name["labels"]].astype(np.uint32)
|
78 |
+
if classes.shape[0] == 1:
|
79 |
+
classes = classes.squeeze(0)
|
80 |
+
assert classes.ndim == 1
|
81 |
+
if self.is_segmentoly:
|
82 |
+
scores = outputs[self.output_blob_name["scores"]]
|
83 |
+
else:
|
84 |
+
scores = boxes[:, 4]
|
85 |
+
boxes = boxes[:, :4]
|
86 |
+
classes += 1
|
87 |
+
|
88 |
+
# Filter out detections with low confidence.
|
89 |
+
detections_filter = scores > self.confidence_threshold # pylint: disable=no-member
|
90 |
+
scores = scores[detections_filter]
|
91 |
+
boxes = boxes[detections_filter]
|
92 |
+
masks = masks[detections_filter]
|
93 |
+
classes = classes[detections_filter]
|
94 |
+
|
95 |
+
scale_x = meta["resized_shape"][1] / meta["original_shape"][1]
|
96 |
+
scale_y = meta["resized_shape"][0] / meta["original_shape"][0]
|
97 |
+
boxes[:, 0::2] /= scale_x
|
98 |
+
boxes[:, 1::2] /= scale_y
|
99 |
+
|
100 |
+
resized_masks = []
|
101 |
+
for box, cls, raw_mask in zip(boxes, classes, masks):
|
102 |
+
raw_cls_mask = raw_mask[cls, ...] if self.is_segmentoly else raw_mask
|
103 |
+
if self.resize_mask:
|
104 |
+
resized_masks.append(self._segm_postprocess(box, raw_cls_mask, *meta["original_shape"][:-1]))
|
105 |
+
else:
|
106 |
+
resized_masks.append(raw_cls_mask)
|
107 |
+
|
108 |
+
return scores, classes, boxes, resized_masks
|
109 |
+
|
110 |
+
def segm_postprocess(self, *args, **kwargs):
|
111 |
+
"""Post-process for segmentation masks."""
|
112 |
+
return self._segm_postprocess(*args, **kwargs)
|
113 |
+
|
114 |
+
def disable_mask_resizing(self):
|
115 |
+
"""Disable mask resizing.
|
116 |
+
|
117 |
+
There is no need to resize mask in tile as it will be processed at the end.
|
118 |
+
"""
|
119 |
+
self.resize_mask = False
|
120 |
+
|
121 |
+
|
122 |
+
class OTXSSDModel(SSD):
|
123 |
+
"""OpenVINO model wrapper for OTX SSD model."""
|
124 |
+
|
125 |
+
__model__ = "OTX_SSD"
|
126 |
+
|
127 |
+
def __init__(self, model_adapter, configuration=None, preload=False):
|
128 |
+
# pylint: disable-next=bad-super-call
|
129 |
+
super(SSD, self).__init__(model_adapter, configuration, preload)
|
130 |
+
self.image_info_blob_name = self.image_info_blob_names[0] if len(self.image_info_blob_names) == 1 else None
|
131 |
+
self.output_parser = BatchBoxesLabelsParser(
|
132 |
+
self.outputs,
|
133 |
+
self.inputs[self.image_blob_name].shape[2:][::-1],
|
134 |
+
)
|
135 |
+
|
136 |
+
def _get_outputs(self) -> Dict:
|
137 |
+
"""Match the output names with graph node index."""
|
138 |
+
output_match_dict = {}
|
139 |
+
output_names = ["boxes", "labels", "feature_vector", "saliency_map"]
|
140 |
+
for output_name in output_names:
|
141 |
+
for node_name, node_meta in self.outputs.items():
|
142 |
+
if output_name in node_meta.names:
|
143 |
+
output_match_dict[output_name] = node_name
|
144 |
+
break
|
145 |
+
return output_match_dict
|
146 |
+
|
147 |
+
|
148 |
+
class BatchBoxesLabelsParser:
|
149 |
+
"""Batched output parser."""
|
150 |
+
|
151 |
+
def __init__(self, layers, input_size, labels_layer="labels", default_label=0):
|
152 |
+
try:
|
153 |
+
self.labels_layer = find_layer_by_name(labels_layer, layers)
|
154 |
+
except ValueError:
|
155 |
+
self.labels_layer = None
|
156 |
+
self.default_label = default_label
|
157 |
+
|
158 |
+
try:
|
159 |
+
self.bboxes_layer = self.find_layer_bboxes_output(layers)
|
160 |
+
except ValueError:
|
161 |
+
self.bboxes_layer = find_layer_by_name("boxes", layers)
|
162 |
+
|
163 |
+
self.input_size = input_size
|
164 |
+
|
165 |
+
@staticmethod
|
166 |
+
def find_layer_bboxes_output(layers):
|
167 |
+
"""find_layer_bboxes_output."""
|
168 |
+
filter_outputs = [name for name, data in layers.items() if len(data.shape) == 3 and data.shape[-1] == 5]
|
169 |
+
if not filter_outputs:
|
170 |
+
raise ValueError("Suitable output with bounding boxes is not found")
|
171 |
+
if len(filter_outputs) > 1:
|
172 |
+
raise ValueError("More than 1 candidate for output with bounding boxes.")
|
173 |
+
return filter_outputs[0]
|
174 |
+
|
175 |
+
def __call__(self, outputs):
|
176 |
+
"""Parse bboxes."""
|
177 |
+
# FIXME: here, batch dim of IR must be 1
|
178 |
+
bboxes = outputs[self.bboxes_layer]
|
179 |
+
if bboxes.shape[0] == 1:
|
180 |
+
bboxes = bboxes.squeeze(0)
|
181 |
+
assert bboxes.ndim == 2
|
182 |
+
scores = bboxes[:, 4]
|
183 |
+
bboxes = bboxes[:, :4]
|
184 |
+
bboxes[:, 0::2] /= self.input_size[0]
|
185 |
+
bboxes[:, 1::2] /= self.input_size[1]
|
186 |
+
if self.labels_layer:
|
187 |
+
labels = outputs[self.labels_layer]
|
188 |
+
else:
|
189 |
+
labels = np.full(len(bboxes), self.default_label, dtype=bboxes.dtype)
|
190 |
+
if labels.shape[0] == 1:
|
191 |
+
labels = labels.squeeze(0)
|
192 |
+
|
193 |
+
detections = [Detection(*bbox, score, label) for label, score, bbox in zip(labels, scores, bboxes)]
|
194 |
+
return detections
|
deployment/Instance segmentation task/python/requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openvino==2022.3.0
|
2 |
+
openmodelzoo-modelapi==2022.3.0
|
3 |
+
otx=1.2.3.3
|
4 |
+
numpy>=1.21.0,<=1.23.5 # np.bool was removed in 1.24.0 which was used in openvino runtime
|
deployment/project.json
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"id": "6483114c18fb8c1c529bd149",
|
3 |
+
"name": "eggs!",
|
4 |
+
"creation_time": "2023-06-09T11:47:24.780000+00:00",
|
5 |
+
"creator_id": "[email protected]",
|
6 |
+
"pipeline": {
|
7 |
+
"tasks": [
|
8 |
+
{
|
9 |
+
"id": "6483114c18fb8c1c529bd14a",
|
10 |
+
"title": "Dataset",
|
11 |
+
"task_type": "dataset"
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"id": "6483114c18fb8c1c529bd14d",
|
15 |
+
"title": "Instance segmentation task",
|
16 |
+
"task_type": "instance_segmentation",
|
17 |
+
"labels": [
|
18 |
+
{
|
19 |
+
"id": "6483114c18fb8c1c529bd150",
|
20 |
+
"name": "egg",
|
21 |
+
"is_anomalous": false,
|
22 |
+
"color": "#c9e649ff",
|
23 |
+
"hotkey": "",
|
24 |
+
"is_empty": false,
|
25 |
+
"group": "Instance segmentation labels",
|
26 |
+
"parent_id": null
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"id": "6483114c18fb8c1c529bd154",
|
30 |
+
"name": "Empty",
|
31 |
+
"is_anomalous": false,
|
32 |
+
"color": "#000000ff",
|
33 |
+
"hotkey": "",
|
34 |
+
"is_empty": true,
|
35 |
+
"group": "Empty",
|
36 |
+
"parent_id": null
|
37 |
+
}
|
38 |
+
],
|
39 |
+
"label_schema_id": "6483114c18fb8c1c529bd156"
|
40 |
+
}
|
41 |
+
],
|
42 |
+
"connections": [
|
43 |
+
{
|
44 |
+
"from": "6483114c18fb8c1c529bd14a",
|
45 |
+
"to": "6483114c18fb8c1c529bd14d"
|
46 |
+
}
|
47 |
+
]
|
48 |
+
},
|
49 |
+
"datasets": [
|
50 |
+
{
|
51 |
+
"id": "6483114c18fb8c1c529bd151",
|
52 |
+
"name": "Dataset",
|
53 |
+
"use_for_training": true,
|
54 |
+
"creation_time": "2023-06-09T11:47:24.780000+00:00"
|
55 |
+
},
|
56 |
+
{
|
57 |
+
"id": "64898e9c68d5ade57e325981",
|
58 |
+
"name": "Testing set 1",
|
59 |
+
"use_for_training": false,
|
60 |
+
"creation_time": "2023-06-14T09:55:40.186000+00:00"
|
61 |
+
}
|
62 |
+
],
|
63 |
+
"thumbnail": "/api/v1/workspaces/6487656fb7efbf83c9b9ec35/projects/6483114c18fb8c1c529bd149/thumbnail",
|
64 |
+
"performance": {
|
65 |
+
"score": 0.9702380952380952
|
66 |
+
}
|
67 |
+
}
|
eggsample1.png
ADDED
Git LFS Details
|
eggsample2.png
ADDED
Git LFS Details
|
example_code/demo.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2022 Intel Corporation
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing,
|
10 |
+
# software distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions
|
13 |
+
# and limitations under the License.
|
14 |
+
|
15 |
+
import cv2
|
16 |
+
from geti_sdk.deployment import Deployment
|
17 |
+
from geti_sdk.utils import show_image_with_annotation_scene
|
18 |
+
|
19 |
+
if __name__ == "__main__":
|
20 |
+
# Step 1: Load the deployment
|
21 |
+
deployment = Deployment.from_folder("../deployment")
|
22 |
+
|
23 |
+
# Step 2: Load the sample image
|
24 |
+
image = cv2.imread("../sample_image.jpg")
|
25 |
+
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
26 |
+
|
27 |
+
# Step 3: Send inference model(s) to CPU
|
28 |
+
deployment.load_inference_models(device="CPU")
|
29 |
+
|
30 |
+
# Step 4: Infer image
|
31 |
+
prediction = deployment.infer(image_rgb)
|
32 |
+
|
33 |
+
# Step 5: Visualization
|
34 |
+
show_image_with_annotation_scene(image_rgb, prediction)
|
example_code/demo_notebook.ipynb
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "markdown",
|
5 |
+
"id": "86111f81-16f5-46e5-9010-1ef9e05a1571",
|
6 |
+
"metadata": {
|
7 |
+
"copyright": [
|
8 |
+
"INTEL CONFIDENTIAL",
|
9 |
+
"Copyright (C) 2022 Intel Corporation",
|
10 |
+
"This software and the related documents are Intel copyrighted materials, and your use of them is governed by",
|
11 |
+
"the express license under which they were provided to you (\"License\"). Unless the License provides otherwise,",
|
12 |
+
"you may not use, modify, copy, publish, distribute, disclose or transmit this software or the related documents",
|
13 |
+
"without Intel's prior written permission.",
|
14 |
+
"This software and the related documents are provided as is, with no express or implied warranties,",
|
15 |
+
"other than those that are expressly stated in the License."
|
16 |
+
]
|
17 |
+
},
|
18 |
+
"source": [
|
19 |
+
"# Intel® Geti™ deployment demo notebook\n",
|
20 |
+
"This notebook demonstrates how to run inference for a deployed Intel® Geti™ project on your local machine. It contains the following steps:\n",
|
21 |
+
"1. Load the deployment for the project from the exported `deployment` folder\n",
|
22 |
+
"2. Load a sample image to run inference on\n",
|
23 |
+
"3. Prepare the deployment for inference by sending the model (or models) for the project to the CPU\n",
|
24 |
+
"4. Infer image\n",
|
25 |
+
"5. Visualize prediction"
|
26 |
+
]
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"cell_type": "markdown",
|
30 |
+
"id": "a0ee561b-49fb-4f8b-9c7f-e4859e3fe99e",
|
31 |
+
"metadata": {},
|
32 |
+
"source": [
|
33 |
+
"### Step 1: Load the deployment"
|
34 |
+
]
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"cell_type": "code",
|
38 |
+
"execution_count": null,
|
39 |
+
"id": "d04d3e58-8cae-4491-86b6-fbc876fd5e4f",
|
40 |
+
"metadata": {},
|
41 |
+
"outputs": [],
|
42 |
+
"source": [
|
43 |
+
"from geti_sdk.deployment import Deployment\n",
|
44 |
+
"\n",
|
45 |
+
"deployment = Deployment.from_folder(\"../deployment\")"
|
46 |
+
]
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"cell_type": "markdown",
|
50 |
+
"id": "713de7c8-0ac4-4865-b947-98ecbc4173fb",
|
51 |
+
"metadata": {},
|
52 |
+
"source": [
|
53 |
+
"### Step 2: Load the sample image"
|
54 |
+
]
|
55 |
+
},
|
56 |
+
{
|
57 |
+
"cell_type": "code",
|
58 |
+
"execution_count": null,
|
59 |
+
"id": "5c61e01f-2c88-4f0d-ae18-88610cc13bf2",
|
60 |
+
"metadata": {},
|
61 |
+
"outputs": [],
|
62 |
+
"source": [
|
63 |
+
"import cv2\n",
|
64 |
+
"\n",
|
65 |
+
"image = cv2.imread(\"../sample_image.jpg\")\n",
|
66 |
+
"image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)"
|
67 |
+
]
|
68 |
+
},
|
69 |
+
{
|
70 |
+
"cell_type": "markdown",
|
71 |
+
"id": "40da9013-46f7-488d-972d-5ceddd54a60c",
|
72 |
+
"metadata": {},
|
73 |
+
"source": [
|
74 |
+
"### Step 3: Send inference model(s) to CPU"
|
75 |
+
]
|
76 |
+
},
|
77 |
+
{
|
78 |
+
"cell_type": "code",
|
79 |
+
"execution_count": null,
|
80 |
+
"id": "f6b80e6f-57fa-421a-b71f-ffbd0847c0a9",
|
81 |
+
"metadata": {},
|
82 |
+
"outputs": [],
|
83 |
+
"source": [
|
84 |
+
"deployment.load_inference_models(device='CPU')"
|
85 |
+
]
|
86 |
+
},
|
87 |
+
{
|
88 |
+
"cell_type": "markdown",
|
89 |
+
"id": "6f539adc-04e7-43b4-b113-99e7ff7f6482",
|
90 |
+
"metadata": {},
|
91 |
+
"source": [
|
92 |
+
"### Step 4: Infer image"
|
93 |
+
]
|
94 |
+
},
|
95 |
+
{
|
96 |
+
"cell_type": "code",
|
97 |
+
"execution_count": null,
|
98 |
+
"id": "a0e72d41-ec75-4bfe-859b-7302463b9fb6",
|
99 |
+
"metadata": {},
|
100 |
+
"outputs": [],
|
101 |
+
"source": [
|
102 |
+
"prediction = deployment.infer(image_rgb)"
|
103 |
+
]
|
104 |
+
},
|
105 |
+
{
|
106 |
+
"cell_type": "markdown",
|
107 |
+
"id": "5f450bb5-29dc-4ac4-b5bb-4b02f350aacc",
|
108 |
+
"metadata": {},
|
109 |
+
"source": [
|
110 |
+
"### Step 5: Visualization"
|
111 |
+
]
|
112 |
+
},
|
113 |
+
{
|
114 |
+
"cell_type": "code",
|
115 |
+
"execution_count": null,
|
116 |
+
"id": "db0dd922-36aa-4203-bc02-76c17d12d8be",
|
117 |
+
"metadata": {},
|
118 |
+
"outputs": [],
|
119 |
+
"source": [
|
120 |
+
"from geti_sdk.utils import show_image_with_annotation_scene\n",
|
121 |
+
"\n",
|
122 |
+
"show_image_with_annotation_scene(image_rgb, prediction, show_in_notebook=True)"
|
123 |
+
]
|
124 |
+
},
|
125 |
+
{
|
126 |
+
"cell_type": "code",
|
127 |
+
"execution_count": null,
|
128 |
+
"id": "a342324f-3177-4d61-bee4-40b47d0f78f8",
|
129 |
+
"metadata": {},
|
130 |
+
"outputs": [],
|
131 |
+
"source": []
|
132 |
+
}
|
133 |
+
],
|
134 |
+
"metadata": {
|
135 |
+
"celltoolbar": "Edit Metadata",
|
136 |
+
"kernelspec": {
|
137 |
+
"display_name": "Python 3 (ipykernel)",
|
138 |
+
"language": "python",
|
139 |
+
"name": "python3"
|
140 |
+
},
|
141 |
+
"language_info": {
|
142 |
+
"codemirror_mode": {
|
143 |
+
"name": "ipython",
|
144 |
+
"version": 3
|
145 |
+
},
|
146 |
+
"file_extension": ".py",
|
147 |
+
"mimetype": "text/x-python",
|
148 |
+
"name": "python",
|
149 |
+
"nbconvert_exporter": "python",
|
150 |
+
"pygments_lexer": "ipython3",
|
151 |
+
"version": "3.8.10"
|
152 |
+
}
|
153 |
+
},
|
154 |
+
"nbformat": 4,
|
155 |
+
"nbformat_minor": 5
|
156 |
+
}
|
example_code/demo_ovms.ipynb
ADDED
@@ -0,0 +1,421 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "markdown",
|
5 |
+
"metadata": {
|
6 |
+
"copyright": [
|
7 |
+
"INTEL CONFIDENTIAL",
|
8 |
+
"Copyright (C) 2023 Intel Corporation",
|
9 |
+
"This software and the related documents are Intel copyrighted materials, and your use of them is governed by",
|
10 |
+
"the express license under which they were provided to you (\"License\"). Unless the License provides otherwise,",
|
11 |
+
"you may not use, modify, copy, publish, distribute, disclose or transmit this software or the related documents",
|
12 |
+
"without Intel's prior written permission.",
|
13 |
+
"This software and the related documents are provided as is, with no express or implied warranties,",
|
14 |
+
"other than those that are expressly stated in the License."
|
15 |
+
]
|
16 |
+
},
|
17 |
+
"source": [
|
18 |
+
"# Serving Intel® Geti™ models with OpenVINO Model Server\n",
|
19 |
+
"This notebook shows how to set up an OpenVINO model server to serve the models trained\n",
|
20 |
+
"in your Intel® Geti™ project. It also shows how to use the Geti SDK as a client to\n",
|
21 |
+
"make inference requests to the model server.\n",
|
22 |
+
"\n",
|
23 |
+
"# Contents\n",
|
24 |
+
"\n",
|
25 |
+
"1. **OpenVINO Model Server**\n",
|
26 |
+
" 1. Requirements\n",
|
27 |
+
" 2. Generating the model server configuration\n",
|
28 |
+
" 3. Launching the model server\n",
|
29 |
+
"\n",
|
30 |
+
"2. **OVMS inference with Geti SDK**\n",
|
31 |
+
" 1. Loading inference model and sample image\n",
|
32 |
+
" 2. Requesting inference\n",
|
33 |
+
" 3. Inspecting the results\n",
|
34 |
+
"\n",
|
35 |
+
"3. **Conclusion**\n",
|
36 |
+
" 1. Cleaning up\n",
|
37 |
+
"\n",
|
38 |
+
"> **NOTE**: This notebook will set up a model server on the same machine that will be\n",
|
39 |
+
"> used as a client to request inference. In a real scenario you'd most likely\n",
|
40 |
+
"> want the server and the client to be different physical machines. The steps to set up\n",
|
41 |
+
"> OVMS on a remote server are the same as for the local server outlined in this\n",
|
42 |
+
"> notebook, but additional network configuration and security measures are most likely\n",
|
43 |
+
"> required.\n",
|
44 |
+
"\n",
|
45 |
+
"# OpenVINO Model Server\n",
|
46 |
+
"## Requirements\n",
|
47 |
+
"We will be running the OpenVINO Model Server (OVMS) with Docker. Please make sure you\n",
|
48 |
+
"have docker available on your system. You can install it by following the instructions\n",
|
49 |
+
"[here](https://docs.docker.com/get-docker/).\n",
|
50 |
+
"\n",
|
51 |
+
"## Generating the model server configuration\n",
|
52 |
+
"The `deployment` that was downloaded from the Intel® Geti™ platform can be used to create\n",
|
53 |
+
"the configuration files that are needed to set up an OpenVINO model server for your project.\n",
|
54 |
+
"\n",
|
55 |
+
"The cell below shows how to create the configuration. Running this cell should create\n",
|
56 |
+
"a folder called `ovms_models` in a temporary directory. The `ovms_models` folder\n",
|
57 |
+
"contains the models and the configuration files required to run OVMS for the Intel®\n",
|
58 |
+
"Geti™ project."
|
59 |
+
]
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"cell_type": "code",
|
63 |
+
"execution_count": null,
|
64 |
+
"metadata": {
|
65 |
+
"collapsed": false,
|
66 |
+
"jupyter": {
|
67 |
+
"outputs_hidden": false
|
68 |
+
},
|
69 |
+
"pycharm": {
|
70 |
+
"name": "#%%\n"
|
71 |
+
}
|
72 |
+
},
|
73 |
+
"outputs": [],
|
74 |
+
"source": [
|
75 |
+
"import os\n",
|
76 |
+
"import tempfile\n",
|
77 |
+
"\n",
|
78 |
+
"from geti_sdk.deployment import Deployment\n",
|
79 |
+
"\n",
|
80 |
+
"deployment_path = os.path.join(\"..\", \"deployment\")\n",
|
81 |
+
"\n",
|
82 |
+
"# Load the Geti deployment\n",
|
83 |
+
"deployment = Deployment.from_folder(deployment_path)\n",
|
84 |
+
"\n",
|
85 |
+
"# Creating the OVMS configuration for the deployment\n",
|
86 |
+
"# First, we'll create a temporary directory to store the config files\n",
|
87 |
+
"ovms_config_path = os.path.join(tempfile.mkdtemp(), \"ovms_models\")\n",
|
88 |
+
"\n",
|
89 |
+
"# Next, we generate the OVMS configuration and save it\n",
|
90 |
+
"deployment.generate_ovms_config(output_folder=ovms_config_path)\n",
|
91 |
+
"\n",
|
92 |
+
"print(f\"Configuration for OpenVINO Model Server was created at '{ovms_config_path}'\")"
|
93 |
+
]
|
94 |
+
},
|
95 |
+
{
|
96 |
+
"cell_type": "markdown",
|
97 |
+
"metadata": {
|
98 |
+
"pycharm": {
|
99 |
+
"name": "#%% md\n"
|
100 |
+
}
|
101 |
+
},
|
102 |
+
"source": [
|
103 |
+
"## Launching the model server\n",
|
104 |
+
"As mentioned before, we will run OVMS in a Docker container. First, we need to make sure\n",
|
105 |
+
"that we have the latest OVMS image on our system. Run the cell below to pull the image."
|
106 |
+
]
|
107 |
+
},
|
108 |
+
{
|
109 |
+
"cell_type": "code",
|
110 |
+
"execution_count": null,
|
111 |
+
"metadata": {
|
112 |
+
"collapsed": false,
|
113 |
+
"jupyter": {
|
114 |
+
"outputs_hidden": false
|
115 |
+
},
|
116 |
+
"pycharm": {
|
117 |
+
"name": "#%%\n"
|
118 |
+
}
|
119 |
+
},
|
120 |
+
"outputs": [],
|
121 |
+
"source": [
|
122 |
+
"! docker pull openvino/model_server:latest"
|
123 |
+
]
|
124 |
+
},
|
125 |
+
{
|
126 |
+
"cell_type": "markdown",
|
127 |
+
"metadata": {
|
128 |
+
"pycharm": {
|
129 |
+
"name": "#%% md\n"
|
130 |
+
}
|
131 |
+
},
|
132 |
+
"source": [
|
133 |
+
"Next, we have to start the container with the configuration that we just generated. This\n",
|
134 |
+
"is done in the cell below.\n",
|
135 |
+
"\n",
|
136 |
+
"> NOTE: The cell below starts the OVMS container and sets it up to listen for inference\n",
|
137 |
+
"> requests on port 9000 on your system. If this port is already occupied the `docker run`\n",
|
138 |
+
"> command will fail and you may need to try a different port number."
|
139 |
+
]
|
140 |
+
},
|
141 |
+
{
|
142 |
+
"cell_type": "code",
|
143 |
+
"execution_count": null,
|
144 |
+
"metadata": {
|
145 |
+
"collapsed": false,
|
146 |
+
"jupyter": {
|
147 |
+
"outputs_hidden": false
|
148 |
+
},
|
149 |
+
"pycharm": {
|
150 |
+
"name": "#%%\n"
|
151 |
+
}
|
152 |
+
},
|
153 |
+
"outputs": [],
|
154 |
+
"source": [
|
155 |
+
"# Launch the OVMS container\n",
|
156 |
+
"result = ! docker run -d --rm -v {ovms_config_path}:/models -p 9000:9000 --name ovms_demo openvino/model_server:latest --port 9000 --config_path /models/ovms_model_config.json\n",
|
157 |
+
"\n",
|
158 |
+
"# Check that the container was created successfully\n",
|
159 |
+
"if len(result) == 1:\n",
|
160 |
+
" container_id = result[0]\n",
|
161 |
+
" print(f\"OVMS container with ID '{container_id}' created.\")\n",
|
162 |
+
"else:\n",
|
163 |
+
" # Anything other than 1 result indicates that something went wrong\n",
|
164 |
+
" raise RuntimeError(result)\n",
|
165 |
+
"\n",
|
166 |
+
"# Check that the container is running properly\n",
|
167 |
+
"container_info = ! docker container inspect {container_id}\n",
|
168 |
+
"container_status = str(container_info.grep(\"Status\"))\n",
|
169 |
+
"\n",
|
170 |
+
"if not container_status or not \"running\" in container_status:\n",
|
171 |
+
" raise RuntimeError(\n",
|
172 |
+
" f\"Invalid ovms docker container status found: {container_status}. Most \"\n",
|
173 |
+
" f\"likely the container has not started properly.\"\n",
|
174 |
+
" )\n",
|
175 |
+
"print(\"OVMS container is up and running.\")"
|
176 |
+
]
|
177 |
+
},
|
178 |
+
{
|
179 |
+
"cell_type": "markdown",
|
180 |
+
"metadata": {
|
181 |
+
"pycharm": {
|
182 |
+
"name": "#%% md\n"
|
183 |
+
}
|
184 |
+
},
|
185 |
+
"source": [
|
186 |
+
"That's it! If all went well the cell above should print the ID of the container that\n",
|
187 |
+
"was created. This can be used to identify your container if you have a lot of docker\n",
|
188 |
+
"containers running on your system.\n",
|
189 |
+
"\n",
|
190 |
+
"# OVMS inference with Geti SDK\n",
|
191 |
+
"Now that the OVMS container is running, we can use the Geti SDK to talk to it and make an\n",
|
192 |
+
"inference request. The remaining part of this notebook shows how to do so.\n",
|
193 |
+
"\n",
|
194 |
+
"## Loading inference model and sample image\n",
|
195 |
+
"In the first part of this notebook we created configuration files for OVMS, using the\n",
|
196 |
+
"`deployment` that was generated for your Intel® Geti™ project. To do inference, we need\n",
|
197 |
+
"to connect the deployment to the OVMS container that is now running. This is done in the\n",
|
198 |
+
"cell below."
|
199 |
+
]
|
200 |
+
},
|
201 |
+
{
|
202 |
+
"cell_type": "code",
|
203 |
+
"execution_count": null,
|
204 |
+
"metadata": {
|
205 |
+
"collapsed": false,
|
206 |
+
"jupyter": {
|
207 |
+
"outputs_hidden": false
|
208 |
+
},
|
209 |
+
"pycharm": {
|
210 |
+
"name": "#%%\n"
|
211 |
+
}
|
212 |
+
},
|
213 |
+
"outputs": [],
|
214 |
+
"source": [
|
215 |
+
"# Load the inference models by connecting to OVMS on port 9000\n",
|
216 |
+
"deployment.load_inference_models(device=\"http://localhost:9000\")\n",
|
217 |
+
"\n",
|
218 |
+
"print(\"Connected to OpenVINO Model Server.\")"
|
219 |
+
]
|
220 |
+
},
|
221 |
+
{
|
222 |
+
"cell_type": "markdown",
|
223 |
+
"metadata": {
|
224 |
+
"pycharm": {
|
225 |
+
"name": "#%% md\n"
|
226 |
+
}
|
227 |
+
},
|
228 |
+
"source": [
|
229 |
+
"You should see some output indicating that the connection to OVMS was made successfully.\n",
|
230 |
+
"If you see any errors at this stage, make sure your OVMS container is running and that the\n",
|
231 |
+
"port number is correct.\n",
|
232 |
+
"\n",
|
233 |
+
"Next up, we'll load a sample image from the project to run inference on"
|
234 |
+
]
|
235 |
+
},
|
236 |
+
{
|
237 |
+
"cell_type": "code",
|
238 |
+
"execution_count": null,
|
239 |
+
"metadata": {
|
240 |
+
"collapsed": false,
|
241 |
+
"jupyter": {
|
242 |
+
"outputs_hidden": false
|
243 |
+
},
|
244 |
+
"pycharm": {
|
245 |
+
"name": "#%%\n"
|
246 |
+
}
|
247 |
+
},
|
248 |
+
"outputs": [],
|
249 |
+
"source": [
|
250 |
+
"import cv2\n",
|
251 |
+
"\n",
|
252 |
+
"# Load the sample image\n",
|
253 |
+
"image = cv2.imread(\"../sample_image.jpg\")\n",
|
254 |
+
"image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n",
|
255 |
+
"\n",
|
256 |
+
"# Show the image in the notebook\n",
|
257 |
+
"from IPython.display import display\n",
|
258 |
+
"from PIL import Image\n",
|
259 |
+
"\n",
|
260 |
+
"display(Image.fromarray(image_rgb))"
|
261 |
+
]
|
262 |
+
},
|
263 |
+
{
|
264 |
+
"cell_type": "markdown",
|
265 |
+
"metadata": {
|
266 |
+
"pycharm": {
|
267 |
+
"name": "#%% md\n"
|
268 |
+
}
|
269 |
+
},
|
270 |
+
"source": [
|
271 |
+
"## Requesting inference\n",
|
272 |
+
"Now that everything is set up, making an inference request is very simple:"
|
273 |
+
]
|
274 |
+
},
|
275 |
+
{
|
276 |
+
"cell_type": "code",
|
277 |
+
"execution_count": null,
|
278 |
+
"metadata": {
|
279 |
+
"collapsed": false,
|
280 |
+
"jupyter": {
|
281 |
+
"outputs_hidden": false
|
282 |
+
},
|
283 |
+
"pycharm": {
|
284 |
+
"name": "#%%\n"
|
285 |
+
}
|
286 |
+
},
|
287 |
+
"outputs": [],
|
288 |
+
"source": [
|
289 |
+
"import time\n",
|
290 |
+
"\n",
|
291 |
+
"t_start = time.time()\n",
|
292 |
+
"prediction = deployment.infer(image_rgb)\n",
|
293 |
+
"t_end = time.time()\n",
|
294 |
+
"\n",
|
295 |
+
"print(\n",
|
296 |
+
" f\"OVMS inference on sample image completed in {(t_end - t_start) * 1000:.1f} milliseconds.\"\n",
|
297 |
+
")"
|
298 |
+
]
|
299 |
+
},
|
300 |
+
{
|
301 |
+
"cell_type": "markdown",
|
302 |
+
"metadata": {
|
303 |
+
"pycharm": {
|
304 |
+
"name": "#%% md\n"
|
305 |
+
}
|
306 |
+
},
|
307 |
+
"source": [
|
308 |
+
"## Inspecting the results\n",
|
309 |
+
"Note that the code to request inference is exactly the same as for the case when the model\n",
|
310 |
+
"is loaded on the CPU (see `demo_notebook.ipynb`). Like The `prediction` can be shown using\n",
|
311 |
+
"the Geti SDK visualization utility function."
|
312 |
+
]
|
313 |
+
},
|
314 |
+
{
|
315 |
+
"cell_type": "code",
|
316 |
+
"execution_count": null,
|
317 |
+
"metadata": {
|
318 |
+
"collapsed": false,
|
319 |
+
"jupyter": {
|
320 |
+
"outputs_hidden": false
|
321 |
+
},
|
322 |
+
"pycharm": {
|
323 |
+
"name": "#%%\n"
|
324 |
+
}
|
325 |
+
},
|
326 |
+
"outputs": [],
|
327 |
+
"source": [
|
328 |
+
"from geti_sdk.utils import show_image_with_annotation_scene\n",
|
329 |
+
"\n",
|
330 |
+
"show_image_with_annotation_scene(image_rgb, prediction, show_in_notebook=True);"
|
331 |
+
]
|
332 |
+
},
|
333 |
+
{
|
334 |
+
"cell_type": "markdown",
|
335 |
+
"metadata": {
|
336 |
+
"jupyter": {
|
337 |
+
"outputs_hidden": false
|
338 |
+
},
|
339 |
+
"pycharm": {
|
340 |
+
"name": "#%% md\n"
|
341 |
+
}
|
342 |
+
},
|
343 |
+
"source": [
|
344 |
+
"# Conclusion\n",
|
345 |
+
"That's all there is to it! Of course in practice the client would request inference\n",
|
346 |
+
"from an OpenVINO model server on a different physical machine, in contrast to the\n",
|
347 |
+
"example here where client and server are running on the same machine.\n",
|
348 |
+
"\n",
|
349 |
+
"The steps outlined in this notebook can be used as a basis to set up a remote\n",
|
350 |
+
"client/server combination, but please note that additional network configuration will\n",
|
351 |
+
"be required (along with necessary security measures).\n",
|
352 |
+
"\n",
|
353 |
+
"## Cleaning up\n",
|
354 |
+
"To clean up, we'll stop the OVMS docker container that we started. This will\n",
|
355 |
+
"automatically remove the container. After that, we'll delete the temporary directory\n",
|
356 |
+
"we created to store the config files."
|
357 |
+
]
|
358 |
+
},
|
359 |
+
{
|
360 |
+
"cell_type": "code",
|
361 |
+
"execution_count": null,
|
362 |
+
"metadata": {},
|
363 |
+
"outputs": [],
|
364 |
+
"source": [
|
365 |
+
"# Stop the container\n",
|
366 |
+
"result = ! docker stop {container_id}\n",
|
367 |
+
"\n",
|
368 |
+
"# Check if removing the container worked correctly\n",
|
369 |
+
"if result[0] == container_id:\n",
|
370 |
+
" print(f\"OVMS container '{container_id}' stopped and removed successfully.\")\n",
|
371 |
+
"else:\n",
|
372 |
+
" print(\n",
|
373 |
+
" \"An error occurred while removing OVMS docker container. Most likely the container \"\n",
|
374 |
+
" \"was already removed. \"\n",
|
375 |
+
" )\n",
|
376 |
+
" print(f\"The docker daemon responded with the following error: \\n{result}\")\n",
|
377 |
+
" \n",
|
378 |
+
"# Remove the temporary directory with the OVMS configuration\n",
|
379 |
+
"import shutil\n",
|
380 |
+
"\n",
|
381 |
+
"temp_dir = os.path.dirname(ovms_config_path)\n",
|
382 |
+
"try:\n",
|
383 |
+
" shutil.rmtree(temp_dir)\n",
|
384 |
+
" print(\"Temporary configuration directory removed successfully.\")\n",
|
385 |
+
"except FileNotFoundError:\n",
|
386 |
+
" print(\n",
|
387 |
+
" f\"Temporary directory with OVMS configuration '{temp_dir}' was \"\n",
|
388 |
+
" f\"not found on the system. Most likely it is already removed.\"\n",
|
389 |
+
" )"
|
390 |
+
]
|
391 |
+
},
|
392 |
+
{
|
393 |
+
"cell_type": "code",
|
394 |
+
"execution_count": null,
|
395 |
+
"metadata": {},
|
396 |
+
"outputs": [],
|
397 |
+
"source": []
|
398 |
+
}
|
399 |
+
],
|
400 |
+
"metadata": {
|
401 |
+
"kernelspec": {
|
402 |
+
"display_name": "Python 3 (ipykernel)",
|
403 |
+
"language": "python",
|
404 |
+
"name": "python3"
|
405 |
+
},
|
406 |
+
"language_info": {
|
407 |
+
"codemirror_mode": {
|
408 |
+
"name": "ipython",
|
409 |
+
"version": 3
|
410 |
+
},
|
411 |
+
"file_extension": ".py",
|
412 |
+
"mimetype": "text/x-python",
|
413 |
+
"name": "python",
|
414 |
+
"nbconvert_exporter": "python",
|
415 |
+
"pygments_lexer": "ipython3",
|
416 |
+
"version": "3.8.16"
|
417 |
+
}
|
418 |
+
},
|
419 |
+
"nbformat": 4,
|
420 |
+
"nbformat_minor": 4
|
421 |
+
}
|
example_code/requirements-notebook.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Requirements for running the `demo_notebook.ipynb` and `demo_ovms.ipynb` Jupyter notebooks
|
2 |
+
geti-sdk==1.5.*
|
3 |
+
jupyterlab==3.6.*
|
4 |
+
opencv-python>=4.5.0
|
5 |
+
Pillow>=9.4.0
|
6 |
+
ipython>=8.10.0
|
example_code/requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Base requirements for the deployment
|
2 |
+
geti-sdk==1.5.*
|
3 |
+
opencv-python>=4.5.0
|
sample_image.jpg
ADDED