├── CMakeLists.txt ├── LICENSE ├── README.md ├── build-poseextractor.bat ├── build-poseextractor.sh ├── default_models.yml ├── labels_coco.txt ├── labels_imagenet.txt ├── labels_voc.txt ├── model_def.yml ├── open_model_zoo_toolkit.py ├── resources ├── car.png ├── car_1.bmp ├── face_lmk.jpg ├── face_res.jpg ├── face_rot.jpg ├── girl.jpg ├── humanpose_res.jpg ├── objdet.jpg ├── people.jpg ├── person.jpg ├── textdet.jpg ├── textdet_res.jpg └── vlcsnap-2020-09-22-13h06m25s471.jpg ├── test_classification.py ├── test_face.py ├── test_humanpose.py ├── test_object_detection.py └── test_text_detection.py /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project( pose_extractor ) 2 | cmake_minimum_required(VERSION 2.8) 3 | 4 | # Enabling Python 5 | find_package(PythonInterp 3.5 REQUIRED) 6 | find_package(PythonLibs "${PYTHON_VERSION_STRING}" EXACT REQUIRED) 7 | execute_process( 8 | COMMAND "${PYTHON_EXECUTABLE}" -c "import numpy; print(numpy.get_include())" 9 | OUTPUT_VARIABLE NUMPY_INCLUDE_DIR 10 | OUTPUT_STRIP_TRAILING_WHITESPACE 11 | RESULT_VARIABLE NUMPY_NOT_FOUND) 12 | if(NUMPY_NOT_FOUND) 13 | message(FATAL_ERROR "NumPy headers not found") 14 | endif() 15 | 16 | add_subdirectory(pose_extractor) 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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 [yyyy] [name of copyright owner] 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. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [OpenVINO](https://software.intel.com/content/www/us/en/develop/tools/openvino-toolkit.html) - Open Model Zoo toolkit 2 | ## Overview: 3 | This is a wrapper library for [Open Model Zoo (OMZ)](https://github.com/openvinotoolkit/open_model_zoo) for [Intel distribution of OpenVINO toolkit](https://software.intel.com/content/www/us/en/develop/tools/openvino-toolkit.html). User can use OMZ models without having deep knowledge of OpenVINO or deep-learning. **This library hides all the mess behind the scene.** 4 | User can utilize OpenVINO performance and OMZ algorithms (models) by simple funciton calls. 5 | これは[Intel distribution of OpenVINO toolkit](https://www.intel.co.jp/content/www/jp/ja/internet-of-things/openvino-toolkit.html)用のモデルライブラリ、[Open Model Zoo (OMZ)](https://github.com/openvinotoolkit/open_model_zoo)を簡単に利用できるようにするためのラッパーライブラリです。ユーザーはディープラーニングやOpenVINOの知識が無くてもディープラーニングを使った処理を実行可能になります。 6 | ユーザーは普通に関数を呼び出すだけでOpenVINOのパフォーマンスとOMZのアルゴリズムを利用可能です。 7 | 8 | ## IMPORTANT NOTICE 9 | - This library uses synchrounous infernence API. OpenVINO can achieve much higher throughput if you use **asynchronous inference API** natively. 10 | - OpenVINO setting is configurable through setConfig() API. User could achieve much higher performance if the user set the appropriate configuration for the system. This libray doesn't provide interface for it but still the user can use setConfig() API to setup OpenVINO for higher throughput. 11 | - このライブラリではOpenVINOの同期推論APIしか使用していません。OpenVINOは非同期推論APIを活用することでもっと高いスループットを発揮することが可能です(多くの場合)。 12 | - このライブラリではサポートしていませんが、setConfig() APIで使用している機材に合わせたセッティングをすることでもっと高い性能を出すことが可能な場合があります。このライブラリを使用していてもsetConfig() APIを使用することは可能です。 13 | 14 | ## Description: 15 | This toolkit (library) provides following functions or capabilities: 16 | 1. Automatic OMZ model downloading - 自動モデルダウンロード 17 | The library will download required OMZ IR models automatically if it's not existing on the computer. 18 | 2. Preprocess and postprocess - 推論プリ/ポストプロセス 19 | The library does required preprocess and postprocess for inferencing. User just need to provide an OpenCV image and get the parsed inference result. 20 | 21 | ## Prerequisites 22 | Intel OpenVINO toolkit 2021.3. 23 | 24 | ## Supported models 25 | Supported models are defined in `model_def.yml`. 26 | Check those files for details. 27 | 28 | ## Supported tasks (algorithms) 29 | The default model for a task is defined in `default_models.yml`. 30 | - image_classification 31 | - object_detection 32 | - face_detection 33 | - age_gender 34 | - head_pose 35 | - emotion 36 | - face_landmarks 37 | - text_detect 38 | - human_pose (require to build the pose_extractor C++ module to enable this feature) 39 | 40 | ## How to use 41 | 1. Deploy required files to your directory 42 | - `open_model_zoo_toolkit.py` 43 | - `default_models.yml` 44 | - `model_def.yml` 45 | - `labels_coco.txt` 46 | - `labels_imagenet.txt` 47 | - `labels_voc.txt` 48 | ** If you want to use human_pose_estimation ** 49 | - `CmakeLists.txt` 50 | - `build-poseextractor.bat` or `build-poseextractor.sh` 51 | Please follow the instruction in `how to build pose_extractor` section below to build the `pose_extractor` C++ module. 52 | 53 | 54 | ### Code example - Image classification 55 | ```python 56 | import cv2 57 | import open_model_zoo_toolkit as omztk 58 | 59 | omz = omztk.openvino_omz() 60 | model = omz.imageClassifier() 61 | #model.setDevice('MYRIAD') # You can change inference device. Default='CPU' 62 | 63 | img = cv2.imread('resources/car.png') 64 | res = model.run(img) 65 | print(res) 66 | # Example: res = [[479, 'car wheel', 0.5016654], [817, 'sports car, sport car', 0.31316656], [436, 'beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon', 0.06171181]] 67 | # res spec : [ [ classId, classLabel, probability ], ...] 68 | ``` 69 | 70 | ### Code example - Object detection 71 | ```python 72 | import cv2 73 | import open_model_zoo_toolkit as omztk 74 | 75 | omz = omztk.openvino_omz() 76 | model = omz.objectDetector() # Default model will be used 77 | #model = omz.objectDetector('ssd_mobilenet_v2_coco') # Also, you can select a OMZ model from 'model_def.yml' and use it 78 | 79 | img = cv2.imread('resources/car_1.bmp') 80 | res = model.run(img) 81 | print(res) 82 | # Example: res = [[1, 'person', 0.9291767, (42, 2), (759, 714)]] 83 | # res spec : [ [ classId, classLabel, probability, upper-right, bottom-left], ...] 84 | 85 | for obj in res: 86 | cv2.rectangle(img, obj[3], obj[4], color=(255,0,0), thickness=2) 87 | cv2.imshow('result', img) 88 | cv2.waitKey(3 * 1000) # 3 seconds 89 | ``` 90 | ![sample](resources/objdet.jpg) 91 | 92 | ### Code example - Text detection 93 | ```python 94 | import cv2 95 | import numpy as np 96 | import open_model_zoo_toolkit as omztk 97 | 98 | omz = omztk.openvino_omz() 99 | model = omz.textDetector() 100 | 101 | img = cv2.imread('resources/textdet.jpg') 102 | rects, imgs = model.run(img) 103 | print(rects) 104 | # res spec : rects = [ ((x0,y0), (x1,y1), angle), ... ] # == list of cv2.RotatedRect() 105 | # imgs = cropped OpenCV images of detected texts 106 | 107 | for rect in rects: 108 | box = cv2.boxPoints(rect).astype(np.int32) # Obtain rotated rectangle 109 | cv2.polylines(img, [box], True, (0,255,0), 4) # Draw bounding box 110 | 111 | cv2.imshow('text', img) 112 | key = cv2.waitKey(3 * 1000) # 3 sec 113 | ``` 114 | ![sample](resources/textdet_res.jpg) 115 | 116 | ### Code example - Human pose estimation 117 | 118 | *Note:* Human pose estimation requires a Python module to decode the inference result (pose extraction). The module comes with OpenVINO human_pose_estimation_demo_3d Python demo program and you need to build the pose extraction module by your self (pose_extractor.pyd). Run build_demo script with "-DENABLE_PYTHON=YES" option to build the module. 119 | 120 | ```python 121 | import cv2 122 | import open_model_zoo_toolkit as omztk 123 | 124 | omz = omztk.openvino_omz() 125 | model = omz.humanPoseEstimator() 126 | 127 | img = cv2.imread('resources/people.jpg') 128 | res = model.run(img) 129 | print(res) 130 | # res spec : res = [ person0, person1, ... ] 131 | # person = [ point * 18, + score ] # 3*18+1 = 55 elements 132 | # point = scaled_x, scaled_y, conf 133 | 134 | omztk.renderPeople(img, res) 135 | cv2.imshow('result', img) 136 | cv2.waitKey(3 * 1000) # 3 sec 137 | ``` 138 | ![sample](resources/humanpose_res.jpg) 139 | 140 | 141 | ### Code example - Face detection 142 | ```python 143 | import cv2 144 | import open_model_zoo_toolkit as omztk 145 | 146 | omz = omztk.openvino_omz() 147 | 148 | facedet = omz.faceDetector() 149 | agegen = omz.ageGenderEstimator() 150 | hp = omz.headPoseEstimator() 151 | emo = omz.emotionEstimator() 152 | lm = omz.faceLandmarksEstimator() 153 | 154 | img = cv2.imread('resources/girl.jpg') 155 | detected_faces = facedet.run(img) 156 | 157 | for face in detected_faces: 158 | face_img = omztk.ocv_crop(img, face[3], face[4], scale=1.3) # Crop detected face (x1.3 wider) 159 | landmarks = lm.run(face_img) # Estimate facial landmark points 160 | # Example: landmarks = [(112, 218), (245, 192), (185, 281), (138, 369), (254, 343)] 161 | 162 | face_lmk_img = face_img.copy() # Copy cropped face image to draw markers on it 163 | for lmk in landmarks: 164 | cv2.drawMarker(face_lmk_img, lmk, (255,0,0), markerType=cv2.MARKER_TILTED_CROSS, thickness=4) # Draw markers on landmarks 165 | cv2.imshow('cropped face with landmarks', face_lmk_img) 166 | cv2.waitKey(2 * 1000) # 2 sec # Display cropped face image with landmarks 167 | 168 | yaw, pitch, roll = hp.run(face_img) # Estimate head pose (=head rotation) 169 | # Example: yaw, pitch, roll = -2.6668947, 22.881355, -5.5514703 170 | face_rot_img = omztk.ocv_rotate(face_img, roll) # Correct roll to be upright the face 171 | 172 | age, gender, prob = agegen.run(face_rot_img) # Estimate age and gender 173 | print(age,gender,prob) 174 | # Example: age, gender, prob = 23, female, 0.8204694 175 | emotion = emo.run(face_rot_img) # Estimate emotion 176 | # Example: emotion = 'smile' 177 | 178 | print(age, gender, emotion, landmarks) 179 | 180 | cv2.imshow('cropped and rotated face', face_rot_img) 181 | cv2.waitKey(2 * 1000) # 2 sec 182 | 183 | cv2.rectangle(img, face[3], face[4], (255,0,0), 2) 184 | 185 | cv2.imshow('result', img) 186 | cv2.waitKey(3 * 1000) # 3 sec 187 | ``` 188 | ![sample](resources/face_lmk.jpg) 189 | ![sample](resources/face_rot.jpg) 190 | ![sample](resources/face_res.jpg) 191 | 192 | 193 | ----------------------------- 194 | 195 | ### How to build `pose extractor` for human_pose_estimation (Windows) 196 | 0. Prerequisites 197 | - Microsoft Visual Studio (w/C++ build package) 198 | 1. Open Microsoft Visual Studio command prompt (`Developer Command Prompt for VSxxxx`) 199 | 2. Run `build-poseextractor.bat` 200 | 3. You'll have `pose_extractor.pyd` in the current directory. 201 | 202 | 203 | ### How to build `pose_extractor` for human_pose_estimation (Ubuntu 18.04) 204 | 1. Open a terminal 205 | 2. Run `build-poseextractor.sh` 206 | You might need to give permission to run -> `chmod +x build-poseextractor.sh` 207 | 3. You'll have `pose_extractor.so` in the current directory. 208 | -------------------------------------------------------------------------------- /build-poseextractor.bat: -------------------------------------------------------------------------------- 1 | xcopy /E "%INTEL_OPENVINO_DIR%\deployment_tools\open_model_zoo\demos\python_demos\human_pose_estimation_3d_demo\pose_extractor" pose_extractor\ 2 | mkdir build 3 | cd build 4 | cmake -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release .. 5 | msbuild pose_extractor.sln /p:Configuration=Release 6 | cd .. 7 | copy build\pose_extractor\Release\pose_extractor.pyd . 8 | -------------------------------------------------------------------------------- /build-poseextractor.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cp -r ${INTEL_OPENVINO_DIR}/deployment_tools/open_model_zoo/demos/python_demos/human_pose_estimation_3d_demo/pose_extractor . 4 | mkdir -p build 5 | cd build 6 | cmake -DCMAKE_BUILD_TYPE=Release .. 7 | make 8 | cd .. 9 | cp build/pose_extractor/pose_extractor.so . 10 | -------------------------------------------------------------------------------- /default_models.yml: -------------------------------------------------------------------------------- 1 | # default IR model definition for omz.py 2 | # model name = OpenVINO Open Model Zoo model name. 3 | 4 | - task: image_classification 5 | model: googlenet-v1 6 | 7 | - task: object_detection 8 | model: ssd_mobilenet_v1_coco 9 | 10 | - task: face_detection 11 | model: face-detection-0200 12 | 13 | - task: age_gender 14 | model: age-gender-recognition-retail-0013 15 | 16 | - task: head_pose 17 | model: head-pose-estimation-adas-0001 18 | 19 | - task: emotion 20 | model: emotions-recognition-retail-0003 21 | 22 | - task: face_landmarks 23 | model: landmarks-regression-retail-0009 24 | 25 | - task: text_detect 26 | model: text-detection-0003 27 | 28 | - task: human_pose 29 | model: human-pose-estimation-0001 30 | -------------------------------------------------------------------------------- /labels_coco.txt: -------------------------------------------------------------------------------- 1 | background 2 | person 3 | bicycle 4 | car 5 | motorcycle 6 | airplane 7 | bus 8 | train 9 | truck 10 | boat 11 | trafficlight 12 | firehydrant 13 | stopsign 14 | parkingmeter 15 | bench 16 | bird 17 | cat 18 | dog 19 | horse 20 | sheep 21 | cow 22 | elephant 23 | bear 24 | zebra 25 | giraffe 26 | backpack 27 | umbrella 28 | handbag 29 | tie 30 | suitcase 31 | frisbee 32 | skis 33 | snowboard 34 | sportsball 35 | kite 36 | baseballbat 37 | baseballglove 38 | skateboard 39 | surfboard 40 | tennisracket 41 | bottle 42 | wineglass 43 | cup 44 | fork 45 | knife 46 | spoon 47 | bowl 48 | banana 49 | apple 50 | sandwich 51 | orange 52 | broccoli 53 | carrot 54 | hotdog 55 | pizza 56 | donut 57 | cake 58 | chair 59 | couch 60 | pottedplant 61 | bed 62 | diningtable 63 | toilet 64 | tv 65 | laptop 66 | mouse 67 | remote 68 | keyboard 69 | cellphone 70 | microwave 71 | oven 72 | toaster 73 | sink 74 | refrigerator 75 | book 76 | clock 77 | vase 78 | scissors 79 | teddybear 80 | hairdrier 81 | toothbrush 82 | -------------------------------------------------------------------------------- /labels_imagenet.txt: -------------------------------------------------------------------------------- 1 | tench, Tinca tinca 2 | goldfish, Carassius auratus 3 | great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias 4 | tiger shark, Galeocerdo cuvieri 5 | hammerhead, hammerhead shark 6 | electric ray, crampfish, numbfish, torpedo 7 | stingray 8 | cock 9 | hen 10 | ostrich, Struthio camelus 11 | brambling, Fringilla montifringilla 12 | goldfinch, Carduelis carduelis 13 | house finch, linnet, Carpodacus mexicanus 14 | junco, snowbird 15 | indigo bunting, indigo finch, indigo bird, Passerina cyanea 16 | robin, American robin, Turdus migratorius 17 | bulbul 18 | jay 19 | magpie 20 | chickadee 21 | water ouzel, dipper 22 | kite 23 | bald eagle, American eagle, Haliaeetus leucocephalus 24 | vulture 25 | great grey owl, great gray owl, Strix nebulosa 26 | European fire salamander, Salamandra salamandra 27 | common newt, Triturus vulgaris 28 | eft 29 | spotted salamander, Ambystoma maculatum 30 | axolotl, mud puppy, Ambystoma mexicanum 31 | bullfrog, Rana catesbeiana 32 | tree frog, tree-frog 33 | tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui 34 | loggerhead, loggerhead turtle, Caretta caretta 35 | leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea 36 | mud turtle 37 | terrapin 38 | box turtle, box tortoise 39 | banded gecko 40 | common iguana, iguana, Iguana iguana 41 | American chameleon, anole, Anolis carolinensis 42 | whiptail, whiptail lizard 43 | agama 44 | frilled lizard, Chlamydosaurus kingi 45 | alligator lizard 46 | Gila monster, Heloderma suspectum 47 | green lizard, Lacerta viridis 48 | African chameleon, Chamaeleo chamaeleon 49 | Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis 50 | African crocodile, Nile crocodile, Crocodylus niloticus 51 | American alligator, Alligator mississipiensis 52 | triceratops 53 | thunder snake, worm snake, Carphophis amoenus 54 | ringneck snake, ring-necked snake, ring snake 55 | hognose snake, puff adder, sand viper 56 | green snake, grass snake 57 | king snake, kingsnake 58 | garter snake, grass snake 59 | water snake 60 | vine snake 61 | night snake, Hypsiglena torquata 62 | boa constrictor, Constrictor constrictor 63 | rock python, rock snake, Python sebae 64 | Indian cobra, Naja naja 65 | green mamba 66 | sea snake 67 | horned viper, cerastes, sand viper, horned asp, Cerastes cornutus 68 | diamondback, diamondback rattlesnake, Crotalus adamanteus 69 | sidewinder, horned rattlesnake, Crotalus cerastes 70 | trilobite 71 | harvestman, daddy longlegs, Phalangium opilio 72 | scorpion 73 | black and gold garden spider, Argiope aurantia 74 | barn spider, Araneus cavaticus 75 | garden spider, Aranea diademata 76 | black widow, Latrodectus mactans 77 | tarantula 78 | wolf spider, hunting spider 79 | tick 80 | centipede 81 | black grouse 82 | ptarmigan 83 | ruffed grouse, partridge, Bonasa umbellus 84 | prairie chicken, prairie grouse, prairie fowl 85 | peacock 86 | quail 87 | partridge 88 | African grey, African gray, Psittacus erithacus 89 | macaw 90 | sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita 91 | lorikeet 92 | coucal 93 | bee eater 94 | hornbill 95 | hummingbird 96 | jacamar 97 | toucan 98 | drake 99 | red-breasted merganser, Mergus serrator 100 | goose 101 | black swan, Cygnus atratus 102 | tusker 103 | echidna, spiny anteater, anteater 104 | platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus 105 | wallaby, brush kangaroo 106 | koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus 107 | wombat 108 | jellyfish 109 | sea anemone, anemone 110 | brain coral 111 | flatworm, platyhelminth 112 | nematode, nematode worm, roundworm 113 | conch 114 | snail 115 | slug 116 | sea slug, nudibranch 117 | chiton, coat-of-mail shell, sea cradle, polyplacophore 118 | chambered nautilus, pearly nautilus, nautilus 119 | Dungeness crab, Cancer magister 120 | rock crab, Cancer irroratus 121 | fiddler crab 122 | king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica 123 | American lobster, Northern lobster, Maine lobster, Homarus americanus 124 | spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish 125 | crayfish, crawfish, crawdad, crawdaddy 126 | hermit crab 127 | isopod 128 | white stork, Ciconia ciconia 129 | black stork, Ciconia nigra 130 | spoonbill 131 | flamingo 132 | little blue heron, Egretta caerulea 133 | American egret, great white heron, Egretta albus 134 | bittern 135 | crane 136 | limpkin, Aramus pictus 137 | European gallinule, Porphyrio porphyrio 138 | American coot, marsh hen, mud hen, water hen, Fulica americana 139 | bustard 140 | ruddy turnstone, Arenaria interpres 141 | red-backed sandpiper, dunlin, Erolia alpina 142 | redshank, Tringa totanus 143 | dowitcher 144 | oystercatcher, oyster catcher 145 | pelican 146 | king penguin, Aptenodytes patagonica 147 | albatross, mollymawk 148 | grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus 149 | killer whale, killer, orca, grampus, sea wolf, Orcinus orca 150 | dugong, Dugong dugon 151 | sea lion 152 | Chihuahua 153 | Japanese spaniel 154 | Maltese dog, Maltese terrier, Maltese 155 | Pekinese, Pekingese, Peke 156 | Shih-Tzu 157 | Blenheim spaniel 158 | papillon 159 | toy terrier 160 | Rhodesian ridgeback 161 | Afghan hound, Afghan 162 | basset, basset hound 163 | beagle 164 | bloodhound, sleuthhound 165 | bluetick 166 | black-and-tan coonhound 167 | Walker hound, Walker foxhound 168 | English foxhound 169 | redbone 170 | borzoi, Russian wolfhound 171 | Irish wolfhound 172 | Italian greyhound 173 | whippet 174 | Ibizan hound, Ibizan Podenco 175 | Norwegian elkhound, elkhound 176 | otterhound, otter hound 177 | Saluki, gazelle hound 178 | Scottish deerhound, deerhound 179 | Weimaraner 180 | Staffordshire bullterrier, Staffordshire bull terrier 181 | American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier 182 | Bedlington terrier 183 | Border terrier 184 | Kerry blue terrier 185 | Irish terrier 186 | Norfolk terrier 187 | Norwich terrier 188 | Yorkshire terrier 189 | wire-haired fox terrier 190 | Lakeland terrier 191 | Sealyham terrier, Sealyham 192 | Airedale, Airedale terrier 193 | cairn, cairn terrier 194 | Australian terrier 195 | Dandie Dinmont, Dandie Dinmont terrier 196 | Boston bull, Boston terrier 197 | miniature schnauzer 198 | giant schnauzer 199 | standard schnauzer 200 | Scotch terrier, Scottish terrier, Scottie 201 | Tibetan terrier, chrysanthemum dog 202 | silky terrier, Sydney silky 203 | soft-coated wheaten terrier 204 | West Highland white terrier 205 | Lhasa, Lhasa apso 206 | flat-coated retriever 207 | curly-coated retriever 208 | golden retriever 209 | Labrador retriever 210 | Chesapeake Bay retriever 211 | German short-haired pointer 212 | vizsla, Hungarian pointer 213 | English setter 214 | Irish setter, red setter 215 | Gordon setter 216 | Brittany spaniel 217 | clumber, clumber spaniel 218 | English springer, English springer spaniel 219 | Welsh springer spaniel 220 | cocker spaniel, English cocker spaniel, cocker 221 | Sussex spaniel 222 | Irish water spaniel 223 | kuvasz 224 | schipperke 225 | groenendael 226 | malinois 227 | briard 228 | kelpie 229 | komondor 230 | Old English sheepdog, bobtail 231 | Shetland sheepdog, Shetland sheep dog, Shetland 232 | collie 233 | Border collie 234 | Bouvier des Flandres, Bouviers des Flandres 235 | Rottweiler 236 | German shepherd, German shepherd dog, German police dog, alsatian 237 | Doberman, Doberman pinscher 238 | miniature pinscher 239 | Greater Swiss Mountain dog 240 | Bernese mountain dog 241 | Appenzeller 242 | EntleBucher 243 | boxer 244 | bull mastiff 245 | Tibetan mastiff 246 | French bulldog 247 | Great Dane 248 | Saint Bernard, St Bernard 249 | Eskimo dog, husky 250 | malamute, malemute, Alaskan malamute 251 | Siberian husky 252 | dalmatian, coach dog, carriage dog 253 | affenpinscher, monkey pinscher, monkey dog 254 | basenji 255 | pug, pug-dog 256 | Leonberg 257 | Newfoundland, Newfoundland dog 258 | Great Pyrenees 259 | Samoyed, Samoyede 260 | Pomeranian 261 | chow, chow chow 262 | keeshond 263 | Brabancon griffon 264 | Pembroke, Pembroke Welsh corgi 265 | Cardigan, Cardigan Welsh corgi 266 | toy poodle 267 | miniature poodle 268 | standard poodle 269 | Mexican hairless 270 | timber wolf, grey wolf, gray wolf, Canis lupus 271 | white wolf, Arctic wolf, Canis lupus tundrarum 272 | red wolf, maned wolf, Canis rufus, Canis niger 273 | coyote, prairie wolf, brush wolf, Canis latrans 274 | dingo, warrigal, warragal, Canis dingo 275 | dhole, Cuon alpinus 276 | African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus 277 | hyena, hyaena 278 | red fox, Vulpes vulpes 279 | kit fox, Vulpes macrotis 280 | Arctic fox, white fox, Alopex lagopus 281 | grey fox, gray fox, Urocyon cinereoargenteus 282 | tabby, tabby cat 283 | tiger cat 284 | Persian cat 285 | Siamese cat, Siamese 286 | Egyptian cat 287 | cougar, puma, catamount, mountain lion, painter, panther, Felis concolor 288 | lynx, catamount 289 | leopard, Panthera pardus 290 | snow leopard, ounce, Panthera uncia 291 | jaguar, panther, Panthera onca, Felis onca 292 | lion, king of beasts, Panthera leo 293 | tiger, Panthera tigris 294 | cheetah, chetah, Acinonyx jubatus 295 | brown bear, bruin, Ursus arctos 296 | American black bear, black bear, Ursus americanus, Euarctos americanus 297 | ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus 298 | sloth bear, Melursus ursinus, Ursus ursinus 299 | mongoose 300 | meerkat, mierkat 301 | tiger beetle 302 | ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle 303 | ground beetle, carabid beetle 304 | long-horned beetle, longicorn, longicorn beetle 305 | leaf beetle, chrysomelid 306 | dung beetle 307 | rhinoceros beetle 308 | weevil 309 | fly 310 | bee 311 | ant, emmet, pismire 312 | grasshopper, hopper 313 | cricket 314 | walking stick, walkingstick, stick insect 315 | cockroach, roach 316 | mantis, mantid 317 | cicada, cicala 318 | leafhopper 319 | lacewing, lacewing fly 320 | dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk 321 | damselfly 322 | admiral 323 | ringlet, ringlet butterfly 324 | monarch, monarch butterfly, milkweed butterfly, Danaus plexippus 325 | cabbage butterfly 326 | sulphur butterfly, sulfur butterfly 327 | lycaenid, lycaenid butterfly 328 | starfish, sea star 329 | sea urchin 330 | sea cucumber, holothurian 331 | wood rabbit, cottontail, cottontail rabbit 332 | hare 333 | Angora, Angora rabbit 334 | hamster 335 | porcupine, hedgehog 336 | fox squirrel, eastern fox squirrel, Sciurus niger 337 | marmot 338 | beaver 339 | guinea pig, Cavia cobaya 340 | sorrel 341 | zebra 342 | hog, pig, grunter, squealer, Sus scrofa 343 | wild boar, boar, Sus scrofa 344 | warthog 345 | hippopotamus, hippo, river horse, Hippopotamus amphibius 346 | ox 347 | water buffalo, water ox, Asiatic buffalo, Bubalus bubalis 348 | bison 349 | ram, tup 350 | bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis 351 | ibex, Capra ibex 352 | hartebeest 353 | impala, Aepyceros melampus 354 | gazelle 355 | Arabian camel, dromedary, Camelus dromedarius 356 | llama 357 | weasel 358 | mink 359 | polecat, fitch, foulmart, foumart, Mustela putorius 360 | black-footed ferret, ferret, Mustela nigripes 361 | otter 362 | skunk, polecat, wood pussy 363 | badger 364 | armadillo 365 | three-toed sloth, ai, Bradypus tridactylus 366 | orangutan, orang, orangutang, Pongo pygmaeus 367 | gorilla, Gorilla gorilla 368 | chimpanzee, chimp, Pan troglodytes 369 | gibbon, Hylobates lar 370 | siamang, Hylobates syndactylus, Symphalangus syndactylus 371 | guenon, guenon monkey 372 | patas, hussar monkey, Erythrocebus patas 373 | baboon 374 | macaque 375 | langur 376 | colobus, colobus monkey 377 | proboscis monkey, Nasalis larvatus 378 | marmoset 379 | capuchin, ringtail, Cebus capucinus 380 | howler monkey, howler 381 | titi, titi monkey 382 | spider monkey, Ateles geoffroyi 383 | squirrel monkey, Saimiri sciureus 384 | Madagascar cat, ring-tailed lemur, Lemur catta 385 | indri, indris, Indri indri, Indri brevicaudatus 386 | Indian elephant, Elephas maximus 387 | African elephant, Loxodonta africana 388 | lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens 389 | giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca 390 | barracouta, snoek 391 | eel 392 | coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch 393 | rock beauty, Holocanthus tricolor 394 | anemone fish 395 | sturgeon 396 | gar, garfish, garpike, billfish, Lepisosteus osseus 397 | lionfish 398 | puffer, pufferfish, blowfish, globefish 399 | abacus 400 | abaya 401 | academic gown, academic robe, judge's robe 402 | accordion, piano accordion, squeeze box 403 | acoustic guitar 404 | aircraft carrier, carrier, flattop, attack aircraft carrier 405 | airliner 406 | airship, dirigible 407 | altar 408 | ambulance 409 | amphibian, amphibious vehicle 410 | analog clock 411 | apiary, bee house 412 | apron 413 | ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin 414 | assault rifle, assault gun 415 | backpack, back pack, knapsack, packsack, rucksack, haversack 416 | bakery, bakeshop, bakehouse 417 | balance beam, beam 418 | balloon 419 | ballpoint, ballpoint pen, ballpen, Biro 420 | Band Aid 421 | banjo 422 | bannister, banister, balustrade, balusters, handrail 423 | barbell 424 | barber chair 425 | barbershop 426 | barn 427 | barometer 428 | barrel, cask 429 | barrow, garden cart, lawn cart, wheelbarrow 430 | baseball 431 | basketball 432 | bassinet 433 | bassoon 434 | bathing cap, swimming cap 435 | bath towel 436 | bathtub, bathing tub, bath, tub 437 | beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon 438 | beacon, lighthouse, beacon light, pharos 439 | beaker 440 | bearskin, busby, shako 441 | beer bottle 442 | beer glass 443 | bell cote, bell cot 444 | bib 445 | bicycle-built-for-two, tandem bicycle, tandem 446 | bikini, two-piece 447 | binder, ring-binder 448 | binoculars, field glasses, opera glasses 449 | birdhouse 450 | boathouse 451 | bobsled, bobsleigh, bob 452 | bolo tie, bolo, bola tie, bola 453 | bonnet, poke bonnet 454 | bookcase 455 | bookshop, bookstore, bookstall 456 | bottlecap 457 | bow 458 | bow tie, bow-tie, bowtie 459 | brass, memorial tablet, plaque 460 | brassiere, bra, bandeau 461 | breakwater, groin, groyne, mole, bulwark, seawall, jetty 462 | breastplate, aegis, egis 463 | broom 464 | bucket, pail 465 | buckle 466 | bulletproof vest 467 | bullet train, bullet 468 | butcher shop, meat market 469 | cab, hack, taxi, taxicab 470 | caldron, cauldron 471 | candle, taper, wax light 472 | cannon 473 | canoe 474 | can opener, tin opener 475 | cardigan 476 | car mirror 477 | carousel, carrousel, merry-go-round, roundabout, whirligig 478 | carpenter's kit, tool kit 479 | carton 480 | car wheel 481 | cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM 482 | cassette 483 | cassette player 484 | castle 485 | catamaran 486 | CD player 487 | cello, violoncello 488 | cellular telephone, cellular phone, cellphone, cell, mobile phone 489 | chain 490 | chainlink fence 491 | chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour 492 | chain saw, chainsaw 493 | chest 494 | chiffonier, commode 495 | chime, bell, gong 496 | china cabinet, china closet 497 | Christmas stocking 498 | church, church building 499 | cinema, movie theater, movie theatre, movie house, picture palace 500 | cleaver, meat cleaver, chopper 501 | cliff dwelling 502 | cloak 503 | clog, geta, patten, sabot 504 | cocktail shaker 505 | coffee mug 506 | coffeepot 507 | coil, spiral, volute, whorl, helix 508 | combination lock 509 | computer keyboard, keypad 510 | confectionery, confectionary, candy store 511 | container ship, containership, container vessel 512 | convertible 513 | corkscrew, bottle screw 514 | cornet, horn, trumpet, trump 515 | cowboy boot 516 | cowboy hat, ten-gallon hat 517 | cradle 518 | crane 519 | crash helmet 520 | crate 521 | crib, cot 522 | Crock Pot 523 | croquet ball 524 | crutch 525 | cuirass 526 | dam, dike, dyke 527 | desk 528 | desktop computer 529 | dial telephone, dial phone 530 | diaper, nappy, napkin 531 | digital clock 532 | digital watch 533 | dining table, board 534 | dishrag, dishcloth 535 | dishwasher, dish washer, dishwashing machine 536 | disk brake, disc brake 537 | dock, dockage, docking facility 538 | dogsled, dog sled, dog sleigh 539 | dome 540 | doormat, welcome mat 541 | drilling platform, offshore rig 542 | drum, membranophone, tympan 543 | drumstick 544 | dumbbell 545 | Dutch oven 546 | electric fan, blower 547 | electric guitar 548 | electric locomotive 549 | entertainment center 550 | envelope 551 | espresso maker 552 | face powder 553 | feather boa, boa 554 | file, file cabinet, filing cabinet 555 | fireboat 556 | fire engine, fire truck 557 | fire screen, fireguard 558 | flagpole, flagstaff 559 | flute, transverse flute 560 | folding chair 561 | football helmet 562 | forklift 563 | fountain 564 | fountain pen 565 | four-poster 566 | freight car 567 | French horn, horn 568 | frying pan, frypan, skillet 569 | fur coat 570 | garbage truck, dustcart 571 | gasmask, respirator, gas helmet 572 | gas pump, gasoline pump, petrol pump, island dispenser 573 | goblet 574 | go-kart 575 | golf ball 576 | golfcart, golf cart 577 | gondola 578 | gong, tam-tam 579 | gown 580 | grand piano, grand 581 | greenhouse, nursery, glasshouse 582 | grille, radiator grille 583 | grocery store, grocery, food market, market 584 | guillotine 585 | hair slide 586 | hair spray 587 | half track 588 | hammer 589 | hamper 590 | hand blower, blow dryer, blow drier, hair dryer, hair drier 591 | hand-held computer, hand-held microcomputer 592 | handkerchief, hankie, hanky, hankey 593 | hard disc, hard disk, fixed disk 594 | harmonica, mouth organ, harp, mouth harp 595 | harp 596 | harvester, reaper 597 | hatchet 598 | holster 599 | home theater, home theatre 600 | honeycomb 601 | hook, claw 602 | hoopskirt, crinoline 603 | horizontal bar, high bar 604 | horse cart, horse-cart 605 | hourglass 606 | iPod 607 | iron, smoothing iron 608 | jack-o'-lantern 609 | jean, blue jean, denim 610 | jeep, landrover 611 | jersey, T-shirt, tee shirt 612 | jigsaw puzzle 613 | jinrikisha, ricksha, rickshaw 614 | joystick 615 | kimono 616 | knee pad 617 | knot 618 | lab coat, laboratory coat 619 | ladle 620 | lampshade, lamp shade 621 | laptop, laptop computer 622 | lawn mower, mower 623 | lens cap, lens cover 624 | letter opener, paper knife, paperknife 625 | library 626 | lifeboat 627 | lighter, light, igniter, ignitor 628 | limousine, limo 629 | liner, ocean liner 630 | lipstick, lip rouge 631 | Loafer 632 | lotion 633 | loudspeaker, speaker, speaker unit, loudspeaker system, speaker system 634 | loupe, jeweler's loupe 635 | lumbermill, sawmill 636 | magnetic compass 637 | mailbag, postbag 638 | mailbox, letter box 639 | maillot 640 | maillot, tank suit 641 | manhole cover 642 | maraca 643 | marimba, xylophone 644 | mask 645 | matchstick 646 | maypole 647 | maze, labyrinth 648 | measuring cup 649 | medicine chest, medicine cabinet 650 | megalith, megalithic structure 651 | microphone, mike 652 | microwave, microwave oven 653 | military uniform 654 | milk can 655 | minibus 656 | miniskirt, mini 657 | minivan 658 | missile 659 | mitten 660 | mixing bowl 661 | mobile home, manufactured home 662 | Model T 663 | modem 664 | monastery 665 | monitor 666 | moped 667 | mortar 668 | mortarboard 669 | mosque 670 | mosquito net 671 | motor scooter, scooter 672 | mountain bike, all-terrain bike, off-roader 673 | mountain tent 674 | mouse, computer mouse 675 | mousetrap 676 | moving van 677 | muzzle 678 | nail 679 | neck brace 680 | necklace 681 | nipple 682 | notebook, notebook computer 683 | obelisk 684 | oboe, hautboy, hautbois 685 | ocarina, sweet potato 686 | odometer, hodometer, mileometer, milometer 687 | oil filter 688 | organ, pipe organ 689 | oscilloscope, scope, cathode-ray oscilloscope, CRO 690 | overskirt 691 | oxcart 692 | oxygen mask 693 | packet 694 | paddle, boat paddle 695 | paddlewheel, paddle wheel 696 | padlock 697 | paintbrush 698 | pajama, pyjama, pj's, jammies 699 | palace 700 | panpipe, pandean pipe, syrinx 701 | paper towel 702 | parachute, chute 703 | parallel bars, bars 704 | park bench 705 | parking meter 706 | passenger car, coach, carriage 707 | patio, terrace 708 | pay-phone, pay-station 709 | pedestal, plinth, footstall 710 | pencil box, pencil case 711 | pencil sharpener 712 | perfume, essence 713 | Petri dish 714 | photocopier 715 | pick, plectrum, plectron 716 | pickelhaube 717 | picket fence, paling 718 | pickup, pickup truck 719 | pier 720 | piggy bank, penny bank 721 | pill bottle 722 | pillow 723 | ping-pong ball 724 | pinwheel 725 | pirate, pirate ship 726 | pitcher, ewer 727 | plane, carpenter's plane, woodworking plane 728 | planetarium 729 | plastic bag 730 | plate rack 731 | plow, plough 732 | plunger, plumber's helper 733 | Polaroid camera, Polaroid Land camera 734 | pole 735 | police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria 736 | poncho 737 | pool table, billiard table, snooker table 738 | pop bottle, soda bottle 739 | pot, flowerpot 740 | potter's wheel 741 | power drill 742 | prayer rug, prayer mat 743 | printer 744 | prison, prison house 745 | projectile, missile 746 | projector 747 | puck, hockey puck 748 | punching bag, punch bag, punching ball, punchball 749 | purse 750 | quill, quill pen 751 | quilt, comforter, comfort, puff 752 | racer, race car, racing car 753 | racket, racquet 754 | radiator 755 | radio, wireless 756 | radio telescope, radio reflector 757 | rain barrel 758 | recreational vehicle, RV, R.V. 759 | reel 760 | reflex camera 761 | refrigerator, icebox 762 | remote control, remote 763 | restaurant, eating house, eating place, eatery 764 | revolver, six-gun, six-shooter 765 | rifle 766 | rocking chair, rocker 767 | rotisserie 768 | rubber eraser, rubber, pencil eraser 769 | rugby ball 770 | rule, ruler 771 | running shoe 772 | safe 773 | safety pin 774 | saltshaker, salt shaker 775 | sandal 776 | sarong 777 | sax, saxophone 778 | scabbard 779 | scale, weighing machine 780 | school bus 781 | schooner 782 | scoreboard 783 | screen, CRT screen 784 | screw 785 | screwdriver 786 | seat belt, seatbelt 787 | sewing machine 788 | shield, buckler 789 | shoe shop, shoe-shop, shoe store 790 | shoji 791 | shopping basket 792 | shopping cart 793 | shovel 794 | shower cap 795 | shower curtain 796 | ski 797 | ski mask 798 | sleeping bag 799 | slide rule, slipstick 800 | sliding door 801 | slot, one-armed bandit 802 | snorkel 803 | snowmobile 804 | snowplow, snowplough 805 | soap dispenser 806 | soccer ball 807 | sock 808 | solar dish, solar collector, solar furnace 809 | sombrero 810 | soup bowl 811 | space bar 812 | space heater 813 | space shuttle 814 | spatula 815 | speedboat 816 | spider web, spider's web 817 | spindle 818 | sports car, sport car 819 | spotlight, spot 820 | stage 821 | steam locomotive 822 | steel arch bridge 823 | steel drum 824 | stethoscope 825 | stole 826 | stone wall 827 | stopwatch, stop watch 828 | stove 829 | strainer 830 | streetcar, tram, tramcar, trolley, trolley car 831 | stretcher 832 | studio couch, day bed 833 | stupa, tope 834 | submarine, pigboat, sub, U-boat 835 | suit, suit of clothes 836 | sundial 837 | sunglass 838 | sunglasses, dark glasses, shades 839 | sunscreen, sunblock, sun blocker 840 | suspension bridge 841 | swab, swob, mop 842 | sweatshirt 843 | swimming trunks, bathing trunks 844 | swing 845 | switch, electric switch, electrical switch 846 | syringe 847 | table lamp 848 | tank, army tank, armored combat vehicle, armoured combat vehicle 849 | tape player 850 | teapot 851 | teddy, teddy bear 852 | television, television system 853 | tennis ball 854 | thatch, thatched roof 855 | theater curtain, theatre curtain 856 | thimble 857 | thresher, thrasher, threshing machine 858 | throne 859 | tile roof 860 | toaster 861 | tobacco shop, tobacconist shop, tobacconist 862 | toilet seat 863 | torch 864 | totem pole 865 | tow truck, tow car, wrecker 866 | toyshop 867 | tractor 868 | trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi 869 | tray 870 | trench coat 871 | tricycle, trike, velocipede 872 | trimaran 873 | tripod 874 | triumphal arch 875 | trolleybus, trolley coach, trackless trolley 876 | trombone 877 | tub, vat 878 | turnstile 879 | typewriter keyboard 880 | umbrella 881 | unicycle, monocycle 882 | upright, upright piano 883 | vacuum, vacuum cleaner 884 | vase 885 | vault 886 | velvet 887 | vending machine 888 | vestment 889 | viaduct 890 | violin, fiddle 891 | volleyball 892 | waffle iron 893 | wall clock 894 | wallet, billfold, notecase, pocketbook 895 | wardrobe, closet, press 896 | warplane, military plane 897 | washbasin, handbasin, washbowl, lavabo, wash-hand basin 898 | washer, automatic washer, washing machine 899 | water bottle 900 | water jug 901 | water tower 902 | whiskey jug 903 | whistle 904 | wig 905 | window screen 906 | window shade 907 | Windsor tie 908 | wine bottle 909 | wing 910 | wok 911 | wooden spoon 912 | wool, woolen, woollen 913 | worm fence, snake fence, snake-rail fence, Virginia fence 914 | wreck 915 | yawl 916 | yurt 917 | web site, website, internet site, site 918 | comic book 919 | crossword puzzle, crossword 920 | street sign 921 | traffic light, traffic signal, stoplight 922 | book jacket, dust cover, dust jacket, dust wrapper 923 | menu 924 | plate 925 | guacamole 926 | consomme 927 | hot pot, hotpot 928 | trifle 929 | ice cream, icecream 930 | ice lolly, lolly, lollipop, popsicle 931 | French loaf 932 | bagel, beigel 933 | pretzel 934 | cheeseburger 935 | hotdog, hot dog, red hot 936 | mashed potato 937 | head cabbage 938 | broccoli 939 | cauliflower 940 | zucchini, courgette 941 | spaghetti squash 942 | acorn squash 943 | butternut squash 944 | cucumber, cuke 945 | artichoke, globe artichoke 946 | bell pepper 947 | cardoon 948 | mushroom 949 | Granny Smith 950 | strawberry 951 | orange 952 | lemon 953 | fig 954 | pineapple, ananas 955 | banana 956 | jackfruit, jak, jack 957 | custard apple 958 | pomegranate 959 | hay 960 | carbonara 961 | chocolate sauce, chocolate syrup 962 | dough 963 | meat loaf, meatloaf 964 | pizza, pizza pie 965 | potpie 966 | burrito 967 | red wine 968 | espresso 969 | cup 970 | eggnog 971 | alp 972 | bubble 973 | cliff, drop, drop-off 974 | coral reef 975 | geyser 976 | lakeside, lakeshore 977 | promontory, headland, head, foreland 978 | sandbar, sand bar 979 | seashore, coast, seacoast, sea-coast 980 | valley, vale 981 | volcano 982 | ballplayer, baseball player 983 | groom, bridegroom 984 | scuba diver 985 | rapeseed 986 | daisy 987 | yellow lady's slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum 988 | corn 989 | acorn 990 | hip, rose hip, rosehip 991 | buckeye, horse chestnut, conker 992 | coral fungus 993 | agaric 994 | gyromitra 995 | stinkhorn, carrion fungus 996 | earthstar 997 | hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa 998 | bolete 999 | ear, spike, capitulum 1000 | toilet tissue, toilet paper, bathroom tissue 1001 | -------------------------------------------------------------------------------- /labels_voc.txt: -------------------------------------------------------------------------------- 1 | background 2 | aeroplane 3 | bicycle 4 | bird 5 | boat 6 | bottle 7 | bus 8 | car 9 | cat 10 | chair 11 | cow 12 | diningtable 13 | dog 14 | horse 15 | motorbike 16 | person 17 | pottedplant 18 | sheep 19 | sofa 20 | train 21 | tvmonitor -------------------------------------------------------------------------------- /model_def.yml: -------------------------------------------------------------------------------- 1 | # omz.yaml 2 | # OpenVINO Open Model Zoo - Model definition file for omz.py 3 | 4 | # ---------------------- Image Classification 5 | 6 | - name: googlenet-v1 7 | label: labels_imagenet.txt 8 | object: omz_image_classification 9 | postprocess: 10 | num_results: 3 11 | - name: googlenet-v2 12 | label: labels_imagenet.txt 13 | object: omz_image_classification 14 | postprocess: 15 | num_results: 3 16 | - name: googlenet-v3 17 | label: labels_imagenet.txt 18 | object: omz_image_classification 19 | postprocess: 20 | num_results: 3 21 | - name: resnet-50 22 | label: labels_imagenet.txt 23 | object: omz_image_classification 24 | postprocess: 25 | num_results: 3 26 | 27 | # ---------------------- Object Detection 28 | 29 | - name: ssd_mobilenet_v1_coco 30 | label: labels_coco.txt 31 | object: omz_object_detection_ssd 32 | postprocess: 33 | threshold: 0.7 34 | - name: ssd_mobilenet_v2_coco 35 | label: labels_coco.txt 36 | object: omz_object_detection_ssd 37 | postprocess: 38 | threshold: 0.7 39 | - name: ssd_resnet50_v1_fpn_coco 40 | label: labels_coco.txt 41 | object: omz_object_detection_ssd 42 | postprocess: 43 | threshold: 0.7 44 | 45 | - name: yolo-v3-tf 46 | label: labels_voc.txt 47 | object: omz_object_detection_yolo_v3 48 | postprocess: 49 | threshold: 0.7 50 | iou: 0.8 51 | 52 | # ---------------------- Face Detection 53 | 54 | - name: face-detection-0200 55 | object: omz_object_detection_ssd 56 | description: Face detector based on MobileNetV2 as a backbone with a multiple SSD head for indoor and outdoor scenes shot by a front-facing camera. During the training of this model, training images were resized to 256x256. 57 | postprocess: 58 | threshold: 0.7 59 | - name: face-detection-0202 60 | description: Face detector based on MobileNetV2 as a backbone with a multiple SSD head for indoor and outdoor scenes shot by a front-facing camera. During the training of this model, training images were resized to 384x384. 61 | object: omz_object_detection_ssd 62 | postprocess: 63 | threshold: 0.7 64 | - name: face-detection-0204 65 | description: Face detector based on MobileNetV2 as a backbone with a multiple SSD head for indoor and outdoor scenes shot by a front-facing camera. During the training of this model, training images were resized to 448x448. 66 | object: omz_object_detection_ssd 67 | postprocess: 68 | threshold: 0.7 69 | 70 | 71 | # ---------------------- Person Detection 72 | 73 | - name: person-detection-retail-0002 74 | description: This is a pedestrian detector based on backbone with hyper-feature + R-FCN for the Retail scenario. 75 | object: omz_object_detection_ssd 76 | postprocess: 77 | threshold: 0.7 78 | - name: person-detection-retail-0013 79 | description: This is a pedestrian detector for the Retail scenario. It is based on MobileNetV2-like backbone that includes depth-wise convolutions to reduce the amount of computation for the 3x3 convolution block. The single SSD head from 1/16 scale feature map has 12 clustered prior boxes. 80 | object: omz_object_detection_ssd 81 | postprocess: 82 | threshold: 0.7 83 | - name: person-detection-retail-0100 84 | description: This is a person detector that is based on MobileNetV2 backbone with two SSD heads from 1/16 and 1/8 scale feature maps and clustered prior boxes for 256x256 resolution. 85 | object: omz_object_detection_ssd 86 | postprocess: 87 | threshold: 0.7 88 | - name: person-detection-retail-0101 89 | description: This is a person detector that is based on MobileNetV2 backbone with two SSD heads from 1/16 and 1/8 scale feature maps and clustered prior boxes for 384x384 resolution. 90 | object: omz_object_detection_ssd 91 | postprocess: 92 | threshold: 0.7 93 | - name: person-detection-retail-0102 94 | description: This is a person detector that is based on MobileNetV2 backbone with two SSD heads from 1/16 and 1/8 scale feature maps and clustered prior boxes for 512x512 resolution. 95 | object: omz_object_detection_ssd 96 | postprocess: 97 | threshold: 0.7 98 | - name: pedestrian-detection-adas-0002 99 | description: Pedestrian detection network based on SSD framework with tuned MobileNet v1 as a feature extractor. 100 | object: omz_object_detection_ssd 101 | postprocess: 102 | threshold: 0.7 103 | - name: pedestrian-detection-adas-binary-0001 104 | description: Pedestrian detection network based on SSD framework with tuned MobileNet v1 as a feature extractor. Some layers of MobileNet v1 are binary and use I1 arithm 105 | object: omz_object_detection_ssd 106 | postprocess: 107 | threshold: 0.7 108 | - name: pedestrian-and-vehicle-detector-adas-0001 109 | description: Pedestrian and vehicle detection network based on MobileNet v1.0 + SSD. 110 | object: omz_object_detection_ssd 111 | postprocess: 112 | threshold: 0.7 113 | 114 | # ---------------------- Vehicle Detection 115 | 116 | - name: vehicle-detection-adas-0002 117 | description: This is a vehicle detection network based on an SSD framework with tuned MobileNet v1 as a feature extractor. 118 | object: omz_object_detection_ssd 119 | postprocess: 120 | threshold: 0.7 121 | 122 | - name: vehicle-detection-adas-binary-0001 123 | description: This is a vehicle detection network based on an SSD framework with tuned MobileNet v1 as a feature extractor and using binary layer for speedup. This detecector was created by binarization the vehicle-detection-adas-0002 124 | object: omz_object_detection_ssd 125 | postprocess: 126 | threshold: 0.7 127 | 128 | # ---------------------- Age Gender Estimation 129 | 130 | - name: age-gender-recognition-retail-0013 131 | description: Fully convolutional network for simultaneous Age/Gender recognition. The network is able to recognize age of people in [18, 75] years old range, it is not applicable for children since their faces were not in the training set. 132 | object: omz_age_gender_estimation 133 | postprocess: 134 | dummy: 0 135 | 136 | # ---------------------- Head pose estimation 137 | 138 | - name: head-pose-estimation-adas-0001 139 | description: Head pose estimation network based on simple, handmade CNN architecture. Angle regression layers are convolutions + ReLU + batch norm + fully connected with one output. 140 | object: omz_head_pose_estimation 141 | postprocess: 142 | dummy: 0 143 | 144 | 145 | - name: emotions-recognition-retail-0003 146 | description: Fully convolutional network for recognition of five emotions ('neutral', 'happy', 'sad', 'surprise', 'anger'). 147 | object: omz_emotion_estimation 148 | postprocess: 149 | dummy: 0 150 | 151 | # ---------------------- Face landmark regression 152 | 153 | - name: landmarks-regression-retail-0009 154 | description: This is a lightweight landmarks regressor for the Smart Classroom scenario. It has a classic convolutional design; stacked 3x3 convolutions, batch normalizations, PReLU activations, and poolings. Final regression is done by the global depthwise pooling head and FullyConnected layers. The model predicts five facial landmarks; two eyes, nose, and two lip corners. 155 | object: omz_face_landmarks_regression 156 | postprocess: 157 | dummy: 0 158 | - name: facial-landmarks-35-adas-0002 159 | description: This is a custom-architecture convolutional neural network for 35 facial landmarks estimation. 160 | object: omz_face_landmarks_regression 161 | postprocess: 162 | dummy: 0 163 | 164 | # ---------------------- Text detection 165 | 166 | - name: text-detection-0003 167 | description: Text detector based on PixelLink architecture with MobileNetV2-like as a backbone for indoor/outdoor scenes. 168 | object: omz_text_detection 169 | postprocess: 170 | dummy: 0 171 | 172 | # ---------------------- Human pose estimation 173 | 174 | - name: human-pose-estimation-0001 175 | description: This is a multi-person 2D pose estimation network (based on the OpenPose approach) with tuned MobileNet v1 as a feature extractor. For every person in an image, the network detects a human pose; a body skeleton consisting of keypoints and connections between them. The pose may contain up to 18 keypoints; ears, eyes, nose, neck, shoulders, elbows, wrists, hips, knees, and ankles. 176 | object: omz_human_pose_estimation 177 | postprocess: 178 | dummy: 0 179 | -------------------------------------------------------------------------------- /open_model_zoo_toolkit.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import subprocess 4 | import math 5 | from math import exp 6 | 7 | import cv2 8 | import yaml 9 | import numpy as np 10 | from functools import reduce 11 | 12 | try: 13 | from openvino.inference_engine import IECore 14 | except ModuleNotFoundError: 15 | raise ModuleNotFoundError('Failed to import \'OpenVINO\'. Install OpenVINO and set environment variables. https://software.intel.com/content/www/us/en/develop/tools/openvino-toolkit.html') 16 | 17 | 18 | class ov_model: 19 | ie = IECore() 20 | available_devices = [ 'CPU', 'GPU', 'MYRIAD', 'HDDL', 'FPGA', 'GNA' ] 21 | available_vdevices = [ 'HETERO', 'MULTI' ] 22 | model_categories = [ 'public', 'intel' ] 23 | model_precision = 'FP16' 24 | 25 | def __init__(self, device='CPU', model=None, **kwargs): 26 | self.ie = ov_model.ie # not deep copy, use given object 27 | self.net = None 28 | self.exenet = None 29 | self.iblob = [] 30 | self.oblob = [] 31 | self.modelDir = '.' 32 | self.modelFile = None 33 | self.setDevice(device) 34 | self.postprocess_params = kwargs['kwargs'] 35 | self.labels = None 36 | if not model is None: 37 | self.loadModel(model) 38 | 39 | def __del__(self): 40 | del self.exenet 41 | del self.net 42 | 43 | def checkDevice(self, device): 44 | """ 45 | Check if the device descriptor is acceptable by IE. 46 | Args: 47 | device (string) : Inference device descriptor for IE 48 | Return: 49 | True or False : True = descriptor is acceptable 50 | """ 51 | if ':' in device: 52 | vdevice, devices = device.split(':') 53 | if not vdevice in ov_model.available_vdevices: 54 | return False 55 | devices = devices.split(',') 56 | for device in devices: 57 | if self.checkDevice(device) == False: 58 | return False 59 | elif not device in ov_model.available_devices: 60 | return False 61 | return True 62 | 63 | def setDevice(self, device='CPU'): 64 | """ 65 | Set inference device. 66 | Args: 67 | device (string) : OpenVINO Inference engine acceptable device descriptor. ('CPU', 'GPU', 'MYRIAD', 'MULTI:CPU,GPU', ...) 68 | Return: 69 | None 70 | """ 71 | if self.checkDevice(device) == False: 72 | raise Exception('Not supported device ({})'.format(device)) 73 | self.device = device 74 | if not self.net is None: 75 | del self.exenet 76 | self.exenet = self.ie.load_network(self.net, self.device, num_requests=4) 77 | 78 | def getInterfaceInfo(self): 79 | """ 80 | Obtain information of input and output blob of the model 81 | Args: 82 | None 83 | Returns: 84 | iblob/oblob : [ [ 'name':name0, 'shape':shape0, 'precision':precision0 ], ...] 85 | """ 86 | if self.net is None or self.exenet is None: 87 | return 88 | self.iblob = [ {'name':bname, 'shape':self.net.input_info[bname].tensor_desc.dims, 'precision':self.net.input_info[bname].precision } for bname in self.net.input_info ] 89 | self.oblob = [ {'name':bname, 'shape':self.net.outputs[bname].shape, 'precision':self.net.outputs[bname].precision } for bname in self.net.outputs ] 90 | 91 | def loadLabel(self, labelFile): 92 | """ 93 | Load label file. 94 | Args: 95 | labelFile (string) : Label file name 96 | Return: 97 | None 98 | """ 99 | self.labels = None 100 | if os.path.isfile(labelFile): 101 | with open(labelFile, 'rt') as f: 102 | self.labels = [ line.rstrip('\n') for line in f ] 103 | 104 | def loadModel(self, modelFile): 105 | """ 106 | Read IR model and load the model to IE. 107 | This function will search the model location under `./public` and `./intel`. 108 | Args: 109 | model : IR model file name without path ('mmmmm.xml') 110 | Return: 111 | None 112 | """ 113 | self.net = None 114 | self.exenet = None 115 | base, ext = os.path.splitext(modelFile) 116 | for modelcat in ov_model.model_categories: 117 | model_dir = os.path.join(self.modelDir, modelcat, base) 118 | if os.path.isdir(model_dir): 119 | modelfile = os.path.join(model_dir, ov_model.model_precision, base) 120 | self.net = self.ie.read_network(modelfile+'.xml', modelfile+'.bin') 121 | self.exenet = self.ie.load_network(self.net, self.device, num_requests=4) 122 | self.getInterfaceInfo() 123 | self.modelFile = modelFile 124 | return 125 | print('Failed to load a model :', modelFile) 126 | 127 | def inference(self, ocvimg): 128 | """ 129 | Do inference. 130 | Args: 131 | ocvimg : OpenCV input image for inference. 132 | Return: 133 | res : Inference result returned by OpenVINO IE 134 | """ 135 | iblobName = self.iblob[0]['name'] 136 | N,C,H,W = self.iblob[0]['shape'] 137 | img = cv2.resize(ocvimg, (W, H)) 138 | img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) 139 | img = img.transpose( (2,0,1) ) 140 | img = img.reshape( (1,C,H,W) ) 141 | res = self.exenet.infer( { iblobName : img }) 142 | return res 143 | 144 | 145 | # --------------------------- Parsing Algorithms 146 | 147 | def bbox_IOU(self, bbox1, bbox2): 148 | """ 149 | Calculate IOU of 2 bboxes. bboxes are in SSD format (7 elements) 150 | bbox = [id, cls, prob, x1, y1, x2, y2] 151 | Args: 152 | bbox1 (bbox) 153 | bbox2 (bbox) 154 | Returns: 155 | IOU value 156 | """ 157 | _xmin, _ymin, _xmax, _ymax = [ 3, 4, 5, 6 ] 158 | width_of_overlap_area = min(bbox1[_xmax], bbox2[_xmax]) - max(bbox1[_xmin], bbox2[_xmin]) 159 | height_of_overlap_area = min(bbox1[_ymax], bbox2[_ymax]) - max(bbox1[_ymin], bbox2[_ymin]) 160 | if width_of_overlap_area < 0 or height_of_overlap_area < 0: 161 | area_of_overlap = 0 162 | else: 163 | area_of_overlap = width_of_overlap_area * height_of_overlap_area 164 | bbox1_area = (bbox1[_ymax] - bbox1[_ymin]) * (bbox1[_xmax] - bbox1[_xmin]) 165 | bbox2_area = (bbox2[_ymax] - bbox2[_ymin]) * (bbox2[_xmax] - bbox2[_xmin]) 166 | area_of_union = bbox1_area + bbox2_area - area_of_overlap 167 | if area_of_union == 0: 168 | return 0 169 | return area_of_overlap / area_of_union 170 | 171 | def bbox_NMS(self, bboxes, iou_threshold=0.7): 172 | """ 173 | Perform non maximum suppression for bboxes to reject redundunt detections. 174 | bbox = [id, cls, prob, x1, y1, x2, y2] 175 | Args: 176 | bboxes ([bbox,...]): 177 | iou_threshold (float): Threshold value of rejection 178 | Returns: 179 | NMS applied bboxes 180 | """ 181 | _clsid, _prob = [ 1, 2 ] 182 | bboxes = sorted(bboxes, key=lambda x: x[_prob], reverse=True) 183 | for i in range(len(bboxes)): 184 | if bboxes[i][_prob] == -1: 185 | continue 186 | for j in range(i + 1, len(bboxes)): 187 | iou = self.bbox_IOU(bboxes[i], bboxes[j]) 188 | if iou > iou_threshold: 189 | bboxes[j][_prob] = -1 190 | res = [ bbox for bbox in bboxes if bbox[_prob]!=-1 ] 191 | return res 192 | 193 | def parse_yolo_region_v3(self, blob, resized_image_shape, params, threshold): 194 | """ 195 | Parse YOLO region. This function is intented to be called from decode_yolo_result(). 196 | Args: 197 | blob : An output blob of YOLO model inference result (one blob only). 198 | resized_image_shape: Shape information of the resized input image. 199 | params (dict) : YOLO parameters to decode the result 200 | threshold (float) : Threshold value for object rejection 201 | Returns: 202 | objs ([bbox]): bbox = [id, clsId, prob, x1, y1, x2, y2] 203 | """ 204 | def entry_index(side, coord, classes, location, entry): 205 | side_power_2 = side ** 2 206 | n = location // side_power_2 207 | loc = location % side_power_2 208 | return int(side_power_2 * (n * (coord + classes + 1) + entry) + loc) 209 | 210 | def scale_bbox(x, y, h, w, class_id, confidence, h_scale, w_scale): 211 | xmin = int((x - w / 2) * w_scale) 212 | ymin = int((y - h / 2) * h_scale) 213 | xmax = int(xmin + w * w_scale) 214 | ymax = int(ymin + h * h_scale) 215 | return [class_id, confidence, xmin, ymin, xmax, ymax] 216 | 217 | param_num = 3 if 'num' not in params else int(params['num']) 218 | param_coords = 4 if 'coords' not in params else int(params['coords']) 219 | param_classes = 80 if 'classes' not in params else int(params['classes']) 220 | param_side = int(params['side']) 221 | if 'anchors' not in params: 222 | anchors = [ 10.0, 13.0, 16.0, 30.0, 33.0, 23.0, 30.0, 61.0, 62.0, 45.0, 59.0, 119.0, 116.0, 90.0, 156.0, 198.0, 373.0, 326.0 ] 223 | else: 224 | anchors = [ float(anchor) for anchor in params['anchors'].split(',') ] 225 | 226 | if 'mask' not in params: 227 | param_anchors = anchors 228 | param_isYoloV3 = False 229 | else: 230 | if params['mask'] == '': 231 | param_anchors = anchors 232 | param_isYoloV3 = False 233 | else: 234 | masks = [ int(m) for m in params['mask'].split(',')] 235 | param_num = len(masks) 236 | param_anchors = [ [anchors[mask*2], anchors[mask*2+1]] for mask in masks ] 237 | param_isYoloV3 = True 238 | 239 | out_blob_h, out_blob_w = blob.shape[-2:] 240 | 241 | resized_image_h, resized_image_w = resized_image_shape 242 | objects = list() 243 | predictions = blob.flatten() 244 | side_square = param_side * param_side 245 | 246 | for i in range(side_square): 247 | row = i // param_side 248 | col = i % param_side 249 | for n in range(param_num): 250 | obj_index = entry_index(param_side, param_coords, param_classes, n * side_square + i, param_coords) 251 | scale = predictions[obj_index] 252 | if scale < threshold: 253 | continue 254 | box_index = entry_index(param_side, param_coords, param_classes, n * side_square + i, 0) 255 | 256 | x = (col + predictions[box_index + 0 * side_square]) / param_side 257 | y = (row + predictions[box_index + 1 * side_square]) / param_side 258 | try: 259 | w_exp = exp(predictions[box_index + 2 * side_square]) 260 | h_exp = exp(predictions[box_index + 3 * side_square]) 261 | except OverflowError: 262 | continue 263 | w = w_exp * param_anchors[n][0] / (resized_image_w if param_isYoloV3 else param_side) 264 | h = h_exp * param_anchors[n][1] / (resized_image_h if param_isYoloV3 else param_side) 265 | for j in range(param_classes): 266 | class_index = entry_index(param_side, param_coords, param_classes, n * side_square + i, 267 | param_coords + 1 + j) 268 | confidence = scale * predictions[class_index] 269 | if confidence < threshold: 270 | continue 271 | objects.append([0., j, confidence, x-w/2, y-h/2, x+w/2, y+h/2]) 272 | return objects 273 | 274 | 275 | def softmax_channel(self, data): 276 | for i in range(0, len(data), 2): 277 | m=max(data[i], data[i+1]) 278 | data[i ] = math.exp(data[i ]-m) 279 | data[i+1] = math.exp(data[i+1]-m) 280 | s=data[i ]+data[i+1] 281 | data[i ]/=s 282 | data[i+1]/=s 283 | return data 284 | 285 | def findRoot(self, point, group_mask): 286 | root = point 287 | update_parent = False 288 | while group_mask[root] != -1: 289 | root = group_mask[root] 290 | update_parent = True 291 | if update_parent: 292 | group_mask[point] = root 293 | return root 294 | 295 | def join(self, p1, p2, group_mask): 296 | root1 = self.findRoot(p1, group_mask) 297 | root2 = self.findRoot(p2, group_mask) 298 | if root1 != root2: 299 | group_mask[root1] = root2 300 | 301 | def get_all(self, points, w, h, group_mask): 302 | root_map = {} 303 | mask = np.zeros((h, w), np.int32) 304 | for px, py in points: 305 | point_root = self.findRoot(px+py*w, group_mask) 306 | if not point_root in root_map: 307 | root_map[point_root] = len(root_map)+1 308 | mask[py, px] = root_map[point_root] 309 | return mask 310 | 311 | def decodeImageByJoin(self, segm_data, segm_data_shape, link_data, link_data_shape, segm_conf_thresh, link_conf_thresh): 312 | h = segm_data_shape[1] 313 | w = segm_data_shape[2] 314 | pixel_mask = np.full((h*w,), False, dtype=np.bool) 315 | group_mask = {} 316 | points = [] 317 | for i, segm in enumerate(segm_data): 318 | if segm>segm_conf_thresh: 319 | pixel_mask[i] = True 320 | points.append((i%w, i//w)) 321 | group_mask[i] = -1 322 | else: 323 | pixel_mask[i] = False 324 | 325 | link_mask = np.array([ ld>=link_conf_thresh for ld in link_data ]) 326 | 327 | neighbours = int(link_data_shape[3]) 328 | for px, py in points: 329 | neighbor = 0 330 | for ny in range(py-1, py+1+1): 331 | for nx in range(px-1, px+1+1): 332 | if nx==px and ny==py: 333 | continue 334 | if nx<0 or nx>=w or ny<0 or ny>=h: 335 | continue 336 | pixel_value = pixel_mask[ny*w + nx] 337 | link_value = link_mask [py*w + px*neighbours + neighbor ] 338 | if pixel_value and link_value: 339 | self.join(px+py*w, nx+ny*w, group_mask) 340 | neighbor+=1 341 | return self.get_all(points, w, h, group_mask) 342 | 343 | def maskToBoxes(self, mask, min_area, min_height, image_size): 344 | _X, _Y = 0, 1 345 | bboxes = [] 346 | min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(mask) 347 | max_bbox_idx = int(max_val) 348 | resized_mask = cv2.resize(mask, image_size, interpolation=cv2.INTER_NEAREST) 349 | 350 | for i in range(1, max_bbox_idx+1): 351 | bbox_mask = np.where(resized_mask==i, 255, 0).astype(np.uint8) 352 | contours, hierarchy = cv2.findContours(bbox_mask, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE) 353 | if len(contours)==0: 354 | continue 355 | center, size, angle = cv2.minAreaRect(contours[0]) 356 | if min(size[_X], size[_Y]) < min_height: 357 | continue 358 | if size[_X]*size[_Y] < min_area: 359 | continue 360 | bboxes.append((center, size, angle)) 361 | return bboxes 362 | 363 | def text_detection_postprocess(self, link, segm, image_size, segm_conf_thresh, link_conf_thresh): 364 | _N, _C, _H, _W = 0, 1, 2, 3 365 | kMinArea = 300 366 | kMinHeight = 10 367 | 368 | link_shape = link.shape 369 | link_data_size = reduce(lambda a, b: a*b, link_shape) 370 | link_data = link.transpose((_N, _H, _W, _C)) 371 | link_data = link_data.flatten() 372 | link_data = self.softmax_channel(link_data) 373 | link_data = link_data.reshape((-1,2))[:,1] 374 | new_link_data_shape = [ link_shape[0], link_shape[2], link_shape[3], link_shape[1]/2 ] 375 | 376 | segm_shape = segm.shape 377 | segm_data_size = reduce(lambda a, b: a*b, segm_shape) 378 | segm_data = segm.transpose((_N, _H, _W, _C)) 379 | segm_data = segm_data.flatten() 380 | segm_data = self.softmax_channel(segm_data) 381 | segm_data = segm_data.reshape((-1,2))[:,1] 382 | new_segm_data_shape = [ segm_shape[0], segm_shape[2], segm_shape[3], segm_shape[1]/2 ] 383 | 384 | mask = self.decodeImageByJoin(segm_data, new_segm_data_shape, link_data, new_link_data_shape, 385 | segm_conf_thresh, link_conf_thresh) 386 | rects = self.maskToBoxes(mask, kMinArea, kMinHeight, image_size) 387 | return rects 388 | 389 | # Crop image by rotated rectangle from the input image 390 | def cropRotatedImage(self, image, rect): 391 | def topLeftPoint(points): 392 | big_number = 1e10 393 | _X, _Y = 0, 1 394 | most_left = [big_number, big_number] 395 | almost_most_left = [big_number, big_number] 396 | most_left_idx = -1 397 | almost_most_left_idx = -1 398 | for i, point in enumerate(points): 399 | px, py = point 400 | if most_left[_X]>px: 401 | if most_left[_X] px and [px,py]!=most_left: 407 | almost_most_left = [px,py] 408 | almost_most_left_idx = i 409 | if almost_most_left[_Y]threshold: # Draw a bounding box and label when confidence>threshold 459 | clsid = int(clsid) 460 | pt0 = ( int(x0 * W), int(y0 * H) ) 461 | pt1 = ( int(x1 * W), int(y1 * H) ) 462 | if self.labels is None: 463 | objs.append([ clsid, '', confidence, pt0, pt1 ]) 464 | else: 465 | objs.append([ clsid, self.labels[clsid], confidence, pt0, pt1 ]) 466 | return objs 467 | 468 | class omz_object_detection_yolo_v3(ov_model): 469 | def run(self, ocvimg): 470 | infres = self.inference(ocvimg) 471 | objs = [] 472 | threshold = 0.7 473 | if 'threshold' in self.postprocess_params: 474 | threshold = self.postprocess_params['threshold'] 475 | iou_threshold = 0.7 476 | if 'iou' in self.postprocess_params: 477 | iou_threshold = self.postprocess_params['iou'] 478 | for outblob in self.oblob: 479 | bname = outblob['name'] 480 | blob_res = infres[bname] 481 | params = self.net.layers[bname].params 482 | params['side'] = outblob['shape'][-1] 483 | objs += self.parse_yolo_region_v3( 484 | blob = blob_res, 485 | resized_image_shape = self.iblob[0]['shape'][-2:], 486 | params = params, 487 | threshold = threshold ) 488 | objs = self.bbox_NMS(objs, iou_threshold = iou_threshold) 489 | return objs 490 | # params = {'anchors': '10,13,16,30,33,23,30,61,62,45,59,119,116,90,156,198,373,326', 'axis': '1', 'classes': '80', 'coords': '4', 'do_softmax': '0', 'end_axis': '3', 'mask': '6,7,8', 'num': '9', 'originalLayersNames': 'conv2d_58/Conv2D/YoloRegion'} 491 | 492 | class omz_age_gender_estimation(ov_model): 493 | def run(self, ocvimg): 494 | infres = self.inference(ocvimg) 495 | age = int(infres['age_conv3'].ravel()[0] * 100) 496 | gender_res = infres['prob'].ravel() 497 | if gender_res[0]>gender_res[1]: 498 | return (age, 'female', gender_res[0]) 499 | else: 500 | return (age, 'male', gender_res[1]) 501 | 502 | class omz_head_pose_estimation(ov_model): 503 | def run(self, ocvimg): 504 | infres = self.inference(ocvimg) 505 | yaw = infres['angle_y_fc'].ravel()[0] 506 | pitch = infres['angle_p_fc'].ravel()[0] 507 | roll = infres['angle_r_fc'].ravel()[0] 508 | return (yaw, pitch, roll) 509 | 510 | class omz_emotion_estimation(ov_model): 511 | def run(self, ocvimg): 512 | infres = self.inference(ocvimg) 513 | infres = infres[self.oblob[0]['name']].ravel() 514 | idx = infres.argsort()[::-1] 515 | emotion = [ 'neutral', 'happy', 'sad', 'surprise', 'anger' ][idx[0]] 516 | return emotion 517 | 518 | class omz_face_landmarks_regression(ov_model): 519 | def run(self, ocvimg): 520 | infres = self.inference(ocvimg) 521 | infres = infres[self.oblob[0]['name']].ravel() 522 | H, W, C = ocvimg.shape 523 | points = [ (int(infres[i]*W), int(infres[i+1]*H)) for i in range(0, infres.size ,2) ] 524 | return points 525 | 526 | class omz_text_detection(ov_model): 527 | def run(self, ocvimg): 528 | infres = self.inference(ocvimg) 529 | link = infres['model/link_logits_/add'] 530 | segm = infres['model/segm_logits/add'] 531 | H, W, C = ocvimg.shape 532 | rects = self.text_detection_postprocess(link, segm, (W,H), 0.7, 0.7) 533 | imgs = [] 534 | for rect in rects: 535 | imgs.append(self.cropRotatedImage(ocvimg, rect)) # Cut out the text region 536 | return rects, imgs 537 | 538 | try: 539 | # C++ module for human pose estimation to extract the human pose from PAFs and heatmaps. 540 | # This module comes with OpenVINO human_pose_estimation_3d Python demo project. 541 | # You need to build the module to enable this feature. 542 | human_pose_available = True 543 | from pose_extractor import extract_poses 544 | except ModuleNotFoundError: 545 | print('ERROR: extract_pose module is required to postprocess the human-pose-estimation model. It comes with OpenVINO human_pose_estimation_demo_3D demo program and you need to build the module, and then place the module to the current directory.') 546 | print('Run the OpenVINO demo build script with \'-DENABLE_PYTHON=YES\' option to build the human pose estimation Python module.') 547 | human_pose_available = False 548 | 549 | class omz_human_pose_estimation(ov_model): 550 | def run(self, ocvimg): 551 | global human_pose_available 552 | if human_pose_available == False: 553 | return None 554 | infres = self.inference(ocvimg) 555 | PAFs = infres['Mconv7_stage2_L1'][0] 556 | HMs = infres['Mconv7_stage2_L2'][0] 557 | people = extract_poses(HMs[:-1], PAFs, 4) # Construct poses from HMs and PAFs 558 | return people 559 | 560 | 561 | 562 | 563 | class openvino_omz: 564 | model_categories = [ 'public', 'intel' ] 565 | 566 | def __init__(self): 567 | self.openvino_dir = os.environ['INTEL_OPENVINO_DIR'] 568 | if self.openvino_dir is None: 569 | raise Exception('OpenVINO environment variables are not set.') 570 | self.omz_dir = os.path.join(self.openvino_dir, 'deployment_tools', 'open_model_zoo') 571 | with open('model_def.yml') as f: 572 | self.model_def = yaml.safe_load(f) 573 | self.ie = IECore() 574 | with open('default_models.yml') as f: 575 | self.default_models = yaml.safe_load(f) 576 | self.ie = IECore() 577 | 578 | def __del__(self): 579 | del self.ie 580 | 581 | def checkModelCategory(self, omzmodel): 582 | """ 583 | Search OMZ model and determine whether the model belongs to eitgher 'public' or 'intel'. 584 | Args: 585 | omzmodel: OMZ model name 586 | Return: 587 | model category ('public', 'intel', or None) 588 | """ 589 | for modelcat in openvino_omz.model_categories: 590 | if os.path.isfile(os.path.join(self.omz_dir, 'models', modelcat, omzmodel, 'model.yml')): 591 | return modelcat 592 | return None 593 | 594 | def downloadModel(self, omzmodel): 595 | """ 596 | Check whether specified OMZ model is existing or not, and download it if it's not existing. 597 | This function will call `model downloader` and `model converter` of OpenVINO to obtain specified OMZ IR model. 598 | Args: 599 | omzmodel: OMZ model name 600 | Return: 601 | None 602 | """ 603 | # omzmodel : omz model name (e.g. googlenet-v1) 604 | model_path = os.path.join(omzmodel, 'FP16') 605 | 606 | # Check if IR model is existing 607 | exist = False 608 | for modelcat in openvino_omz.model_categories: 609 | if os.path.isfile(os.path.join(modelcat, model_path, omzmodel+'.xml')) == True: 610 | exist = True 611 | 612 | if exist == False: # IR model is not existing. Let's download it. 613 | if os.name == 'nt': 614 | python = 'python' 615 | elif os.name == 'posix': 616 | python = 'python3' 617 | else: 618 | raise Exception('Unknown OS type ({})'.format(os.name)) 619 | downloader_path = os.path.join(self.omz_dir, 'tools', 'downloader') 620 | # Download a OMZ model 621 | cmd = [ python , os.path.join(downloader_path, 'downloader.py'), '--name', omzmodel, '--precisions', 'FP16' ] 622 | subprocess.call(cmd) 623 | # Convert the model into IR if the model is a 'public' model 624 | category = self.checkModelCategory(omzmodel) 625 | if category == 'public': 626 | cmd = [ python , os.path.join(downloader_path, 'converter.py'), '--name', omzmodel , '--precisions', 'FP16'] 627 | subprocess.call(cmd) 628 | 629 | def findModelDef(self, omzmodel): 630 | """ 631 | Search a model definition and return the record in a dictionary. 632 | Args: 633 | omzmodel: OMZ model name 634 | Return: 635 | `model_def` record for the specified omzmodel 636 | """ 637 | for modelinfo in self.model_def: 638 | if modelinfo['name'] == omzmodel: 639 | return modelinfo 640 | return None 641 | 642 | def loadModel(self, omzmodel, download=True, **kwargs): 643 | """ 644 | Download the OMZ IR model if the specified model has not been downloaded yet. 645 | Create an `ov_model` object and load the OMZ IR model. The `ov_model` is created based on the description in `model_def.yml`. 646 | Return the created `ov_model` object. 647 | Args: 648 | omzmodel : OMZ model name 649 | download (bool): default=True 650 | kwargs (dict): parameters for postprocessing 651 | Returns: 652 | ov_model object 653 | """ 654 | if download: 655 | self.downloadModel(omzmodel) 656 | modelinfo = self.findModelDef(omzmodel) 657 | objname = modelinfo['object'] 658 | obj = globals()[objname](model=omzmodel+'.xml', kwargs=kwargs['kwargs']) 659 | return obj 660 | 661 | def getDefaultmodel(self, name): 662 | """ 663 | Get default OMZ model name for a specified task from `default_models.yml`. 664 | Args: 665 | name: Task name to find the default model (image_classification, object_detection, face_detection) 666 | Return: 667 | Default OMZ model name. Return 'None' if the default model is not found. 668 | """ 669 | for model in self.default_models: 670 | if model['task'] == name: 671 | return model['model'] 672 | return None 673 | 674 | def modelObjectFactory(self, taskName, omzModel=None): 675 | """ 676 | Create `ov_model` for a specified IR model by `omzModel`. 677 | The default IR model will be searched in `default_models.yml` based on `taskName` if `omzModel` is not specified. 678 | Args: 679 | taskName: Name of the NN-task ('image_classification', 'object_detection', ...) used for finding the default IR model from `default_model.yml` 680 | omzModel: This IR model will be used to create the ov_model object if specified. Otherwise, default model will be searched based on taskName. 681 | Return: 682 | ov_model object 683 | """ 684 | if omzModel is None: 685 | omzModel = self.getDefaultmodel(taskName) 686 | modelInfo = self.findModelDef(omzModel) 687 | params = modelInfo['postprocess'] 688 | obj = self.loadModel(omzModel, kwargs=params) 689 | if 'label' in modelInfo: 690 | obj.loadLabel(modelInfo['label']) 691 | return obj 692 | 693 | # ------------------------------------------------------ 694 | 695 | def imageClassifier(self, omzmodel=None): 696 | return self.modelObjectFactory('image_classification', omzmodel) 697 | 698 | def objectDetector(self, omzmodel=None): 699 | return self.modelObjectFactory('object_detection', omzmodel) 700 | 701 | def faceDetector(self, omzmodel=None): 702 | return self.modelObjectFactory('face_detection', omzmodel) 703 | 704 | def ageGenderEstimator(self, omzmodel=None): 705 | return self.modelObjectFactory('age_gender', omzmodel) 706 | 707 | def headPoseEstimator(self, omzmodel=None): 708 | return self.modelObjectFactory('head_pose', omzmodel) 709 | 710 | def emotionEstimator(self, omzmodel=None): 711 | return self.modelObjectFactory('emotion', omzmodel) 712 | 713 | def faceLandmarksEstimator(self, omzmodel=None): 714 | return self.modelObjectFactory('face_landmarks', omzmodel) 715 | 716 | def textDetector(self, omzmodel=None): 717 | return self.modelObjectFactory('text_detect', omzmodel) 718 | 719 | def humanPoseEstimator(self, omzmodel=None): 720 | return self.modelObjectFactory('human_pose', omzmodel) 721 | 722 | 723 | 724 | def ocv_crop(ocvimg, top_left, bottom_right, scale=1.0): 725 | """ 726 | Crop OpenCV image 727 | Args: 728 | ocvimg : OpenCV input image 729 | top_left (tuple) : top-left point of cropping region 730 | bottom_right (tuple) : bottom-right point of cropping region 731 | scale (float) : scale factor for the cropping region 732 | Return: 733 | cropped OpenCV image 734 | """ 735 | if top_left[0]>bottom_right[0] or top_left[1]>bottom_right[1]: 736 | top_left, bottom_right = bottom_right, top_left 737 | w, h = (bottom_right[0]-top_left[0])*scale, (bottom_right[1]-top_left[1])*scale 738 | cx, cy = (bottom_right[0]+top_left[0])//2 , (bottom_right[1]+top_left[1])//2 739 | x1 = max(int(cx - w//2), 0) 740 | y1 = max(int(cy - h//2), 0) 741 | x2 = min(int(cx + w//2), ocvimg.shape[1]-1) 742 | y2 = min(int(cy + h//2), ocvimg.shape[0]-1) 743 | img = ocvimg[y1:y2,x1:x2].copy() 744 | return img 745 | 746 | def ocv_rotate(ocvimg, angle_deg): 747 | """ 748 | Rotate OpenCV image. Rotation center is the center of the input image. 749 | Args: 750 | ocvimg : OpenCV input image 751 | angle_deg (float) : Angle to rotate in degree 752 | Return: 753 | Rotated OpenCV image 754 | """ 755 | h, w = ocvimg.shape[:2] 756 | rotmat = cv2.getRotationMatrix2D((w//2, h//2), angle_deg, 1.0) 757 | img = cv2.warpAffine(ocvimg, rotmat, (ocvimg.shape[1], ocvimg.shape[0])) 758 | return img 759 | 760 | def renderPeople(img, people, scaleFactor=4, threshold=0.5): 761 | """ 762 | Render people's bones estimated by human_pose_estimator. 763 | Args: 764 | img : OpenCV image 765 | people : Estimated human pose [ [person0], [person1], ...] 766 | scaleFactor (float) : Scale factor of heatmaps and PAFs (default=4) 767 | threshold (float) : Thresold value to determine whether draw or not 768 | Return: 769 | None 770 | """ 771 | if people is None: 772 | return 773 | 774 | limbIds = [ [ 1, 2], [ 1, 5], [ 2, 3], [ 3, 4], [ 5, 6], 775 | [ 6, 7], [ 1, 8], [ 8, 9], [ 9, 10], [ 1, 11], 776 | [11, 12], [12, 13], [ 1, 0], [ 0, 14], [14, 16], 777 | [ 0, 15], [15, 17] ] 778 | 779 | limbColors = [ 780 | (255, 0, 0), (255, 85, 0), (255,170, 0), 781 | (255,255, 0), (170,255, 0), ( 85,255, 0), 782 | ( 0,255, 0), ( 0,255, 85), ( 0,255,170), 783 | ( 0,255,255), ( 0,170,255), ( 0, 85,255), 784 | ( 0, 0,255), ( 85, 0,255), (170, 0,255), 785 | (255, 0,255), (255, 0,170), (255, 0, 85) 786 | ] 787 | # 57x32 = resolution of HM and PAF 788 | scalex = img.shape[1]/(57 * scaleFactor) 789 | scaley = img.shape[0]/(32 * scaleFactor) 790 | for person in people: 791 | for i, limbId in enumerate(limbIds): 792 | x1, y1, conf1 = person[ limbId[0]*3 : limbId[0]*3+2 +1 ] 793 | x2, y2, conf2 = person[ limbId[1]*3 : limbId[1]*3+2 +1 ] 794 | if conf1>threshold and conf2>threshold: 795 | cv2.line(img, (int(x1*scalex),int(y1*scaley)), (int(x2*scalex),int(y2*scaley)), limbColors[i], 2) 796 | 797 | 798 | 799 | if __name__ == "__main__": 800 | pass 801 | # test code 802 | -------------------------------------------------------------------------------- /resources/car.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/car.png -------------------------------------------------------------------------------- /resources/car_1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/car_1.bmp -------------------------------------------------------------------------------- /resources/face_lmk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/face_lmk.jpg -------------------------------------------------------------------------------- /resources/face_res.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/face_res.jpg -------------------------------------------------------------------------------- /resources/face_rot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/face_rot.jpg -------------------------------------------------------------------------------- /resources/girl.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/girl.jpg -------------------------------------------------------------------------------- /resources/humanpose_res.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/humanpose_res.jpg -------------------------------------------------------------------------------- /resources/objdet.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/objdet.jpg -------------------------------------------------------------------------------- /resources/people.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/people.jpg -------------------------------------------------------------------------------- /resources/person.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/person.jpg -------------------------------------------------------------------------------- /resources/textdet.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/textdet.jpg -------------------------------------------------------------------------------- /resources/textdet_res.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/textdet_res.jpg -------------------------------------------------------------------------------- /resources/vlcsnap-2020-09-22-13h06m25s471.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yas-sim/openvino_open_model_zoo_toolkit/23b65130e7ecff96c19d9b7d74ac8407096b64fe/resources/vlcsnap-2020-09-22-13h06m25s471.jpg -------------------------------------------------------------------------------- /test_classification.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import open_model_zoo_toolkit as omztk 3 | 4 | omz = omztk.openvino_omz() 5 | model = omz.imageClassifier() 6 | 7 | img = cv2.imread('resources/car.png') 8 | res = model.run(img) 9 | print(res) 10 | # Example: res = [[479, 'car wheel', 0.5016654], [817, 'sports car, sport car', 0.31316656], [436, 'beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon', 0.06171181]] 11 | -------------------------------------------------------------------------------- /test_face.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import open_model_zoo_toolkit as omztk 3 | 4 | omz = omztk.openvino_omz() 5 | 6 | facedet = omz.faceDetector() 7 | agegen = omz.ageGenderEstimator() 8 | hp = omz.headPoseEstimator() 9 | emo = omz.emotionEstimator() 10 | lm = omz.faceLandmarksEstimator() 11 | 12 | img = cv2.imread('resources/girl.jpg') 13 | detected_faces = facedet.run(img) 14 | 15 | for face in detected_faces: 16 | face_img = omztk.ocv_crop(img, face[3], face[4], scale=1.3) # Crop detected face (x1.3 wider) 17 | landmarks = lm.run(face_img) # Estimate facial landmark points 18 | # Example: landmarks = [(112, 218), (245, 192), (185, 281), (138, 369), (254, 343)] 19 | 20 | face_lmk_img = face_img.copy() # Copy cropped face image to draw markers on it 21 | for lmk in landmarks: 22 | cv2.drawMarker(face_lmk_img, lmk, (255,0,0), markerType=cv2.MARKER_TILTED_CROSS, thickness=4) # Draw markers on landmarks 23 | cv2.imshow('cropped face with landmarks', face_lmk_img) 24 | cv2.waitKey(2 * 1000) # 2 sec # Display cropped face image with landmarks 25 | 26 | yaw, pitch, roll = hp.run(face_img) # Estimate head pose (=head rotation) 27 | # Example: yaw, pitch, roll = -2.6668947, 22.881355, -5.5514703 28 | face_rot_img = omztk.ocv_rotate(face_img, roll) # Correct roll to be upright the face 29 | 30 | age, gender, prob = agegen.run(face_rot_img) # Estimate age and gender 31 | print(age,gender,prob) 32 | # Example: age, gender, prob = 23, female, 0.8204694 33 | emotion = emo.run(face_rot_img) # Estimate emotion 34 | # Example: emotion = 'smile' 35 | 36 | print(age, gender, emotion, landmarks) 37 | 38 | cv2.imshow('cropped and rotated face', face_rot_img) 39 | cv2.waitKey(2 * 1000) # 2 sec 40 | 41 | cv2.rectangle(img, face[3], face[4], (255,0,0), 2) 42 | 43 | cv2.imshow('result', img) 44 | cv2.waitKey(3 * 1000) # 3 sec 45 | -------------------------------------------------------------------------------- /test_humanpose.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import open_model_zoo_toolkit as omztk 3 | 4 | omz = omztk.openvino_omz() 5 | model = omz.humanPoseEstimator() 6 | 7 | #model.setDevice('MYRIAD') 8 | 9 | img = cv2.imread('resources/people.jpg') 10 | res = model.run(img) 11 | print(res) 12 | 13 | omztk.renderPeople(img, res) 14 | cv2.imshow('result', img) 15 | cv2.waitKey(3 * 1000) # 3 sec 16 | -------------------------------------------------------------------------------- /test_object_detection.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import open_model_zoo_toolkit as omztk 3 | 4 | omz = omztk.openvino_omz() 5 | model = omz.objectDetector() # Default model will be used 6 | #model = omz.objectDetector('ssd_mobilenet_v2_coco') # Also, you can select a OMZ model from 'model_def.yml' and use it 7 | 8 | img = cv2.imread('resources/car_1.bmp') 9 | res = model.run(img) 10 | print(res) 11 | # Example: res = [[1, 'person', 0.9291767, (42, 2), (759, 714)]] 12 | 13 | for obj in res: 14 | cv2.rectangle(img, obj[3], obj[4], color=(255,0,0), thickness=2) 15 | cv2.imshow('result', img) 16 | cv2.waitKey(3 * 1000) # 3 seconds -------------------------------------------------------------------------------- /test_text_detection.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import open_model_zoo_toolkit as omztk 4 | 5 | omz = omztk.openvino_omz() 6 | model = omz.textDetector() 7 | 8 | img = cv2.imread('resources/textdet.jpg') 9 | rects, imgs = model.run(img) 10 | print(rects) 11 | 12 | for rect in rects: 13 | box = cv2.boxPoints(rect).astype(np.int32) # Obtain rotated rectangle 14 | cv2.polylines(img, [box], True, (0,255,0), 4) # Draw bounding box 15 | 16 | cv2.imshow('text', img) 17 | key = cv2.waitKey(3 * 1000) # 3 sec 18 | --------------------------------------------------------------------------------