├── .clang-format ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── question.md ├── PULL_REQUEST_TEMPLATE.md ├── labeler.yml └── workflows │ ├── docs.yml │ ├── pr-labeler.yml │ ├── pre_commit.yml │ ├── publish.yaml │ ├── test_accuracy.yml │ └── test_precommit.yml ├── .gitignore ├── .isort.cfg ├── .markdownlint.yaml ├── .pre-commit-config.yaml ├── CONTRIBUTING.md ├── Doxyfile ├── LICENSE ├── README.md ├── SECURITY.md ├── docs ├── Makefile └── source │ ├── conf.py │ ├── cpp │ ├── adapters │ │ └── index.md │ ├── index.md │ ├── models │ │ ├── anomaly_model.md │ │ ├── classification_model.md │ │ ├── detection_model.md │ │ ├── detection_model_ext.md │ │ ├── detection_model_ssd.md │ │ ├── detection_model_yolo.md │ │ ├── detection_model_yolov3_onnx.md │ │ ├── detection_model_yolox.md │ │ ├── image_model.md │ │ ├── index.md │ │ ├── input_data.md │ │ ├── instance_segmentation.md │ │ ├── internal_model_data.md │ │ ├── keypoint_detection.md │ │ ├── model_base.md │ │ ├── results.md │ │ └── segmentation_model.md │ ├── tilers │ │ ├── detection.md │ │ ├── index.md │ │ ├── instance_segmentation.md │ │ ├── semantic_segmentation.md │ │ └── tiler_base.md │ └── utils │ │ ├── args_helper.md │ │ ├── async_infer_queue.md │ │ ├── common.md │ │ ├── image_utils.md │ │ ├── index.md │ │ ├── kuhn_munkres.md │ │ ├── nms.md │ │ ├── ocv_common.md │ │ ├── performance_metrics.md │ │ └── slog.md │ ├── guides │ ├── index.md │ └── model-configuration.md │ ├── index.md │ └── python │ ├── adapters │ ├── index.md │ ├── inference_adapter.md │ ├── onnx_adapter.md │ ├── openvino_adapter.md │ ├── ovms_adapter.md │ └── utils.md │ ├── index.md │ ├── models │ ├── action_classification.md │ ├── anomaly.md │ ├── classification.md │ ├── detection_model.md │ ├── image_model.md │ ├── index.md │ ├── instance_segmentation.md │ ├── keypoint_detection.md │ ├── model.md │ ├── sam_models.md │ ├── segmentation.md │ ├── ssd.md │ ├── types.md │ ├── utils.md │ ├── visual_prompting.md │ └── yolo.md │ ├── pipelines │ ├── async_pipeline.md │ └── index.md │ └── tilers │ ├── detection.md │ ├── index.md │ ├── instance_segmentation.md │ ├── semantic_segmentation.md │ └── tiler.md ├── examples ├── cpp │ ├── CMakeLists.txt │ ├── asynchronous_api │ │ ├── README.md │ │ └── main.cpp │ └── synchronous_api │ │ ├── README.md │ │ └── main.cpp └── python │ ├── __init__.py │ ├── asynchronous_api │ ├── README.md │ └── run.py │ ├── serving_api │ ├── README.md │ └── run.py │ ├── synchronous_api │ ├── README.md │ └── run.py │ ├── visual_prompting │ ├── README.md │ └── run.py │ ├── visualization │ ├── README.md │ └── run.py │ └── zsl_visual_prompting │ ├── README.md │ └── run.py ├── src ├── cpp │ ├── CMakeLists.txt │ ├── adapters │ │ ├── include │ │ │ └── adapters │ │ │ │ ├── inference_adapter.h │ │ │ │ └── openvino_adapter.h │ │ └── src │ │ │ └── openvino_adapter.cpp │ ├── cmake │ │ └── model_apiConfig.cmake │ ├── install_dependencies.sh │ ├── models │ │ ├── include │ │ │ └── models │ │ │ │ ├── anomaly_model.h │ │ │ │ ├── base_model.h │ │ │ │ ├── classification_model.h │ │ │ │ ├── detection_model.h │ │ │ │ ├── detection_model_ext.h │ │ │ │ ├── detection_model_ssd.h │ │ │ │ ├── detection_model_yolo.h │ │ │ │ ├── detection_model_yolov3_onnx.h │ │ │ │ ├── detection_model_yolox.h │ │ │ │ ├── input_data.h │ │ │ │ ├── instance_segmentation.h │ │ │ │ ├── internal_model_data.h │ │ │ │ ├── keypoint_detection.h │ │ │ │ ├── results.h │ │ │ │ └── segmentation_model.h │ │ └── src │ │ │ ├── anomaly_model.cpp │ │ │ ├── base_model.cpp │ │ │ ├── classification_model.cpp │ │ │ ├── detection_model.cpp │ │ │ ├── detection_model_ext.cpp │ │ │ ├── detection_model_ssd.cpp │ │ │ ├── detection_model_yolo.cpp │ │ │ ├── detection_model_yolov3_onnx.cpp │ │ │ ├── detection_model_yolox.cpp │ │ │ ├── instance_segmentation.cpp │ │ │ ├── keypoint_detection.cpp │ │ │ └── segmentation_model.cpp │ ├── py_bindings │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── pyproject.toml │ │ └── src │ │ │ └── vision_api │ │ │ ├── __init__.py │ │ │ ├── py_base.cpp │ │ │ ├── py_classification.cpp │ │ │ ├── py_utils.cpp │ │ │ ├── py_utils.hpp │ │ │ └── py_vision_api.cpp │ ├── tilers │ │ ├── include │ │ │ └── tilers │ │ │ │ ├── detection.h │ │ │ │ ├── instance_segmentation.h │ │ │ │ ├── semantic_segmentation.h │ │ │ │ └── tiler_base.h │ │ └── src │ │ │ ├── detection.cpp │ │ │ ├── instance_segmentation.cpp │ │ │ ├── semantic_segmentation.cpp │ │ │ └── tiler_base.cpp │ └── utils │ │ ├── include │ │ └── utils │ │ │ ├── args_helper.hpp │ │ │ ├── async_infer_queue.hpp │ │ │ ├── common.hpp │ │ │ ├── image_utils.h │ │ │ ├── kuhn_munkres.hpp │ │ │ ├── nms.hpp │ │ │ ├── ocv_common.hpp │ │ │ ├── performance_metrics.hpp │ │ │ └── slog.hpp │ │ └── src │ │ ├── args_helper.cpp │ │ ├── async_infer_queue.cpp │ │ ├── image_utils.cpp │ │ ├── kuhn_munkres.cpp │ │ └── nms.cpp └── python │ ├── README.md │ ├── docs │ ├── action_classification.md │ ├── keypoint_detection.md │ └── visual_prompting.md │ ├── model_api │ ├── __init__.py │ ├── adapters │ │ ├── __init__.py │ │ ├── inference_adapter.py │ │ ├── onnx_adapter.md │ │ ├── onnx_adapter.py │ │ ├── openvino_adapter.py │ │ ├── ovms_adapter.md │ │ ├── ovms_adapter.py │ │ └── utils.py │ ├── models │ │ ├── __init__.py │ │ ├── action_classification.py │ │ ├── anomaly.py │ │ ├── classification.py │ │ ├── detection_model.py │ │ ├── image_model.py │ │ ├── instance_segmentation.py │ │ ├── keypoint_detection.py │ │ ├── model.py │ │ ├── result │ │ │ ├── __init__.py │ │ │ ├── anomaly.py │ │ │ ├── base.py │ │ │ ├── classification.py │ │ │ ├── detection.py │ │ │ ├── keypoint.py │ │ │ ├── segmentation.py │ │ │ ├── utils.py │ │ │ └── visual_prompting.py │ │ ├── sam_models.py │ │ ├── segmentation.py │ │ ├── ssd.py │ │ ├── types.py │ │ ├── utils.py │ │ ├── visual_prompting.py │ │ └── yolo.py │ ├── performance_metrics.py │ ├── pipelines │ │ ├── __init__.py │ │ └── async_pipeline.py │ ├── tilers │ │ ├── __init__.py │ │ ├── detection.py │ │ ├── instance_segmentation.py │ │ ├── semantic_segmentation.py │ │ └── tiler.py │ └── visualizer │ │ ├── __init__.py │ │ ├── layout │ │ ├── __init__.py │ │ ├── flatten.py │ │ ├── hstack.py │ │ └── layout.py │ │ ├── primitive │ │ ├── __init__.py │ │ ├── bounding_box.py │ │ ├── keypoints.py │ │ ├── label.py │ │ ├── overlay.py │ │ ├── polygon.py │ │ └── primitive.py │ │ ├── scene │ │ ├── __init__.py │ │ ├── anomaly.py │ │ ├── classification.py │ │ ├── detection.py │ │ ├── keypoint.py │ │ ├── scene.py │ │ ├── segmentation │ │ │ ├── __init__.py │ │ │ ├── instance_segmentation.py │ │ │ └── segmentation.py │ │ └── visual_prompting.py │ │ └── visualizer.py │ └── pyproject.toml └── tests ├── cpp ├── accuracy │ ├── CMakeLists.txt │ ├── conftest.py │ ├── test_YOLOv8.cpp │ ├── test_accuracy.cpp │ └── test_bindings.py ├── cmake │ └── common.cmake └── precommit │ ├── CMakeLists.txt │ ├── prepare_data.py │ ├── public_scope.json │ ├── test_model_config.cpp │ └── test_sanity.cpp └── python ├── accuracy ├── __init__.py ├── conftest.py ├── prepare_data.py ├── public_scope.json ├── test_YOLOv8.py └── test_accuracy.py ├── functional ├── __init__.py ├── conftest.py ├── test_load.py └── test_save.py ├── precommit └── __init__.py └── unit ├── results ├── test_cls_result.py └── test_det_result.py ├── test_utils.py └── visualizer ├── __init__.py ├── conftest.py ├── test_layout.py ├── test_primitive.py └── test_scene.py /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | IndentWidth: 4 3 | UseTab: Never 4 | ColumnLimit: 120 5 | 6 | Language: Cpp 7 | Standard: Cpp11 8 | 9 | AccessModifierOffset: -4 10 | AlignConsecutiveMacros: true 11 | AllowAllArgumentsOnNextLine: false 12 | AllowAllConstructorInitializersOnNextLine: false 13 | AllowAllParametersOfDeclarationOnNextLine: false 14 | AllowShortFunctionsOnASingleLine: Empty 15 | AllowShortIfStatementsOnASingleLine: Never 16 | AllowShortLambdasOnASingleLine: Empty 17 | AllowShortLoopsOnASingleLine: false 18 | AlwaysBreakBeforeMultilineStrings: false 19 | BinPackArguments: false 20 | BinPackParameters: false 21 | CommentPragmas: "^#" 22 | DerivePointerAlignment: false 23 | FixNamespaceComments: true 24 | IndentCaseLabels: false 25 | IndentPPDirectives: AfterHash 26 | ForEachMacros: 27 | - foreach 28 | - FOREACH_CHILD 29 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @open-edge-platform/model_api-maintain 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "" 5 | labels: bug 6 | assignees: "" 7 | --- 8 | 9 | 12 | 13 | ### Describe the bug 14 | 15 | 20 | 21 | ### Steps to Reproduce 22 | 23 | 1. 24 | 2. 25 | 3. 26 | 4. 27 | 28 | ### Environment 29 | 30 | - OS: 31 | - OpenVINO version: 32 | - Inference device model and memory: 33 | 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "" 5 | labels: enhancement 6 | assignees: "" 7 | --- 8 | 9 | 12 | 13 | ### Is your feature request related to a problem? Please describe 14 | 15 | 18 | 19 | ### Describe the solution you'd like to propose 20 | 21 | 24 | 25 | ### Describe alternatives you've considered 26 | 27 | 30 | 31 | ### Additional context 32 | 33 | 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Ask any question about this repository 4 | title: "" 5 | labels: question 6 | assignees: "" 7 | --- 8 | 9 | 14 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # What does this PR do? 2 | 3 | 12 | 13 | 14 | 15 | Fixes # (issue) 16 | 17 | ## Before submitting 18 | 19 | - [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). 20 | - [ ] Did you make sure to update the documentation with your changes? 21 | - [ ] Did you write any new necessary tests? 22 | -------------------------------------------------------------------------------- /.github/labeler.yml: -------------------------------------------------------------------------------- 1 | # See help here: https://github.com/marketplace/actions/labeler 2 | 3 | cpp: 4 | - changed-files: 5 | - any-glob-to-any-file: 6 | - src/cpp/** 7 | 8 | python: 9 | - changed-files: 10 | - any-glob-to-any-file: 11 | - src/python/** 12 | 13 | tests: 14 | - changed-files: 15 | - any-glob-to-any-file: 16 | - tests/** 17 | 18 | docs: 19 | - changed-files: 20 | - any-glob-to-any-file: 21 | - docs/** 22 | - "**/*.md" 23 | - "LICENSE" 24 | 25 | build: 26 | - changed-files: 27 | - any-glob-to-any-file: 28 | - ".github/**/*" 29 | - ".pre-commit-config.yaml" 30 | - "pyproject.toml" 31 | - "**/CMakeLists.txt" 32 | 33 | samples: 34 | - changed-files: 35 | - any-glob-to-any-file: 36 | - examples/** 37 | -------------------------------------------------------------------------------- /.github/workflows/pr-labeler.yml: -------------------------------------------------------------------------------- 1 | name: "Pull Request Labeler" 2 | permissions: read-all 3 | on: 4 | - pull_request_target 5 | 6 | jobs: 7 | labeler: 8 | permissions: 9 | contents: read 10 | pull-requests: write 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/labeler@v5 14 | with: 15 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 16 | -------------------------------------------------------------------------------- /.github/workflows/pre_commit.yml: -------------------------------------------------------------------------------- 1 | name: Pre-Commit Checks 2 | permissions: read-all 3 | 4 | on: 5 | push: 6 | branches: 7 | - master 8 | pull_request: 9 | types: 10 | - opened 11 | - reopened 12 | - synchronize 13 | - ready_for_review 14 | workflow_dispatch: # run on request (no need for PR) 15 | 16 | jobs: 17 | Code-Quality-Checks: 18 | runs-on: ubuntu-22.04 19 | steps: 20 | - name: CHECKOUT REPOSITORY 21 | uses: actions/checkout@v4 22 | - name: Set up Python 23 | uses: actions/setup-python@v5 24 | with: 25 | python-version: "3.10" 26 | - name: Set up Node.js 27 | uses: actions/setup-node@v4 28 | with: 29 | node-version: 22 30 | - name: Install clang-format 31 | run: sudo apt-get install -y clang-format-13 32 | - name: Install dependencies 33 | run: pip install 'src/python/.[full]' 34 | - name: Run pre-commit checks 35 | run: pre-commit run --all-files 36 | Unit-Tests: 37 | runs-on: ubuntu-22.04 38 | steps: 39 | - name: CHECKOUT REPOSITORY 40 | uses: actions/checkout@v4 41 | - name: Set up Python 42 | uses: actions/setup-python@v5 43 | with: 44 | python-version: "3.9" 45 | - name: Install dependencies 46 | run: pip install 'src/python/.[tests,ovms]' 47 | - name: Run python unit tests 48 | run: pytest tests/python/unit 49 | -------------------------------------------------------------------------------- /.github/workflows/publish.yaml: -------------------------------------------------------------------------------- 1 | name: Build and upload to PyPI 2 | 3 | on: 4 | workflow_dispatch: # run on request (no need for PR) 5 | release: 6 | types: [published] 7 | 8 | # Declare default permissions as read only. 9 | permissions: read-all 10 | 11 | jobs: 12 | build: 13 | name: Build 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v4 18 | - name: Set up Python 3.10 19 | uses: actions/setup-python@v5 20 | with: 21 | python-version: "3.10" 22 | - name: Install pypa/build 23 | run: | 24 | python -m pip install --upgrade build 25 | - name: Build sdist 26 | run: | 27 | python -m build --sdist src/python/ 28 | - uses: actions/upload-artifact@v4 29 | with: 30 | name: artifact-sdist 31 | path: src/python/dist/*.tar.gz 32 | - name: Build wheel 33 | run: | 34 | python -m build --wheel src/python/ 35 | - uses: actions/upload-artifact@v4 36 | with: 37 | name: artifact-wheel 38 | path: src/python/dist/*.whl 39 | 40 | publish_package: 41 | name: Publish package 42 | needs: [build] 43 | environment: pypi 44 | runs-on: ubuntu-latest 45 | permissions: 46 | packages: write 47 | contents: write 48 | id-token: write 49 | steps: 50 | - name: Download artifacts 51 | uses: actions/download-artifact@v4 52 | with: 53 | path: dist 54 | pattern: artifact-* 55 | merge-multiple: true 56 | # to determine where to publish the package distribution to PyPI or TestPyPI 57 | - name: Check tag 58 | id: check-tag 59 | uses: actions-ecosystem/action-regex-match@v2 60 | with: 61 | text: ${{ github.ref }} 62 | regex: '^refs/tags/[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)+(\.[0-9]+rc[0-9]+|rc[0-9]+)?$' 63 | - name: Upload package distributions to github 64 | if: ${{ steps.check-tag.outputs.match != '' }} 65 | uses: svenstaro/upload-release-action@04733e069f2d7f7f0b4aebc4fbdbce8613b03ccd # v2 66 | with: 67 | repo_token: ${{ secrets.GITHUB_TOKEN }} 68 | file: dist/* 69 | tag: ${{ github.ref }} 70 | overwrite: true 71 | file_glob: true 72 | - name: Publish package distributions to PyPI 73 | if: ${{ steps.check-tag.outputs.match != '' }} 74 | uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3 75 | - name: Publish package distributions to TestPyPI 76 | if: ${{ steps.check-tag.outputs.match == '' }} 77 | uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3 78 | with: 79 | repository-url: https://test.pypi.org/legacy/ 80 | verbose: true 81 | -------------------------------------------------------------------------------- /.github/workflows/test_accuracy.yml: -------------------------------------------------------------------------------- 1 | name: test_accuracy 2 | permissions: read-all 3 | on: 4 | pull_request: 5 | merge_group: 6 | branches: 7 | - master 8 | concurrency: 9 | group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} 10 | cancel-in-progress: true 11 | jobs: 12 | test_accuracy: 13 | runs-on: ubuntu-22.04 14 | steps: 15 | - uses: actions/checkout@v3 16 | - uses: actions/setup-python@v4 17 | with: 18 | python-version: "3.12" 19 | cache: pip 20 | - name: Create and start a virtual environment 21 | run: | 22 | python -m venv venv 23 | source venv/bin/activate 24 | - name: Install dependencies 25 | run: | 26 | source venv/bin/activate 27 | python -m pip install --upgrade pip 28 | pip install src/python/[tests,build] --extra-index-url https://download.pytorch.org/whl/cpu 29 | - name: Prepare test data 30 | run: | 31 | source venv/bin/activate 32 | python tests/python/accuracy/prepare_data.py -d data 33 | - name: Run Python Test 34 | run: | 35 | source venv/bin/activate 36 | pytest --data=./data tests/python/accuracy/test_accuracy.py 37 | - name: Install CPP dependencies 38 | run: | 39 | sudo bash src/cpp/install_dependencies.sh 40 | - name: Build CPP Test 41 | run: | 42 | mkdir build && cd build 43 | pip install nanobind==2.4.0 44 | pip install typing_extensions==4.12.2 45 | cmake ../tests/cpp/accuracy/ 46 | make -j 47 | - name: Build CPP-PY Bindings 48 | run: | 49 | source venv/bin/activate 50 | pip install src/cpp/py_bindings 51 | - name: Run CPP Test 52 | run: | 53 | build/test_accuracy -d data -p tests/python/accuracy/public_scope.json 54 | - name: Run CPP-PY Bindings Test 55 | run: | 56 | source venv/bin/activate 57 | pip list 58 | pytest --data=./data --config=./tests/python/accuracy/public_scope.json tests/cpp/accuracy/test_bindings.py 59 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by examples/python/synchronous_api/run.py 2 | mask.png 3 | ssd_mobilenet_v1_fpn_coco_with_preprocessing.xml 4 | ssd_mobilenet_v1_fpn_coco_with_preprocessing.bin 5 | tmp/ 6 | # Generated by tests/python/accuracy/test_accuracy.py 7 | test_scope.json 8 | 9 | # Byte-compiled / optimized / DLL files 10 | __pycache__/ 11 | *.py[cod] 12 | *$py.class 13 | 14 | # C extensions 15 | *.so 16 | 17 | # Distribution / packaging 18 | .Python 19 | build/ 20 | develop-eggs/ 21 | dist/ 22 | downloads/ 23 | eggs/ 24 | .eggs/ 25 | lib/ 26 | lib64/ 27 | parts/ 28 | sdist/ 29 | var/ 30 | wheels/ 31 | pip-wheel-metadata/ 32 | share/python-wheels/ 33 | *.egg-info/ 34 | .installed.cfg 35 | *.egg 36 | MANIFEST 37 | 38 | # PyInstaller 39 | # Usually these files are written by a python script from a template 40 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 41 | *.manifest 42 | *.spec 43 | 44 | # Installer logs 45 | pip-log.txt 46 | pip-delete-this-directory.txt 47 | 48 | # Unit test / coverage reports 49 | htmlcov/ 50 | .tox/ 51 | .nox/ 52 | .coverage 53 | .coverage.* 54 | .cache 55 | nosetests.xml 56 | coverage.xml 57 | *.cover 58 | *.py,cover 59 | .hypothesis/ 60 | .pytest_cache/ 61 | 62 | # Translations 63 | *.mo 64 | *.pot 65 | 66 | # Django stuff: 67 | *.log 68 | local_settings.py 69 | db.sqlite3 70 | db.sqlite3-journal 71 | 72 | # Flask stuff: 73 | instance/ 74 | .webassets-cache 75 | 76 | # Scrapy stuff: 77 | .scrapy 78 | 79 | # Sphinx documentation 80 | docs/_build/ 81 | 82 | # PyBuilder 83 | target/ 84 | 85 | # Jupyter Notebook 86 | .ipynb_checkpoints 87 | 88 | # IPython 89 | profile_default/ 90 | ipython_config.py 91 | 92 | # pyenv 93 | .python-version 94 | 95 | # pipenv 96 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 97 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 98 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 99 | # install all needed dependencies. 100 | #Pipfile.lock 101 | 102 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 103 | __pypackages__/ 104 | 105 | # Celery stuff 106 | celerybeat-schedule 107 | celerybeat.pid 108 | 109 | # SageMath parsed files 110 | *.sage.py 111 | 112 | # Environments 113 | .env 114 | .venv 115 | env/ 116 | venv/ 117 | ENV/ 118 | env.bak/ 119 | venv.bak/ 120 | 121 | # Spyder project settings 122 | .spyderproject 123 | .spyproject 124 | 125 | # Rope project settings 126 | .ropeproject 127 | 128 | # mkdocs documentation 129 | /site 130 | 131 | # mypy 132 | .mypy_cache/ 133 | .dmypy.json 134 | dmypy.json 135 | 136 | # Pyre type checker 137 | .pyre/ 138 | 139 | # Sphinx documentation 140 | docs/build/ 141 | docs/build_cpp/ 142 | docs/source/_build/ 143 | 144 | # vs-code 145 | .vscode/ 146 | -------------------------------------------------------------------------------- /.isort.cfg: -------------------------------------------------------------------------------- 1 | [settings] 2 | profile = black 3 | extend_skip = model_api/python/openvino/__init__.py 4 | -------------------------------------------------------------------------------- /.markdownlint.yaml: -------------------------------------------------------------------------------- 1 | # Default state for all rules 2 | default: true 3 | 4 | # Path to configuration file to extend 5 | extends: null 6 | 7 | # MD001/heading-increment/header-increment - Heading levels should only increment by one level at a time 8 | MD001: true 9 | 10 | # MD013/line-length - Line length 11 | MD013: 12 | # Number of characters 13 | line_length: 1000 14 | 15 | # This is not useful for some files such as `CHANGELOG.md` 16 | MD024: 17 | # Only check sibling headings 18 | siblings_only: true 19 | 20 | MD033: false 21 | 22 | # If a page is printed, it helps if the URL is viewable. 23 | MD034: false # Bare URL used 24 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | default_language_version: 2 | node: 22.10.0 3 | 4 | repos: 5 | - repo: https://github.com/pre-commit/pre-commit-hooks 6 | rev: v4.6.0 7 | hooks: 8 | # list of supported hooks: https://pre-commit.com/hooks.html 9 | - id: trailing-whitespace 10 | - id: end-of-file-fixer 11 | - id: check-yaml 12 | - id: check-added-large-files 13 | - id: debug-statements 14 | - id: detect-private-key 15 | 16 | # Ruff version. 17 | - repo: https://github.com/charliermarsh/ruff-pre-commit 18 | rev: "v0.6.2" 19 | hooks: 20 | # Run the linter. 21 | - id: ruff 22 | args: ["--fix"] 23 | # Run the formatter 24 | - id: ruff-format 25 | 26 | # python static type checking 27 | - repo: https://github.com/pre-commit/mirrors-mypy 28 | rev: "v1.11.2" 29 | hooks: 30 | - id: mypy 31 | additional_dependencies: [types-PyYAML, types-setuptools] 32 | 33 | - repo: https://github.com/pre-commit/mirrors-prettier 34 | rev: v4.0.0-alpha.8 35 | hooks: 36 | - id: prettier 37 | 38 | - repo: https://github.com/igorshubovych/markdownlint-cli 39 | rev: v0.41.0 40 | hooks: 41 | - id: markdownlint 42 | 43 | # C++ code quality 44 | - repo: https://github.com/cpp-linter/cpp-linter-hooks 45 | rev: v0.5.1 46 | hooks: 47 | - id: clang-format 48 | args: [--style=file, --version=13] 49 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. 4 | 5 | ## Reporting a Vulnerability 6 | 7 | Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). 8 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # For the full list of built-in configuration values, see the documentation: 4 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 5 | 6 | # -- Project information ----------------------------------------------------- 7 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information 8 | 9 | import sys 10 | from pathlib import Path 11 | 12 | # Define the path to your module using Path 13 | module_path = Path(__file__).parent.parent / "src" / "python" 14 | 15 | # Insert the path to sys.path 16 | sys.path.insert(0, str(module_path.resolve())) 17 | 18 | project = "ModelAPI" 19 | copyright = "2025, Intel" 20 | author = "Intel" 21 | release = "2025" 22 | 23 | # -- General configuration --------------------------------------------------- 24 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration 25 | 26 | extensions = [ 27 | "breathe", 28 | "sphinx.ext.autodoc", 29 | "sphinx.ext.mathjax", 30 | "sphinx_design", 31 | "myst_parser", 32 | "nbsphinx", 33 | "sphinx.ext.napoleon", 34 | "sphinx_autodoc_typehints", 35 | "sphinx_copybutton", 36 | "sphinx.ext.graphviz", 37 | ] 38 | 39 | myst_enable_extensions = [ 40 | "colon_fence", 41 | # other MyST extensions... 42 | ] 43 | 44 | templates_path = ["_templates"] 45 | exclude_patterns: list[str] = [] 46 | 47 | # Automatic exclusion of prompts from the copies 48 | # https://sphinx-copybutton.readthedocs.io/en/latest/use.html#automatic-exclusion-of-prompts-from-the-copies 49 | copybutton_exclude = ".linenos, .gp, .go" 50 | 51 | # -- Options for HTML output ------------------------------------------------- 52 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output 53 | 54 | html_theme = "pydata_sphinx_theme" 55 | html_static_path = ["_static"] 56 | 57 | breathe_projects = {"InferenceSDK": Path(__file__).parent.parent / "build_cpp" / "xml"} 58 | breathe_default_project = "InferenceSDK" 59 | breathe_default_members = ("members", "undoc-members", "private-members") 60 | 61 | autodoc_docstring_signature = True 62 | autodoc_member_order = "bysource" 63 | intersphinx_mapping = { 64 | "python": ("https://docs.python.org/3", None), 65 | "numpy": ("https://numpy.org/doc/stable/", None), 66 | } 67 | autodoc_member_order = "groupwise" 68 | autodoc_default_options = { 69 | "members": True, 70 | "methods": True, 71 | "special-members": "__call__", 72 | "exclude-members": "_abc_impl", 73 | "show-inheritance": True, 74 | } 75 | 76 | autoclass_content = "both" 77 | 78 | autosummary_generate = True # Turn on sphinx.ext.autosummary 79 | -------------------------------------------------------------------------------- /docs/source/cpp/adapters/index.md: -------------------------------------------------------------------------------- 1 | # Adapters 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: InferenceAdapter 5 | 6 | ``` 7 | 8 | ```{eval-rst} 9 | .. doxygenclass:: OpenVINOInferenceAdapter 10 | 11 | ``` 12 | -------------------------------------------------------------------------------- /docs/source/cpp/index.md: -------------------------------------------------------------------------------- 1 | # C++ API Reference 2 | 3 | ::::{grid} 1 2 2 3 4 | :margin: 1 1 0 0 5 | :gutter: 1 6 | 7 | :::{grid-item-card} {octicon}`plug` Adapters 8 | :link: ./adapters/index 9 | :link-type: doc 10 | 11 | Adapters description[todo] 12 | ::: 13 | 14 | :::{grid-item-card} {octicon}`dependabot` Models 15 | :link: ./models/index 16 | :link-type: doc 17 | 18 | Models description[todo] 19 | ::: 20 | 21 | :::{grid-item-card} {octicon}`versions` Tilers 22 | :link: ./tilers/index 23 | :link-type: doc 24 | 25 | Tilers description[todo] 26 | ::: 27 | 28 | :::{grid-item-card} {octicon}`tools` Utils 29 | :link: ./utils/index 30 | :link-type: doc 31 | 32 | Utils description[todo] 33 | ::: 34 | 35 | :::: 36 | 37 | ```{toctree} 38 | :caption: Classes 39 | :hidden: 40 | 41 | adapters/index 42 | models/index 43 | tilers/index 44 | utils/index 45 | ``` 46 | -------------------------------------------------------------------------------- /docs/source/cpp/models/anomaly_model.md: -------------------------------------------------------------------------------- 1 | # Anomaly Model 2 | 3 | The `AnomalyModel` is a generic OpenVINO model that aims to provide a single interface for all the exported models based on [Anomalib](https://github.com/open-edge-platform/anomalib). 4 | 5 | Currently, the `AnomalyModel` supports the following models: 6 | 7 | - Padim 8 | - STFPM 9 | 10 | ```{eval-rst} 11 | .. doxygenclass:: AnomalyModel 12 | 13 | ``` 14 | -------------------------------------------------------------------------------- /docs/source/cpp/models/classification_model.md: -------------------------------------------------------------------------------- 1 | # Classification Model 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: ClassificationModel 5 | 6 | ``` 7 | 8 | ## Probabilistic Labels Resolver 9 | 10 | ```{eval-rst} 11 | .. doxygenclass:: ProbabilisticLabelsResolver 12 | 13 | ``` 14 | 15 | ## Greedy Labels Resolver 16 | 17 | ```{eval-rst} 18 | .. doxygenclass:: GreedyLabelsResolver 19 | 20 | ``` 21 | 22 | ## Simple Labels Graph 23 | 24 | ```{eval-rst} 25 | .. doxygenclass:: SimpleLabelsGraph 26 | 27 | ``` 28 | -------------------------------------------------------------------------------- /docs/source/cpp/models/detection_model.md: -------------------------------------------------------------------------------- 1 | # Detection Model 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: DetectionModel 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/models/detection_model_ext.md: -------------------------------------------------------------------------------- 1 | # Detection Model Ext 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: DetectionModelExt 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/models/detection_model_ssd.md: -------------------------------------------------------------------------------- 1 | # Detection Model SSD 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: ModelSSD 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/models/detection_model_yolo.md: -------------------------------------------------------------------------------- 1 | # Detection Model Yolo 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: ModelYolo 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/models/detection_model_yolov3_onnx.md: -------------------------------------------------------------------------------- 1 | # Detection Model Yolov3 ONNX 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: ModelYoloV3ONNX 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/models/detection_model_yolox.md: -------------------------------------------------------------------------------- 1 | # Detection Model YoloX 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: ModelYoloX 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/models/image_model.md: -------------------------------------------------------------------------------- 1 | # Image Model 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: ImageModel 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/models/index.md: -------------------------------------------------------------------------------- 1 | # Models 2 | 3 | ::::{grid} 1 2 2 3 4 | :margin: 1 1 0 0 5 | :gutter: 1 6 | 7 | :::{grid-item-card} Model Base 8 | :link: ./model_base 9 | :link-type: doc 10 | 11 | [todo] 12 | ::: 13 | 14 | :::{grid-item-card} Detection Model 15 | :link: ./detection_model 16 | :link-type: doc 17 | 18 | [todo] 19 | ::: 20 | 21 | :::{grid-item-card} Image Model 22 | :link: ./image_model 23 | :link-type: doc 24 | 25 | [todo] 26 | ::: 27 | :::{grid-item-card} Internal Model Data 28 | :link: ./internal_model_data 29 | :link-type: doc 30 | 31 | [todo] 32 | ::: 33 | :::{grid-item-card} Keypoint Detection 34 | :link: ./keypoint_detection 35 | :link-type: doc 36 | 37 | [todo] 38 | ::: 39 | 40 | :::{grid-item-card} Detection Model Yolov3 ONNX 41 | :link: ./detection_model_yolov3_onnx 42 | :link-type: doc 43 | 44 | [todo] 45 | ::: 46 | :::{grid-item-card} Anomaly Model 47 | :link: ./anomaly_model 48 | :link-type: doc 49 | 50 | [todo] 51 | ::: 52 | :::{grid-item-card} Detection Model Ext 53 | :link: ./detection_model_ext 54 | :link-type: doc 55 | 56 | [todo] 57 | ::: 58 | :::{grid-item-card} Segmentation Model 59 | :link: ./segmentation_model 60 | :link-type: doc 61 | 62 | [todo] 63 | ::: 64 | :::{grid-item-card} Detection Model YoloX 65 | :link: ./detection_model_yolox 66 | :link-type: doc 67 | 68 | [todo] 69 | ::: 70 | :::{grid-item-card} Detection Model SSD 71 | :link: ./detection_model_ssd 72 | :link-type: doc 73 | 74 | [todo] 75 | ::: 76 | 77 | :::{grid-item-card} Results 78 | :link: ./results 79 | :link-type: doc 80 | 81 | [todo] 82 | ::: 83 | 84 | :::{grid-item-card} Instance Segmentation 85 | :link: ./instance_segmentation 86 | :link-type: doc 87 | 88 | [todo] 89 | ::: 90 | :::{grid-item-card} Input Data 91 | :link: ./input_data 92 | :link-type: doc 93 | 94 | [todo] 95 | ::: 96 | 97 | :::{grid-item-card} Detection Model YOLO 98 | :link: ./detection_model_yolo 99 | :link-type: doc 100 | 101 | [todo] 102 | ::: 103 | :::{grid-item-card} Classification Model 104 | :link: ./classification_model 105 | :link-type: doc 106 | 107 | [todo] 108 | ::: 109 | 110 | :::: 111 | 112 | ```{toctree} 113 | :caption: Models 114 | :hidden: 115 | 116 | ./model_base 117 | ./detection_model 118 | ./image_model 119 | ./internal_model_data 120 | ./keypoint_detection 121 | ./detection_model_yolov3_onnx 122 | ./anomaly_model 123 | ./detection_model_ext 124 | ./segmentation_model 125 | ./detection_model_yolox 126 | ./detection_model_ssd 127 | ./results 128 | ./instance_segmentation 129 | ./input_data 130 | ./detection_model_yolo 131 | ./classification_model 132 | 133 | ``` 134 | -------------------------------------------------------------------------------- /docs/source/cpp/models/input_data.md: -------------------------------------------------------------------------------- 1 | # Input Data 2 | 3 | ```{eval-rst} 4 | .. doxygenstruct:: InputData 5 | 6 | ``` 7 | 8 | ## ImageInput Data 9 | 10 | ```{eval-rst} 11 | .. doxygenstruct:: ImageInputData 12 | 13 | ``` 14 | -------------------------------------------------------------------------------- /docs/source/cpp/models/instance_segmentation.md: -------------------------------------------------------------------------------- 1 | # Instance Segmentation 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: MaskRCNNModel 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/models/internal_model_data.md: -------------------------------------------------------------------------------- 1 | # Internal Model Data 2 | 3 | ```{eval-rst} 4 | .. doxygenstruct:: InternalModelData 5 | 6 | ``` 7 | 8 | ## InternamImageModelData 9 | 10 | ```{eval-rst} 11 | .. doxygenstruct:: InternalImageModelData 12 | 13 | ``` 14 | 15 | ## InternalScaleData 16 | 17 | ```{eval-rst} 18 | .. doxygenstruct:: InternalScaleData 19 | 20 | ``` 21 | -------------------------------------------------------------------------------- /docs/source/cpp/models/keypoint_detection.md: -------------------------------------------------------------------------------- 1 | # Keypoint Detection 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: KeypointDetectionModel 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/models/model_base.md: -------------------------------------------------------------------------------- 1 | # Model Base 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: ModelBase 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/models/results.md: -------------------------------------------------------------------------------- 1 | # Results 2 | 3 | ## Result Base 4 | 5 | ```{eval-rst} 6 | .. doxygenstruct:: ResultBase 7 | 8 | ``` 9 | 10 | ## Anomaly Result 11 | 12 | ```{eval-rst} 13 | .. doxygenstruct:: AnomalyResult 14 | 15 | ``` 16 | 17 | ## Inference Result 18 | 19 | ```{eval-rst} 20 | .. doxygenstruct:: InferenceResult 21 | 22 | ``` 23 | 24 | ## Classification Result 25 | 26 | ```{eval-rst} 27 | .. doxygenstruct:: ClassificationResult 28 | 29 | ``` 30 | 31 | ## Detected Object 32 | 33 | ```{eval-rst} 34 | .. doxygenstruct:: DetectedObject 35 | 36 | ``` 37 | 38 | ## Detection Result 39 | 40 | ```{eval-rst} 41 | .. doxygenstruct:: DetectionResult 42 | 43 | ``` 44 | 45 | ## RetinaFace Detection Result 46 | 47 | ```{eval-rst} 48 | .. doxygenstruct:: RetinaFaceDetectionResult 49 | 50 | ``` 51 | 52 | ## ResultBase 53 | 54 | ```{eval-rst} 55 | .. doxygenstruct:: ResultBase 56 | 57 | ``` 58 | 59 | ## Segmented Object 60 | 61 | ```{eval-rst} 62 | .. doxygenstruct:: SegmentedObject 63 | 64 | ``` 65 | 66 | ## Segmented Object With Rects 67 | 68 | ```{eval-rst} 69 | .. doxygenstruct:: SegmentedObjectWithRects 70 | 71 | ``` 72 | 73 | ## Instance Segmentation Result 74 | 75 | ```{eval-rst} 76 | .. doxygenstruct:: InstanceSegmentationResult 77 | 78 | ``` 79 | 80 | ## Image Result 81 | 82 | ```{eval-rst} 83 | .. doxygenstruct:: ImageResult 84 | 85 | ``` 86 | 87 | ## ImageResult With Soft Prediction 88 | 89 | ```{eval-rst} 90 | .. doxygenstruct:: ImageResultWithSoftPrediction 91 | 92 | ``` 93 | 94 | ## Contour 95 | 96 | ```{eval-rst} 97 | .. doxygenstruct:: Contour 98 | 99 | ``` 100 | 101 | ## HumanPose 102 | 103 | ```{eval-rst} 104 | .. doxygenstruct:: HumanPose 105 | 106 | ``` 107 | 108 | ## HumanPoseResult 109 | 110 | ```{eval-rst} 111 | .. doxygenstruct:: HumanPoseResult 112 | 113 | ``` 114 | 115 | ## DetectedKeypoints 116 | 117 | ```{eval-rst} 118 | .. doxygenstruct:: DetectedKeypoints 119 | 120 | ``` 121 | 122 | ## KeypointDetectionResult 123 | 124 | ```{eval-rst} 125 | .. doxygenstruct:: KeypointDetectionResult 126 | 127 | ``` 128 | -------------------------------------------------------------------------------- /docs/source/cpp/models/segmentation_model.md: -------------------------------------------------------------------------------- 1 | # Segmentation Model 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: SegmentationModel 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/tilers/detection.md: -------------------------------------------------------------------------------- 1 | # Detection 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: DetectionTiler 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/tilers/index.md: -------------------------------------------------------------------------------- 1 | # Tilers 2 | 3 | ::::{grid} 1 2 2 3 4 | :margin: 1 1 0 0 5 | :gutter: 1 6 | 7 | :::{grid-item-card} Tiler Base 8 | :link: ./tiler_base 9 | :link-type: doc 10 | 11 | [todo] 12 | ::: 13 | :::{grid-item-card} Instance Segmentation 14 | :link: ./instance_segmentation 15 | :link-type: doc 16 | 17 | [todo] 18 | ::: 19 | :::{grid-item-card} Detection 20 | :link: ./detection 21 | :link-type: doc 22 | 23 | [todo] 24 | ::: 25 | :::{grid-item-card} Semantic Segmentation 26 | :link: ./semantic_segmentation 27 | :link-type: doc 28 | 29 | [todo] 30 | ::: 31 | 32 | :::: 33 | 34 | ```{toctree} 35 | :caption: Tilers 36 | :hidden: 37 | 38 | ./tiler_base 39 | ./instance_segmentation 40 | ./detection 41 | ./semantic_segmentation 42 | ``` 43 | -------------------------------------------------------------------------------- /docs/source/cpp/tilers/instance_segmentation.md: -------------------------------------------------------------------------------- 1 | # Instance Segmentation 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: InstanceSegmentationTiler 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/tilers/semantic_segmentation.md: -------------------------------------------------------------------------------- 1 | # Semantic Segmentation 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: SemanticSegmentationTiler 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/tilers/tiler_base.md: -------------------------------------------------------------------------------- 1 | # Tiler Base 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: TilerBase 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/utils/args_helper.md: -------------------------------------------------------------------------------- 1 | # Args Helper 2 | 3 | ```{eval-rst} 4 | .. doxygenfile:: args_helper.hpp 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/utils/async_infer_queue.md: -------------------------------------------------------------------------------- 1 | # Async Infer Queue 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: AsyncInferQueue 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/utils/common.md: -------------------------------------------------------------------------------- 1 | # Common 2 | 3 | ```{eval-rst} 4 | .. doxygenfile:: common.hpp 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/utils/image_utils.md: -------------------------------------------------------------------------------- 1 | # Image Utils 2 | 3 | ```{eval-rst} 4 | .. doxygenfile:: image_utils.h 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/utils/index.md: -------------------------------------------------------------------------------- 1 | # Utils 2 | 3 | ::::{grid} 1 2 2 3 4 | :margin: 1 1 0 0 5 | :gutter: 1 6 | 7 | :::{grid-item-card} Ocv Common 8 | :link: ./ocv_common 9 | :link-type: doc 10 | 11 | [todo] 12 | ::: 13 | :::{grid-item-card} Common 14 | :link: ./common 15 | :link-type: doc 16 | 17 | [todo] 18 | ::: 19 | :::{grid-item-card} Args Helper 20 | :link: ./args_helper 21 | :link-type: doc 22 | 23 | [todo] 24 | ::: 25 | :::{grid-item-card} Slog 26 | :link: ./slog 27 | :link-type: doc 28 | 29 | [todo] 30 | ::: 31 | :::{grid-item-card} Nms 32 | :link: ./nms 33 | :link-type: doc 34 | 35 | [todo] 36 | ::: 37 | :::{grid-item-card} Image Utils 38 | :link: ./image_utils 39 | :link-type: doc 40 | 41 | [todo] 42 | ::: 43 | :::{grid-item-card} Performance Metrics 44 | :link: ./performance_metrics 45 | :link-type: doc 46 | 47 | [todo] 48 | ::: 49 | :::{grid-item-card} Async Infer Queue 50 | :link: ./async_infer_queue 51 | :link-type: doc 52 | 53 | [todo] 54 | ::: 55 | :::{grid-item-card} Kuhn Munkres 56 | :link: ./kuhn_munkres 57 | :link-type: doc 58 | 59 | [todo] 60 | ::: 61 | 62 | :::: 63 | 64 | ```{toctree} 65 | :caption: Utils 66 | :hidden: 67 | 68 | ./ocv_common 69 | ./common 70 | ./args_helper 71 | ./slog 72 | ./nms 73 | ./image_utils 74 | ./performance_metrics 75 | ./async_infer_queue 76 | ./kuhn_munkres 77 | 78 | ``` 79 | -------------------------------------------------------------------------------- /docs/source/cpp/utils/kuhn_munkres.md: -------------------------------------------------------------------------------- 1 | # Kuhn Munkres 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: KuhnMunkres 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/utils/nms.md: -------------------------------------------------------------------------------- 1 | # Nms 2 | 3 | ```{eval-rst} 4 | .. doxygenfile:: nms.hpp 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/utils/ocv_common.md: -------------------------------------------------------------------------------- 1 | # Ocv Common 2 | 3 | ```{eval-rst} 4 | .. doxygenfile:: ocv_common.hpp 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/utils/performance_metrics.md: -------------------------------------------------------------------------------- 1 | # Performance Metrics 2 | 3 | ```{eval-rst} 4 | .. doxygenclass:: PerformanceMetrics 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/cpp/utils/slog.md: -------------------------------------------------------------------------------- 1 | # Slog 2 | 3 | ```{eval-rst} 4 | .. doxygenfile:: slog.hpp 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /docs/source/guides/index.md: -------------------------------------------------------------------------------- 1 | # Guides 2 | 3 | ```{toctree} 4 | :caption: Guides 5 | :hidden: 6 | 7 | ./model-configuration 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/index.md: -------------------------------------------------------------------------------- 1 | # InferenceSDK Documentation 2 | 3 | ## Python API Reference 4 | 5 | ::::{grid} 1 2 2 3 6 | :margin: 1 1 0 0 7 | :gutter: 1 8 | 9 | :::{grid-item-card} {octicon}`plug` Adapters 10 | :link: ./python/adapters/index 11 | :link-type: doc 12 | 13 | Adapters description[todo] 14 | ::: 15 | 16 | :::{grid-item-card} {octicon}`dependabot` Models 17 | :link: ./python/models/index 18 | :link-type: doc 19 | 20 | Models description[todo] 21 | ::: 22 | 23 | :::{grid-item-card} {octicon}`git-compare` Pipelines 24 | :link: ./python/pipelines/index 25 | :link-type: doc 26 | 27 | Pipelines description[todo] 28 | ::: 29 | 30 | :::{grid-item-card} {octicon}`versions` Tilers 31 | :link: ./python/tilers/index 32 | :link-type: doc 33 | 34 | Tilers description[todo] 35 | ::: 36 | 37 | :::: 38 | 39 | ## C++ API Reference 40 | 41 | ::::{grid} 1 2 2 3 42 | :margin: 1 1 0 0 43 | :gutter: 1 44 | 45 | :::{grid-item-card} {octicon}`plug` Adapters 46 | :link: ./cpp/adapters/index 47 | :link-type: doc 48 | 49 | Adapters description[todo] 50 | ::: 51 | 52 | :::{grid-item-card} {octicon}`dependabot` Models 53 | :link: ./cpp/models/index 54 | :link-type: doc 55 | 56 | Models description[todo] 57 | ::: 58 | 59 | :::{grid-item-card} {octicon}`versions` Tilers 60 | :link: ./cpp/tilers/index 61 | :link-type: doc 62 | 63 | Tilers description[todo] 64 | ::: 65 | 66 | :::{grid-item-card} {octicon}`tools` Utils 67 | :link: ./cpp/utils/index 68 | :link-type: doc 69 | 70 | Pipelines description[todo] 71 | ::: 72 | 73 | :::: 74 | 75 | ```{toctree} 76 | :caption: Python Reference 77 | :hidden: 78 | 79 | ./python/index 80 | ``` 81 | 82 | ```{toctree} 83 | :caption: C++ Reference 84 | :hidden: 85 | 86 | ./cpp/index 87 | ``` 88 | 89 | ```{toctree} 90 | :caption: Developer Guides 91 | :hidden: 92 | 93 | ./guides/index 94 | ``` 95 | -------------------------------------------------------------------------------- /docs/source/python/adapters/index.md: -------------------------------------------------------------------------------- 1 | # Adapters 2 | 3 | ::::{grid} 1 2 2 3 4 | :margin: 1 1 0 0 5 | :gutter: 1 6 | 7 | :::{grid-item-card} Utils 8 | :link: ./utils 9 | :link-type: doc 10 | 11 | [todo] 12 | ::: 13 | 14 | :::{grid-item-card} Ovms Adapter 15 | :link: ./ovms_adapter 16 | :link-type: doc 17 | 18 | [todo] 19 | ::: 20 | :::{grid-item-card} Onnx Adapter 21 | :link: ./onnx_adapter 22 | :link-type: doc 23 | 24 | [todo] 25 | ::: 26 | :::{grid-item-card} Inference Adapter 27 | :link: ./inference_adapter 28 | :link-type: doc 29 | 30 | [todo] 31 | ::: 32 | :::{grid-item-card} Openvino Adapter 33 | :link: ./openvino_adapter 34 | :link-type: doc 35 | 36 | [todo] 37 | ::: 38 | 39 | :::: 40 | 41 | ```{toctree} 42 | :caption: Adapters 43 | :hidden: 44 | 45 | ./inference_adapter 46 | ./onnx_adapter 47 | ./openvino_adapter 48 | ./ovms_adapter 49 | ./utils 50 | ``` 51 | -------------------------------------------------------------------------------- /docs/source/python/adapters/inference_adapter.md: -------------------------------------------------------------------------------- 1 | # Inference Adapter 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.adapters.inference_adapter 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/adapters/onnx_adapter.md: -------------------------------------------------------------------------------- 1 | # Onnx Adapter 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.adapters.onnx_adapter 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/adapters/openvino_adapter.md: -------------------------------------------------------------------------------- 1 | # Openvino Adapter 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.adapters.openvino_adapter 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/adapters/ovms_adapter.md: -------------------------------------------------------------------------------- 1 | # Ovms Adapter 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.adapters.ovms_adapter 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/adapters/utils.md: -------------------------------------------------------------------------------- 1 | # Utils 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.adapters.utils 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/index.md: -------------------------------------------------------------------------------- 1 | # Python API Reference 2 | 3 | ::::{grid} 1 2 2 3 4 | :margin: 1 1 0 0 5 | :gutter: 1 6 | 7 | :::{grid-item-card} {octicon}`plug` Adapters 8 | :link: adapters/index 9 | :link-type: doc 10 | 11 | Adapters description[todo] 12 | ::: 13 | 14 | :::{grid-item-card} {octicon}`dependabot` Models 15 | :link: models/index 16 | :link-type: doc 17 | 18 | Models description[todo] 19 | ::: 20 | 21 | :::{grid-item-card} {octicon}`git-compare` Pipelines 22 | :link: pipelines/index 23 | :link-type: doc 24 | 25 | Pipelines description[todo] 26 | ::: 27 | 28 | :::{grid-item-card} {octicon}`versions` Tilers 29 | :link: tilers/index 30 | :link-type: doc 31 | 32 | Tilers description[todo] 33 | ::: 34 | 35 | :::: 36 | 37 | ```{toctree} 38 | :caption: Python API Reference 39 | :hidden: 40 | 41 | ./adapters/index 42 | ./models/index 43 | ./pipelines/index 44 | ./tilers/index 45 | ``` 46 | -------------------------------------------------------------------------------- /docs/source/python/models/action_classification.md: -------------------------------------------------------------------------------- 1 | # Action Classification 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.models.action_classification 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/models/anomaly.md: -------------------------------------------------------------------------------- 1 | # Anomaly 2 | 3 | The `AnomalyModel` is a generic OpenVINO model that aims to provide a single interface for all the exported models based on [Anomalib](https://github.com/open-edge-platform/anomalib). 4 | 5 | Currently, the `AnomalyModel` supports the following models: 6 | 7 | - Padim 8 | - STFPM 9 | 10 | ```{eval-rst} 11 | .. automodule:: model_api.models.anomaly 12 | :members: 13 | :undoc-members: 14 | :show-inheritance: 15 | ``` 16 | -------------------------------------------------------------------------------- /docs/source/python/models/classification.md: -------------------------------------------------------------------------------- 1 | # Classification 2 | 3 | ## Description 4 | 5 | The `ClassificationModel` is the OpenVINO wrapper for models exported from [OpenVINO Training Extensions](https://github.com/openvinotoolkit/training_extensions). It supports multi-label classification as well as hierarchical classification. 6 | 7 | ## Model Specifications 8 | 9 | ## Inputs 10 | 11 | A single input image of shape (H, W, 3) where H and W are the height and width of the image, respectively. 12 | 13 | ## Outputs 14 | 15 | - `top_labels`: List of tuples containing the top labels of the classification model. 16 | - `saliency_map`: Saliency map of the input image. 17 | - `feature_vector`: Feature vector of the input image. This is useful for Active Learning. 18 | - `raw_scores`: Raw scores of the classification model. 19 | 20 | ```{eval-rst} 21 | .. automodule:: model_api.models.classification 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | ``` 26 | -------------------------------------------------------------------------------- /docs/source/python/models/detection_model.md: -------------------------------------------------------------------------------- 1 | # Detection Model 2 | 3 | ## Description 4 | 5 | Detection model aims to detect objects in an image. The model outputs a list of detected objects, each containing a bounding box, score and class label. 6 | 7 | ## OpenVINO Model Specifications 8 | 9 | ### Inputs 10 | 11 | A single input image of shape (H, W, 3) where H and W are the height and width of the image, respectively. 12 | 13 | ### Outputs 14 | 15 | Detection model outputs a `DetectionResult` objects containing the following attributes: 16 | 17 | - `boxes` (np.ndarray) - Bounding boxes of the detected objects. Each in format of x1, y1, x2 y2. 18 | - `scores` (np.ndarray) - Confidence scores of the detected objects. 19 | - `labels` (np.ndarray) - Class labels of the detected objects. 20 | - `label_names` (list[str]) - List of class names of the detected objects. 21 | 22 | ## Example 23 | 24 | ```python 25 | import cv2 26 | from model_api.models import SSD 27 | 28 | # Load the model 29 | model = SSD.create_model("model.xml") 30 | 31 | # Forward pass 32 | predictions = model(image) 33 | 34 | # Iterate over detection result 35 | for box, score, label, label_name in zip( 36 | predictions.boxes, 37 | predictions.scores, 38 | predictions.labels, 39 | predictions.label_names, 40 | ): 41 | print(f"Box: {box}, Score: {score}, Label: {label}, Label Name: {label_name}") 42 | ``` 43 | 44 | ```{eval-rst} 45 | .. automodule:: model_api.models.detection_model 46 | :members: 47 | :undoc-members: 48 | :show-inheritance: 49 | ``` 50 | -------------------------------------------------------------------------------- /docs/source/python/models/image_model.md: -------------------------------------------------------------------------------- 1 | # Image Model 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.models.image_model 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/models/index.md: -------------------------------------------------------------------------------- 1 | # Models 2 | 3 | ::::{grid} 1 2 2 3 4 | :margin: 1 1 0 0 5 | :gutter: 1 6 | 7 | :::{grid-item-card} Utils 8 | :link: ./utils 9 | :link-type: doc 10 | 11 | [todo] 12 | ::: 13 | 14 | :::{grid-item-card} Detection Model 15 | :link: ./detection_model 16 | :link-type: doc 17 | 18 | [todo] 19 | ::: 20 | :::{grid-item-card} Anomaly 21 | :link: ./anomaly 22 | :link-type: doc 23 | 24 | [todo] 25 | ::: 26 | 27 | :::{grid-item-card} SSD 28 | :link: ./ssd 29 | :link-type: doc 30 | 31 | [todo] 32 | ::: 33 | 34 | :::{grid-item-card} Keypoint Detection 35 | :link: ./keypoint_detection 36 | :link-type: doc 37 | 38 | [todo] 39 | ::: 40 | 41 | :::{grid-item-card} Visual Prompting 42 | :link: ./visual_prompting 43 | :link-type: doc 44 | 45 | [todo] 46 | ::: 47 | 48 | :::{grid-item-card} Classification 49 | :link: ./classification 50 | :link-type: doc 51 | 52 | [todo] 53 | ::: 54 | 55 | :::{grid-item-card} Segmentation 56 | :link: ./segmentation 57 | :link-type: doc 58 | 59 | [todo] 60 | ::: 61 | 62 | :::{grid-item-card} Instance Segmentation 63 | :link: ./instance_segmentation 64 | :link-type: doc 65 | 66 | [todo] 67 | ::: 68 | 69 | :::{grid-item-card} Model 70 | :link: ./model 71 | :link-type: doc 72 | 73 | [todo] 74 | ::: 75 | 76 | :::{grid-item-card} Action Classification 77 | :link: ./action_classification 78 | :link-type: doc 79 | 80 | [todo] 81 | ::: 82 | 83 | :::{grid-item-card} Image Model 84 | :link: ./image_model 85 | :link-type: doc 86 | 87 | [todo] 88 | ::: 89 | :::{grid-item-card} Types 90 | :link: ./types 91 | :link-type: doc 92 | 93 | [todo] 94 | ::: 95 | 96 | :::{grid-item-card} Sam Models 97 | :link: ./sam_models 98 | :link-type: doc 99 | 100 | [todo] 101 | ::: 102 | :::{grid-item-card} Yolo 103 | :link: ./yolo 104 | :link-type: doc 105 | 106 | [todo] 107 | ::: 108 | 109 | :::: 110 | 111 | ```{toctree} 112 | :caption: Models 113 | :hidden: 114 | 115 | ./utils 116 | ./detection_model 117 | ./anomaly 118 | ./ssd 119 | ./keypoint_detection 120 | ./visual_prompting 121 | ./classification 122 | ./segmentation 123 | ./instance_segmentation 124 | ./model 125 | ./action_classification 126 | ./image_model 127 | ./types 128 | ./sam_models 129 | ./yolo 130 | ``` 131 | -------------------------------------------------------------------------------- /docs/source/python/models/instance_segmentation.md: -------------------------------------------------------------------------------- 1 | # Instance Segmentation 2 | 3 | ## Description 4 | 5 | Instance segmentation model aims to detect and segment objects in an image. It is an extension of object detection, where each object is segmented into a separate mask. The model outputs a list of segmented objects, each containing a mask, bounding box, score and class label. 6 | 7 | ## OpenVINO Model Specifications 8 | 9 | ### Inputs 10 | 11 | A single input image of shape (H, W, 3) where H and W are the height and width of the image, respectively. 12 | 13 | ### Outputs 14 | 15 | Instance segmentation model outputs a `InstanceSegmentationResult` object containing the following attributes: 16 | 17 | - `boxes` (np.ndarray) - Bounding boxes of the detected objects. Each in format of x1, y1, x2 y2. 18 | - `scores` (np.ndarray) - Confidence scores of the detected objects. 19 | - `masks` (np.ndarray) - Segmentation masks of the detected objects. 20 | - `labels` (np.ndarray) - Class labels of the detected objects. 21 | - `label_names` (list[str]) - List of class names of the detected objects. 22 | 23 | ## Example 24 | 25 | ```python 26 | import cv2 27 | from model_api.models import MaskRCNNModel 28 | 29 | # Load the model 30 | model = MaskRCNNModel.create_model("model.xml") 31 | 32 | # Forward pass 33 | predictions = model(image) 34 | 35 | # Iterate over the segmented objects 36 | for box, score, mask, label, label_name in zip( 37 | predictions.boxes, 38 | predictions.scores, 39 | predictions.masks, 40 | predictions.labels, 41 | predictions.label_names, 42 | ): 43 | print(f"Box: {box}, Score: {score}, Label: {label}, Label Name: {label_name}") 44 | cv2.imshow("Mask", mask) 45 | cv2.waitKey(0) 46 | cv2.destroyAllWindows() 47 | ``` 48 | 49 | ```{eval-rst} 50 | .. automodule:: model_api.models.instance_segmentation 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | ``` 55 | -------------------------------------------------------------------------------- /docs/source/python/models/keypoint_detection.md: -------------------------------------------------------------------------------- 1 | # Keypoint Detection 2 | 3 | ## Description 4 | 5 | Keypoint detection model aims to detect a set of pre-defined keypoints on a cropped object. 6 | If a crop is not tight enough, quality of keypoints degrades. Having this model and an 7 | object detector, one can organize keypoint detection for all objects of interest presented on an image (top-down approach). 8 | 9 | ## Models 10 | 11 | Top-down keypoint detection pipeline uses detections that come from any appropriate detector, 12 | and a keypoints regression model acting on crops. 13 | 14 | ### Parameters 15 | 16 | The following parameters can be provided via python API or RT Info embedded into OV model: 17 | 18 | - `labels`(`list(str)`) : a list of keypoints names. 19 | 20 | ## OpenVINO Model Specifications 21 | 22 | ### Inputs 23 | 24 | A single `NCHW` tensor representing a batch of images. 25 | 26 | ### Outputs 27 | 28 | Two vectors in Simple Coordinate Classification Perspective ([SimCC](https://arxiv.org/abs/2107.03332)) format: 29 | 30 | - `pred_x` (B, N, D1) - `x` coordinate representation, where `N` is the number of keypoints. 31 | - `pred_y` (B, N, D2) - `y` coordinate representation, where `N` is the number of keypoints. 32 | 33 | ## Example 34 | 35 | ```python 36 | import cv2 37 | from model_api.models import TopDownKeypointDetectionPipeline, Detection, KeypointDetectionModel 38 | 39 | model = KeypointDetectionModel.create_model("kp_model.xml") 40 | # a list of detections in (x_min, y_min, x_max, y_max, score, class_id) format 41 | detections = [Detection(0, 0, 100, 100, 1.0, 0)] 42 | top_down_pipeline = TopDownKeypointDetectionPipeline(model) 43 | predictions = top_down_detector.predict(image, detections) 44 | 45 | # iterating over a list of DetectedKeypoints. Each of the items corresponds to a detection 46 | for obj_keypoints in predictions: 47 | for point in obj_keypoints.keypoints.astype(np.int32): 48 | cv2.circle( 49 | image, point, radius=0, color=(0, 255, 0), thickness=5 50 | ) 51 | ``` 52 | 53 | ```{eval-rst} 54 | .. automodule:: model_api.models.keypoint_detection 55 | :members: 56 | :undoc-members: 57 | :show-inheritance: 58 | ``` 59 | -------------------------------------------------------------------------------- /docs/source/python/models/model.md: -------------------------------------------------------------------------------- 1 | # Model 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.models.model 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/models/sam_models.md: -------------------------------------------------------------------------------- 1 | # Sam Models 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.models.sam_models 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/models/segmentation.md: -------------------------------------------------------------------------------- 1 | # Segmentation 2 | 3 | The `SegmentationModel` is the OpenVINO wrapper for models exported from [OpenVINO Training Extensions](https://github.com/openvinotoolkit/training_extensions). It produces a segmentation mask for the input image. 4 | 5 | ## Model Specifications 6 | 7 | ### Inputs 8 | 9 | A single input image of shape (H, W, 3) where H and W are the height and width of the image, respectively. 10 | 11 | ### Outputs 12 | 13 | - `resultImage`: Image with the segmentation mask. 14 | - `soft_prediction`: Soft prediction of the segmentation model. 15 | - `saliency_map`: Saliency map of the input image. 16 | - `feature_vector`: Feature vector of the input image. This is useful for Active Learning. 17 | 18 | ```{eval-rst} 19 | .. automodule:: model_api.models.segmentation 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | ``` 24 | -------------------------------------------------------------------------------- /docs/source/python/models/ssd.md: -------------------------------------------------------------------------------- 1 | # Ssd 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.models.ssd 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/models/types.md: -------------------------------------------------------------------------------- 1 | # Types 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.models.types 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/models/utils.md: -------------------------------------------------------------------------------- 1 | # Utils 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.models.utils 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/models/visual_prompting.md: -------------------------------------------------------------------------------- 1 | # Visual Prompting 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.models.visual_prompting 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/models/yolo.md: -------------------------------------------------------------------------------- 1 | # Yolo 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.models.yolo 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/pipelines/async_pipeline.md: -------------------------------------------------------------------------------- 1 | # Async Pipeline 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.pipelines.async_pipeline 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/pipelines/index.md: -------------------------------------------------------------------------------- 1 | # Pipelines 2 | 3 | ::::{grid} 1 2 2 3 4 | :margin: 1 1 0 0 5 | :gutter: 1 6 | 7 | :::{grid-item-card} Async Pipeline 8 | :link: ./async_pipeline 9 | :link-type: doc 10 | 11 | [todo] 12 | ::: 13 | 14 | :::: 15 | 16 | ```{toctree} 17 | :caption: Pipelines 18 | :hidden: 19 | 20 | ./async_pipeline 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/source/python/tilers/detection.md: -------------------------------------------------------------------------------- 1 | # Detection 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.tilers.detection 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/tilers/index.md: -------------------------------------------------------------------------------- 1 | # Tilers 2 | 3 | ::::{grid} 1 2 2 3 4 | :margin: 1 1 0 0 5 | :gutter: 1 6 | 7 | :::{grid-item-card} Semantic Segmentation 8 | :link: ./semantic_segmentation 9 | :link-type: doc 10 | 11 | [todo] 12 | ::: 13 | 14 | :::{grid-item-card} Instance Segmentation 15 | :link: ./instance_segmentation 16 | :link-type: doc 17 | 18 | [todo] 19 | ::: 20 | 21 | :::{grid-item-card} Detection 22 | :link: ./detection 23 | :link-type: doc 24 | 25 | [todo] 26 | ::: 27 | 28 | :::{grid-item-card} Tiler 29 | :link: ./tiler 30 | :link-type: doc 31 | 32 | [todo] 33 | ::: 34 | 35 | :::: 36 | 37 | ```{toctree} 38 | :caption: Tilers 39 | :hidden: 40 | 41 | ./tiler 42 | ./detection 43 | ./instance_segmentation 44 | ./semantic_segmentation 45 | ``` 46 | -------------------------------------------------------------------------------- /docs/source/python/tilers/instance_segmentation.md: -------------------------------------------------------------------------------- 1 | # Instance Segmentation 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.tilers.instance_segmentation 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/tilers/semantic_segmentation.md: -------------------------------------------------------------------------------- 1 | # Semantic Segmentation 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.tilers.semantic_segmentation 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/source/python/tilers/tiler.md: -------------------------------------------------------------------------------- 1 | # Tiler 2 | 3 | ```{eval-rst} 4 | .. automodule:: model_api.tilers.tiler 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | ``` 9 | -------------------------------------------------------------------------------- /examples/cpp/asynchronous_api/README.md: -------------------------------------------------------------------------------- 1 | # Synchronous API example 2 | 3 | This example demonstrates how to use a C++ API of OpenVINO Model API for asynchronous inference and its basic steps: 4 | 5 | - Instantiate a model 6 | - Set a callback to grab inference results 7 | - Model inference 8 | - Model batch inference 9 | - Process results of the batch inference 10 | 11 | ## Prerequisites 12 | 13 | - Install third party dependencies by running the following script: 14 | 15 | ```bash 16 | chmod +x ../../../src/cpp/install_dependencies.sh 17 | sudo ../../../src/cpp/install_dependencies.sh 18 | ``` 19 | 20 | - Build example: 21 | 22 | - Create `build` folder and navigate into it: 23 | 24 | ```bash 25 | mkdir build && cd build 26 | ``` 27 | 28 | - Run cmake: 29 | 30 | ```bash 31 | cmake ../ 32 | ``` 33 | 34 | - Build: 35 | 36 | ```bash 37 | make -j 38 | ``` 39 | 40 | - Download a model by running a Python code with Model API, see Python [example](../../python/asynchronous_api/README.md): 41 | 42 | ```python 43 | from model_api.models import DetectionModel 44 | 45 | model = DetectionModel.create_model("ssd_mobilenet_v1_fpn_coco", 46 | download_dir="tmp") 47 | ``` 48 | 49 | ## Run example 50 | 51 | To run the example, please execute the following command: 52 | 53 | ```bash 54 | ./asynchronous_api ./tmp/public/ssd_mobilenet_v1_fpn_coco/FP16/ssd_mobilenet_v1_fpn_coco.xml 55 | ``` 56 | -------------------------------------------------------------------------------- /examples/cpp/synchronous_api/README.md: -------------------------------------------------------------------------------- 1 | # Synchronous API example 2 | 3 | This example demonstrates how to use a C++ API of OpenVINO Model API for synchronous inference and its basic steps: 4 | 5 | - Instantiate a model 6 | - Model inference 7 | - Process results 8 | 9 | ## Prerequisites 10 | 11 | - Install third party dependencies by running the following script: 12 | 13 | ```bash 14 | chmod +x ../../../src/cpp/install_dependencies.sh 15 | sudo ../../../src/cpp/install_dependencies.sh 16 | ``` 17 | 18 | - Build example: 19 | 20 | - Create `build` folder and navigate into it: 21 | 22 | ```bash 23 | mkdir build && cd build 24 | ``` 25 | 26 | - Run cmake: 27 | 28 | ```bash 29 | cmake ../ 30 | ``` 31 | 32 | - Build: 33 | 34 | ```bash 35 | make -j 36 | ``` 37 | 38 | - Download a model by running a Python code with Model API, see Python [example](../../python/synchronous_api/README.md): 39 | 40 | ```python 41 | from model_api.models import DetectionModel 42 | 43 | model = DetectionModel.create_model("ssd_mobilenet_v1_fpn_coco", 44 | download_dir="tmp") 45 | ``` 46 | 47 | ## Run example 48 | 49 | To run the example, please execute the following command: 50 | 51 | ```bash 52 | ./synchronous_api ./tmp/public/ssd_mobilenet_v1_fpn_coco/FP16/ssd_mobilenet_v1_fpn_coco.xml 53 | ``` 54 | -------------------------------------------------------------------------------- /examples/cpp/synchronous_api/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | int main(int argc, char* argv[]) try { 22 | if (argc != 3) { 23 | throw std::runtime_error(std::string{"Usage: "} + argv[0] + " "); 24 | } 25 | 26 | cv::Mat image = cv::imread(argv[2]); 27 | cv::cvtColor(image, image, cv::COLOR_BGR2RGB); 28 | 29 | if (!image.data) { 30 | throw std::runtime_error{"Failed to read the image"}; 31 | } 32 | 33 | // Instantiate Object Detection model 34 | auto model = DetectionModel::create_model(argv[1]); // works with SSD models. Download it using Python Model API 35 | 36 | // Run the inference 37 | auto result = model->infer(image); 38 | 39 | // Process detections 40 | for (auto& obj : result->objects) { 41 | std::cout << " " << std::left << std::setw(9) << obj.label << " | " << std::setw(10) << obj.confidence << " | " 42 | << std::setw(4) << int(obj.x) << " | " << std::setw(4) << int(obj.y) << " | " << std::setw(4) 43 | << int(obj.x + obj.width) << " | " << std::setw(4) << int(obj.y + obj.height) << "\n"; 44 | } 45 | } catch (const std::exception& error) { 46 | std::cerr << error.what() << '\n'; 47 | return 1; 48 | } catch (...) { 49 | std::cerr << "Non-exception object thrown\n"; 50 | return 1; 51 | } 52 | -------------------------------------------------------------------------------- /examples/python/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2024 Intel Corporation 2 | # SPDX-License-Identifier: Apache-2.0 3 | -------------------------------------------------------------------------------- /examples/python/asynchronous_api/README.md: -------------------------------------------------------------------------------- 1 | # Asynchronous API example 2 | 3 | This example demonstrates how to use a Python API of OpenVINO Model API for asynchronous inference and its basic steps: 4 | 5 | - Instantiate a model 6 | - Define a callback function for results processing 7 | - Run inference 8 | - Fetch and process results 9 | 10 | ## Prerequisites 11 | 12 | Install Model API from source. Please refer to the main [README](../../../README.md) for details. 13 | 14 | ## Run example 15 | 16 | To run the example, please execute the following command: 17 | 18 | ```bash 19 | python run.py 20 | ``` 21 | -------------------------------------------------------------------------------- /examples/python/asynchronous_api/run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (C) 2020-2024 Intel Corporation 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | 7 | import sys 8 | 9 | import cv2 10 | from model_api.models import DetectionModel 11 | 12 | 13 | def main(): 14 | if len(sys.argv) != 2: 15 | raise RuntimeError(f"Usage: {sys.argv[0]} ") 16 | 17 | image = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2RGB) 18 | if image is None: 19 | raise RuntimeError("Failed to read the image") 20 | 21 | # Create Object Detection model using mode name and download from Open Model Zoo 22 | # Replace numpy preprocessing and embed it directly into a model graph to speed up inference 23 | # download_dir is used to store downloaded model 24 | model = DetectionModel.create_model("yolo-v4-tf") 25 | 26 | ITERATIONS = 10 27 | results = {} # container for results 28 | 29 | def callback(result, userdata): 30 | print(f"Done! Number: {userdata}") 31 | results[userdata] = result 32 | 33 | model.set_callback(callback) 34 | ## Run parallel inference 35 | for i in range(ITERATIONS): 36 | model.infer_async(image, user_data=i) 37 | 38 | model.await_all() 39 | assert len(results) == ITERATIONS 40 | 41 | for i in range(ITERATIONS): 42 | print(f"Request {i}: {results[i]}") 43 | 44 | 45 | if __name__ == "__main__": 46 | main() 47 | -------------------------------------------------------------------------------- /examples/python/serving_api/README.md: -------------------------------------------------------------------------------- 1 | # Serving API example 2 | 3 | This example demonstrates how to use a Python API of OpenVINO Model API for a remote inference of models hosted with [OpenVINO Model Server](https://docs.openvino.ai/latest/ovms_what_is_openvino_model_server.html). This tutorial assumes that you are familiar with Docker subsystem and includes the following steps: 4 | 5 | - Run Docker image with 6 | - Instantiate a model 7 | - Run inference 8 | - Process results 9 | 10 | ## Prerequisites 11 | 12 | - Install Model API from source. Please refer to the main [README](../../../README.md) for details. 13 | - Install Docker. Please refer to the [official documentation](https://docs.docker.com/get-docker/) for details. 14 | - Install OVMS client into the Python environment: 15 | 16 | ```bash 17 | pip install ovmsclient 18 | ``` 19 | 20 | - Download a model by running a Python code with Model API, see Python [exaple](../../python/synchronous_api/README.md) and resave a configured model at OVMS friendly folder layout: 21 | 22 | ```python 23 | from model_api.models import DetectionModel 24 | 25 | DetectionModel.create_model("ssd_mobilenet_v1_fpn_coco").save("/home/user/models/ssd_mobilenet_v1_fpn_coco/1/ssd_mobilenet_v1_fpn_coco.xml") 26 | ``` 27 | 28 | - Run docker with OVMS server: 29 | 30 | ```bash 31 | docker run -d -v /home/user/models:/models -p 8000:8000 openvino/model_server:latest --model_path /models/ssd_mobilenet_v1_fpn_coco --model_name ssd_mobilenet_v1_fpn_coco --rest_port 8000 --nireq 4 --target_device CPU 32 | ``` 33 | 34 | ## Run example 35 | 36 | To run the example, please execute the following command: 37 | 38 | ```bash 39 | python run.py 40 | ``` 41 | -------------------------------------------------------------------------------- /examples/python/serving_api/run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (C) 2020-2024 Intel Corporation 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | 7 | import sys 8 | 9 | import cv2 10 | from model_api.models import DetectionModel 11 | 12 | 13 | def main(): 14 | if len(sys.argv) != 2: 15 | raise RuntimeError(f"Usage: {sys.argv[0]} ") 16 | 17 | image = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2RGB) 18 | if image is None: 19 | raise RuntimeError("Failed to read the image") 20 | 21 | # Create Object Detection model specifying the OVMS server URL 22 | model = DetectionModel.create_model( 23 | "localhost:8000/v2/models/ssd_mobilenet_v1_fpn_coco", model_type="ssd" 24 | ) 25 | detections = model(image) 26 | print(f"Detection results: {detections}") 27 | 28 | 29 | if __name__ == "__main__": 30 | main() 31 | -------------------------------------------------------------------------------- /examples/python/synchronous_api/README.md: -------------------------------------------------------------------------------- 1 | # Synchronous API example 2 | 3 | This example demonstrates how to use a Python API of OpenVINO Model API for synchronous inference as well as basic features such as: 4 | 5 | - Automatic download and convertion of public models 6 | - Preprocessing embedding 7 | - Creating model from local source 8 | - Image Classification, Object Detection and Semantic Segmentation use cases 9 | 10 | ## Prerequisites 11 | 12 | Install Model API from source. Please refer to the main [README](../../../README.md) for details. 13 | 14 | ## Run example 15 | 16 | To run the example, please execute the following command: 17 | 18 | ```bash 19 | python run.py 20 | ``` 21 | 22 | > _NOTE_: results of Semantic Segmentation models are saved to `mask.png` file. 23 | -------------------------------------------------------------------------------- /examples/python/synchronous_api/run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (C) 2020-2024 Intel Corporation 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | 7 | import sys 8 | 9 | import cv2 10 | from model_api.models import ClassificationModel, DetectionModel, SegmentationModel 11 | from PIL import Image 12 | 13 | 14 | def main(): 15 | if len(sys.argv) != 2: 16 | raise RuntimeError(f"Usage: {sys.argv[0]} ") 17 | 18 | image = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2RGB) 19 | if image is None: 20 | raise RuntimeError("Failed to read the image") 21 | 22 | # Create Image Classification model using mode name and download from Open Model Zoo 23 | efficientnet_b0 = ClassificationModel.create_model("efficientnet-b0-pytorch") 24 | classifications = efficientnet_b0(image) 25 | print(f"Classification results: {classifications}") 26 | 27 | # Create Object Detection model using mode name and download from Open Model Zoo 28 | # Replace numpy preprocessing and embed it directly into a model graph to speed up inference 29 | # download_dir is used to store downloaded model 30 | ssd_mobilenet_fpn = DetectionModel.create_model( 31 | "ssd_mobilenet_v1_fpn_coco", 32 | download_dir="tmp", 33 | ) 34 | detections = ssd_mobilenet_fpn(image) 35 | print(f"Detection results: {detections}") 36 | ssd_mobilenet_fpn.save("ssd_mobilenet_v1_fpn_coco_with_preprocessing.xml") 37 | 38 | # Instantiate from a local model (downloaded previously) 39 | ssd_mobilenet_fpn_local = DetectionModel.create_model( 40 | "tmp/public/ssd_mobilenet_v1_fpn_coco/FP16/ssd_mobilenet_v1_fpn_coco.xml" 41 | ) 42 | detections = ssd_mobilenet_fpn_local(image) 43 | print(f"Detection results for local: {detections}") 44 | 45 | # Create Image Segmentation model 46 | hrnet = SegmentationModel.create_model("hrnet-v2-c1-segmentation") 47 | mask = hrnet(image) 48 | Image.fromarray(mask + 20).save("mask.png") 49 | 50 | 51 | if __name__ == "__main__": 52 | main() 53 | -------------------------------------------------------------------------------- /examples/python/visual_prompting/README.md: -------------------------------------------------------------------------------- 1 | # Segment Anything example 2 | 3 | This example demonstrates how to use a Python API implementation of Segment Anything pipeline inference: 4 | 5 | - Create encoder and decoder models 6 | - Create a visual prompter pipeline 7 | - Use points as prompts 8 | - Visualized result is saved to `sam_result.jpg` 9 | 10 | ## Prerequisites 11 | 12 | Install Model API from source. Please refer to the main [README](../../../README.md) for details. 13 | 14 | ## Run example 15 | 16 | To run the example, please execute the following command: 17 | 18 | ```bash 19 | python run.py 20 | ``` 21 | 22 | where prompts are in X Y format. 23 | 24 | To run the pipeline out-of-the box you can download the test data by running the following command from the repo root: 25 | 26 | ```bash 27 | pip install httpx 28 | python tests/python/accuracy/prepare_data.py -d data 29 | ``` 30 | 31 | and then run 32 | 33 | ```bash 34 | python run.py ../../../data/coco128/images/train2017/000000000127.jpg \ 35 | ../../../data/otx_models/sam_vit_b_zsl_encoder.xml ../../../data/otx_models/sam_vit_b_zsl_decoder.xml \ 36 | 274 306 482 295 37 | ``` 38 | 39 | from the sample folder. Here two prompt poinst are passed via CLI: `(274, 306)` and `(482, 295)` 40 | 41 | > _NOTE_: results of segmentation models are saved to `sam_result.jpg` file. 42 | -------------------------------------------------------------------------------- /examples/python/visual_prompting/run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (C) 2020-2024 Intel Corporation 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | 7 | import argparse 8 | import colorsys 9 | 10 | import cv2 11 | import numpy as np 12 | from model_api.models import Model, Prompt, SAMVisualPrompter 13 | 14 | 15 | def get_colors(n: int): 16 | HSV_tuples = [(x / n, 0.5, 0.5) for x in range(n)] 17 | RGB_tuples = map(lambda x: colorsys.hsv_to_rgb(*x), HSV_tuples) 18 | return (np.array(list(RGB_tuples)) * 255).astype(np.uint8) 19 | 20 | 21 | def main(): 22 | parser = argparse.ArgumentParser(description="SAM sample script") 23 | parser.add_argument("image", type=str) 24 | parser.add_argument("encoder_path", type=str) 25 | parser.add_argument("decoder_path", type=str) 26 | parser.add_argument("prompts", nargs="+", type=int) 27 | args = parser.parse_args() 28 | 29 | image = cv2.cvtColor(cv2.imread(args.image), cv2.COLOR_BGR2RGB) 30 | if image is None: 31 | raise RuntimeError("Failed to read the image") 32 | 33 | encoder = Model.create_model(args.encoder_path) 34 | decoder = Model.create_model(args.decoder_path) 35 | sam_prompter = SAMVisualPrompter(encoder, decoder) 36 | 37 | all_prompts = [] 38 | for i, p in enumerate(np.array(args.prompts).reshape(-1, 2)): 39 | all_prompts.append(Prompt(p, i)) 40 | 41 | result = sam_prompter(image, points=all_prompts) 42 | 43 | colors = get_colors(len(all_prompts)) 44 | 45 | for i in range(len(result.upscaled_masks)): 46 | print(f"Prompt {i}, mask score {result.best_iou[i]:.3f}") 47 | masked_img = np.where(result.processed_mask[i][..., None], colors[i], image) 48 | image = cv2.addWeighted(image, 0.2, masked_img, 0.8, 0) 49 | 50 | cv2.imwrite("sam_result.jpg", cv2.cvtColor(image, cv2.COLOR_RGB2BGR)) 51 | 52 | 53 | if __name__ == "__main__": 54 | main() 55 | -------------------------------------------------------------------------------- /examples/python/visualization/README.md: -------------------------------------------------------------------------------- 1 | # Visualization Example 2 | 3 | This example demonstrates how to use the Visualizer in VisionAPI. 4 | 5 | ## Prerequisites 6 | 7 | Install Model API from source. Please refer to the main [README](../../../README.md) for details. 8 | 9 | ## Run example 10 | 11 | To run the example, please execute the following command: 12 | 13 | ```bash 14 | python run.py --image --model .xml --output 15 | ``` 16 | -------------------------------------------------------------------------------- /examples/python/visualization/run.py: -------------------------------------------------------------------------------- 1 | """Visualization Example.""" 2 | 3 | # Copyright (C) 2025 Intel Corporation 4 | # SPDX-License-Identifier: Apache-2.0 5 | 6 | import argparse 7 | from argparse import Namespace 8 | 9 | import numpy as np 10 | from PIL import Image 11 | 12 | from model_api.models import Model 13 | from model_api.visualizer import Visualizer 14 | 15 | 16 | def main(args: Namespace): 17 | image = Image.open(args.image) 18 | 19 | model = Model.create_model(args.model) 20 | 21 | predictions = model(np.array(image)) 22 | visualizer = Visualizer() 23 | 24 | if args.output: 25 | visualizer.save(image=image, result=predictions, path=args.output) 26 | else: 27 | visualizer.show(image=image, result=predictions) 28 | 29 | 30 | if __name__ == "__main__": 31 | parser = argparse.ArgumentParser() 32 | parser.add_argument("--image", type=str, required=True) 33 | parser.add_argument("--model", type=str, required=True) 34 | parser.add_argument("--output", type=str, required=False) 35 | args = parser.parse_args() 36 | main(args) 37 | -------------------------------------------------------------------------------- /examples/python/zsl_visual_prompting/README.md: -------------------------------------------------------------------------------- 1 | # Zero-shot Segment Anything example 2 | 3 | This example demonstrates how to use a Python API implementation of Zero-shot Segment Anything pipeline inference: 4 | 5 | - Create encoder and decoder models 6 | - Create a zero-shot visual prompter pipeline 7 | - Use points as prompts to learn on one image 8 | - Segment other image using leaned on the previous image representation 9 | - Visualized result is saved to `zsl_sam_result.jpg` 10 | 11 | ## Prerequisites 12 | 13 | Install Model API from source. Please refer to the main [README](../../../README.md) for details. 14 | 15 | ## Run example 16 | 17 | To run the example, please execute the following command: 18 | 19 | ```bash 20 | python run.py -t 21 | ``` 22 | 23 | where prompts are in X Y format. `t` is a threshold to match the reference features from the source image vs features 24 | obtained from the target image. 25 | Higher thresholds leads to lower mask recall in the final prediction, i.e. low confidence masks can be filtered. 26 | 27 | To run the pipeline out-of-the box you can download the test data by running the following command from the repo root: 28 | 29 | ```bash 30 | pip install httpx 31 | python tests/python/accuracy/prepare_data.py -d data 32 | ``` 33 | 34 | and then run 35 | 36 | ```bash 37 | python run.py ../../../data/coco128/images/train2017/000000000025.jpg \ 38 | ../../../data/coco128/images/train2017/000000000072.jpg ../../../data/otx_models/sam_vit_b_zsl_encoder.xml \ 39 | ../../../data/otx_models/sam_vit_b_zsl_decoder.xml 464 202 -t 0.7 40 | 41 | ``` 42 | 43 | from the sample folder. Here one prompt is passed via CLI: `(464 202)` 44 | 45 | > _NOTE_: results of segmentation models are saved to `zsl_sam_result.jpg` file. 46 | -------------------------------------------------------------------------------- /examples/python/zsl_visual_prompting/run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (C) 2020-2024 Intel Corporation 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | 7 | import argparse 8 | import colorsys 9 | 10 | import cv2 11 | import numpy as np 12 | from model_api.models import Model, Prompt, SAMLearnableVisualPrompter 13 | 14 | 15 | def get_colors(n: int): 16 | HSV_tuples = [(x / n, 0.5, 0.5) for x in range(n)] 17 | RGB_tuples = map(lambda x: colorsys.hsv_to_rgb(*x), HSV_tuples) 18 | return (np.array(list(RGB_tuples)) * 255).astype(np.uint8) 19 | 20 | 21 | def main(): 22 | parser = argparse.ArgumentParser(description="SAM sample script") 23 | parser.add_argument("image_source", type=str) 24 | parser.add_argument("image_target", type=str) 25 | parser.add_argument("encoder_path", type=str) 26 | parser.add_argument("decoder_path", type=str) 27 | parser.add_argument("prompts", nargs="+", type=int) 28 | parser.add_argument("-t", "--threshold", type=float, default=0.65) 29 | args = parser.parse_args() 30 | 31 | image = cv2.cvtColor(cv2.imread(args.image_source), cv2.COLOR_BGR2RGB) 32 | if image is None: 33 | raise RuntimeError("Failed to read the source image") 34 | 35 | image_target = cv2.cvtColor(cv2.imread(args.image_target), cv2.COLOR_BGR2RGB) 36 | if image_target is None: 37 | raise RuntimeError("Failed to read the target image") 38 | 39 | encoder = Model.create_model(args.encoder_path) 40 | decoder = Model.create_model(args.decoder_path) 41 | zsl_sam_prompter = SAMLearnableVisualPrompter( 42 | encoder, decoder, threshold=args.threshold 43 | ) 44 | 45 | all_prompts = [] 46 | for i, p in enumerate(np.array(args.prompts).reshape(-1, 2)): 47 | all_prompts.append(Prompt(p, i)) 48 | 49 | zsl_sam_prompter.learn(image, points=all_prompts) 50 | 51 | colors = get_colors(len(all_prompts)) 52 | 53 | result = zsl_sam_prompter(image_target) 54 | 55 | for i in result.data: 56 | masks = result.get_mask(i) 57 | for j, instance in enumerate(masks.mask): 58 | prompt_point = masks.points[j].astype(np.int32) 59 | confidence = float(masks.scores[j]) 60 | masked_img = np.where(instance[..., None], colors[i], image_target) 61 | image_target = cv2.addWeighted(image_target, 0.2, masked_img, 0.8, 0) 62 | print(f"Reference point: {prompt_point}, point score: {confidence:.3f}") 63 | cv2.circle( 64 | image_target, prompt_point, radius=0, color=(0, 0, 255), thickness=5 65 | ) 66 | 67 | cv2.imwrite("zsl_sam_result.jpg", cv2.cvtColor(image_target, cv2.COLOR_RGB2BGR)) 68 | 69 | 70 | if __name__ == "__main__": 71 | main() 72 | -------------------------------------------------------------------------------- /src/cpp/adapters/include/adapters/inference_adapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | struct InputData; 15 | struct InferenceResult; 16 | 17 | using InferenceOutput = std::map; 18 | using InferenceInput = std::map; 19 | using CallbackData = std::shared_ptr; 20 | 21 | // The interface doesn't have implementation 22 | class InferenceAdapter { 23 | public: 24 | virtual ~InferenceAdapter() = default; 25 | 26 | virtual InferenceOutput infer(const InferenceInput& input) = 0; 27 | virtual void infer(const InferenceInput& input, InferenceOutput& output) = 0; 28 | virtual void setCallback(std::function callback) = 0; 29 | virtual void inferAsync(const InferenceInput& input, CallbackData callback_args) = 0; 30 | virtual bool isReady() = 0; 31 | virtual void awaitAll() = 0; 32 | virtual void awaitAny() = 0; 33 | virtual size_t getNumAsyncExecutors() const = 0; 34 | virtual void loadModel(const std::shared_ptr& model, 35 | ov::Core& core, 36 | const std::string& device = "", 37 | const ov::AnyMap& compilationConfig = {}, 38 | size_t max_num_requests = 0) = 0; 39 | virtual ov::PartialShape getInputShape(const std::string& inputName) const = 0; 40 | virtual ov::PartialShape getOutputShape(const std::string& inputName) const = 0; 41 | virtual ov::element::Type_t getInputDatatype(const std::string& inputName) const = 0; 42 | virtual ov::element::Type_t getOutputDatatype(const std::string& outputName) const = 0; 43 | virtual std::vector getInputNames() const = 0; 44 | virtual std::vector getOutputNames() const = 0; 45 | virtual const ov::AnyMap& getModelConfig() const = 0; 46 | }; 47 | -------------------------------------------------------------------------------- /src/cpp/adapters/include/adapters/openvino_adapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "adapters/inference_adapter.h" 15 | #include "utils/async_infer_queue.hpp" 16 | 17 | class OpenVINOInferenceAdapter : public InferenceAdapter { 18 | public: 19 | OpenVINOInferenceAdapter() = default; 20 | 21 | virtual InferenceOutput infer(const InferenceInput& input) override; 22 | virtual void infer(const InferenceInput& input, InferenceOutput& output) override; 23 | virtual void inferAsync(const InferenceInput& input, const CallbackData callback_args) override; 24 | virtual void setCallback(std::function callback); 25 | virtual bool isReady(); 26 | virtual void awaitAll(); 27 | virtual void awaitAny(); 28 | virtual void loadModel(const std::shared_ptr& model, 29 | ov::Core& core, 30 | const std::string& device = "", 31 | const ov::AnyMap& compilationConfig = {}, 32 | size_t max_num_requests = 1) override; 33 | virtual size_t getNumAsyncExecutors() const; 34 | virtual ov::PartialShape getInputShape(const std::string& inputName) const override; 35 | virtual ov::PartialShape getOutputShape(const std::string& outputName) const override; 36 | virtual ov::element::Type_t getInputDatatype(const std::string& inputName) const override; 37 | virtual ov::element::Type_t getOutputDatatype(const std::string& outputName) const override; 38 | virtual std::vector getInputNames() const override; 39 | virtual std::vector getOutputNames() const override; 40 | virtual const ov::AnyMap& getModelConfig() const override; 41 | 42 | protected: 43 | void initInputsOutputs(); 44 | 45 | protected: 46 | // Depends on the implementation details but we should share the model state in this class 47 | std::vector inputNames; 48 | std::vector outputNames; 49 | ov::CompiledModel compiledModel; 50 | std::unique_ptr asyncQueue; 51 | ov::AnyMap modelConfig; // the content of model_info section of rt_info 52 | }; 53 | -------------------------------------------------------------------------------- /src/cpp/cmake/model_apiConfig.cmake: -------------------------------------------------------------------------------- 1 | include(CMakeFindDependencyMacro) 2 | find_dependency(OpenCV COMPONENTS core imgproc) 3 | find_dependency(OpenVINO COMPONENTS Runtime) 4 | 5 | include("${CMAKE_CURRENT_LIST_DIR}/model_apiTargets.cmake") 6 | 7 | check_required_components() 8 | -------------------------------------------------------------------------------- /src/cpp/install_dependencies.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Added required keys / do the update 4 | wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB 5 | 6 | apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB 7 | 8 | echo "deb https://apt.repos.intel.com/openvino/2025 ubuntu22 main" | sudo tee /etc/apt/sources.list.d/intel-openvino-2025.list 9 | 10 | apt update 11 | 12 | #Install OpenCV 13 | apt-get install libopencv-dev 14 | 15 | # Install OpenVINO 16 | sudo apt install openvino-2025.0.0 17 | -------------------------------------------------------------------------------- /src/cpp/models/include/models/anomaly_model.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include "models/base_model.h" 8 | 9 | namespace ov { 10 | class Model; 11 | } // namespace ov 12 | struct AnomalyResult; 13 | struct ImageInputData; 14 | 15 | class AnomalyModel : public BaseModel { 16 | public: 17 | AnomalyModel(std::shared_ptr& model, const ov::AnyMap& configuration); 18 | AnomalyModel(std::shared_ptr& adapter, const ov::AnyMap& configuration = {}); 19 | 20 | static std::unique_ptr create_model(const std::string& modelFile, 21 | const ov::AnyMap& configuration = {}, 22 | bool preload = true, 23 | const std::string& device = "AUTO"); 24 | static std::unique_ptr create_model(std::shared_ptr& adapter); 25 | 26 | virtual std::unique_ptr infer(const ImageInputData& inputData); 27 | virtual std::vector> inferBatch(const std::vector& inputImgs); 28 | std::unique_ptr postprocess(InferenceResult& infResult) override; 29 | 30 | friend std::ostream& operator<<(std::ostream& os, std::unique_ptr& model); 31 | 32 | static std::string ModelType; 33 | 34 | protected: 35 | float imageThreshold{0.5f}; 36 | float pixelThreshold{0.5f}; 37 | float normalizationScale{1.0f}; 38 | std::string task = "segmentation"; 39 | 40 | void init_from_config(const ov::AnyMap& top_priority, const ov::AnyMap& mid_priority); 41 | 42 | void prepareInputsOutputs(std::shared_ptr& model) override; 43 | void updateModelInfo() override; 44 | cv::Mat normalize(cv::Mat& tensor, float threshold); 45 | double normalize(double& tensor, float threshold); 46 | std::vector getBoxes(cv::Mat& mask); 47 | }; 48 | -------------------------------------------------------------------------------- /src/cpp/models/include/models/detection_model.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #include "models/base_model.h" 11 | 12 | struct DetectionResult; 13 | struct ImageInputData; 14 | struct InferenceAdatper; 15 | 16 | class DetectionModel : public BaseModel { 17 | public: 18 | DetectionModel(std::shared_ptr& model, const ov::AnyMap& configuration); 19 | DetectionModel(std::shared_ptr& adapter, const ov::AnyMap& configuration = {}); 20 | 21 | static std::unique_ptr create_model(const std::string& modelFile, 22 | const ov::AnyMap& configuration = {}, 23 | std::string model_type = "", 24 | bool preload = true, 25 | const std::string& device = "AUTO"); 26 | static std::unique_ptr create_model(std::shared_ptr& adapter); 27 | 28 | virtual std::unique_ptr infer(const ImageInputData& inputData); 29 | virtual std::vector> inferBatch(const std::vector& inputImgs); 30 | 31 | protected: 32 | float confidence_threshold = 0.5f; 33 | 34 | void updateModelInfo() override; 35 | }; 36 | -------------------------------------------------------------------------------- /src/cpp/models/include/models/detection_model_ext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "models/detection_model.h" 13 | 14 | struct DetectionResult; 15 | struct ImageInputData; 16 | struct InferenceAdatper; 17 | 18 | class DetectionModelExt : public DetectionModel { 19 | public: 20 | DetectionModelExt(std::shared_ptr& model, const ov::AnyMap& configuration); 21 | DetectionModelExt(std::shared_ptr& adapter); 22 | 23 | protected: 24 | void updateModelInfo() override; 25 | float iou_threshold = 0.5f; 26 | }; 27 | -------------------------------------------------------------------------------- /src/cpp/models/include/models/detection_model_ssd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "models/detection_model.h" 14 | 15 | namespace ov { 16 | class InferRequest; 17 | class Model; 18 | } // namespace ov 19 | struct InferenceResult; 20 | struct InputData; 21 | struct InternalModelData; 22 | struct ResultBase; 23 | 24 | class ModelSSD : public DetectionModel { 25 | public: 26 | using DetectionModel::DetectionModel; 27 | std::shared_ptr preprocess(const InputData& inputData, InferenceInput& input) override; 28 | std::unique_ptr postprocess(InferenceResult& infResult) override; 29 | static std::string ModelType; 30 | 31 | protected: 32 | std::unique_ptr postprocessSingleOutput(InferenceResult& infResult); 33 | std::unique_ptr postprocessMultipleOutputs(InferenceResult& infResult); 34 | void prepareInputsOutputs(std::shared_ptr& model) override; 35 | void prepareSingleOutput(std::shared_ptr& model); 36 | void prepareMultipleOutputs(std::shared_ptr& model); 37 | void updateModelInfo() override; 38 | }; 39 | -------------------------------------------------------------------------------- /src/cpp/models/include/models/detection_model_yolov3_onnx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "models/detection_model.h" 13 | 14 | class ModelYoloV3ONNX : public DetectionModel { 15 | public: 16 | ModelYoloV3ONNX(std::shared_ptr& model, const ov::AnyMap& configuration); 17 | ModelYoloV3ONNX(std::shared_ptr& adapter); 18 | using DetectionModel::DetectionModel; 19 | 20 | std::unique_ptr postprocess(InferenceResult& infResult) override; 21 | std::shared_ptr preprocess(const InputData& inputData, InferenceInput& input) override; 22 | 23 | protected: 24 | void prepareInputsOutputs(std::shared_ptr& model) override; 25 | void initDefaultParameters(const ov::AnyMap& configuration); 26 | 27 | std::string boxesOutputName; 28 | std::string scoresOutputName; 29 | std::string indicesOutputName; 30 | static const int numberOfClasses = 80; 31 | }; 32 | -------------------------------------------------------------------------------- /src/cpp/models/include/models/detection_model_yolox.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "models/detection_model_ext.h" 13 | 14 | class ModelYoloX : public DetectionModelExt { 15 | public: 16 | ModelYoloX(std::shared_ptr& model, const ov::AnyMap& configuration); 17 | ModelYoloX(std::shared_ptr& adapter); 18 | using DetectionModelExt::DetectionModelExt; 19 | 20 | std::unique_ptr postprocess(InferenceResult& infResult) override; 21 | std::shared_ptr preprocess(const InputData& inputData, InferenceInput& input) override; 22 | static std::string ModelType; 23 | 24 | protected: 25 | void prepareInputsOutputs(std::shared_ptr& model) override; 26 | void setStridesGrids(); 27 | void initDefaultParameters(const ov::AnyMap& configuration); 28 | void updateModelInfo() override; 29 | 30 | float iou_threshold; 31 | std::vector> grids; 32 | std::vector expandedStrides; 33 | static const size_t numberOfClasses = 80; 34 | }; 35 | -------------------------------------------------------------------------------- /src/cpp/models/include/models/input_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | 9 | struct InputData { 10 | virtual ~InputData() {} 11 | 12 | template 13 | T& asRef() { 14 | return dynamic_cast(*this); 15 | } 16 | 17 | template 18 | const T& asRef() const { 19 | return dynamic_cast(*this); 20 | } 21 | }; 22 | 23 | struct ImageInputData : public InputData { 24 | cv::Mat inputImage; 25 | 26 | ImageInputData() {} 27 | ImageInputData(const cv::Mat& img) { 28 | inputImage = img; 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /src/cpp/models/include/models/instance_segmentation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | #include 9 | #include 10 | 11 | #include "models/base_model.h" 12 | 13 | namespace ov { 14 | class Model; 15 | } // namespace ov 16 | struct InferenceResult; 17 | struct ResultBase; 18 | struct InstanceSegmentationResult; 19 | struct ImageInputData; 20 | struct SegmentedObject; 21 | 22 | class MaskRCNNModel : public BaseModel { 23 | public: 24 | MaskRCNNModel(std::shared_ptr& model, const ov::AnyMap& configuration); 25 | MaskRCNNModel(std::shared_ptr& adapter, const ov::AnyMap& configuration = {}); 26 | 27 | static std::unique_ptr create_model(const std::string& modelFile, 28 | const ov::AnyMap& configuration = {}, 29 | bool preload = true, 30 | const std::string& device = "AUTO"); 31 | static std::unique_ptr create_model(std::shared_ptr& adapter); 32 | 33 | std::unique_ptr postprocess(InferenceResult& infResult) override; 34 | 35 | virtual std::unique_ptr infer(const ImageInputData& inputData); 36 | virtual std::vector> inferBatch( 37 | const std::vector& inputImgs); 38 | static std::string ModelType; 39 | bool postprocess_semantic_masks = true; 40 | 41 | protected: 42 | void prepareInputsOutputs(std::shared_ptr& model) override; 43 | void updateModelInfo() override; 44 | void init_from_config(const ov::AnyMap& top_priority, const ov::AnyMap& mid_priority); 45 | std::string getLabelName(size_t labelID) { 46 | return labelID < labels.size() ? labels[labelID] : std::string("Label #") + std::to_string(labelID); 47 | } 48 | 49 | float confidence_threshold = 0.5f; 50 | }; 51 | 52 | cv::Mat segm_postprocess(const SegmentedObject& box, const cv::Mat& unpadded, int im_h, int im_w); 53 | -------------------------------------------------------------------------------- /src/cpp/models/include/models/internal_model_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | 8 | struct InternalModelData { 9 | virtual ~InternalModelData() {} 10 | 11 | template 12 | T& asRef() { 13 | return dynamic_cast(*this); 14 | } 15 | 16 | template 17 | const T& asRef() const { 18 | return dynamic_cast(*this); 19 | } 20 | }; 21 | 22 | struct InternalImageModelData : public InternalModelData { 23 | InternalImageModelData(int width, int height) : inputImgWidth(width), inputImgHeight(height) {} 24 | 25 | int inputImgWidth; 26 | int inputImgHeight; 27 | }; 28 | 29 | struct InternalScaleData : public InternalImageModelData { 30 | InternalScaleData(int width, int height, float scaleX, float scaleY) 31 | : InternalImageModelData(width, height), 32 | scaleX(scaleX), 33 | scaleY(scaleY) {} 34 | 35 | float scaleX; 36 | float scaleY; 37 | }; 38 | -------------------------------------------------------------------------------- /src/cpp/models/include/models/keypoint_detection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2025 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | #include 9 | #include 10 | 11 | #include "models/base_model.h" 12 | 13 | namespace ov { 14 | class Model; 15 | } // namespace ov 16 | struct InferenceResult; 17 | struct ResultBase; 18 | struct KeypointDetectionResult; 19 | struct ImageInputData; 20 | 21 | class KeypointDetectionModel : public BaseModel { 22 | public: 23 | KeypointDetectionModel(std::shared_ptr& model, const ov::AnyMap& configuration); 24 | KeypointDetectionModel(std::shared_ptr& adapter, const ov::AnyMap& configuration = {}); 25 | 26 | static std::unique_ptr create_model(const std::string& modelFile, 27 | const ov::AnyMap& configuration = {}, 28 | bool preload = true, 29 | const std::string& device = "AUTO"); 30 | static std::unique_ptr create_model(std::shared_ptr& adapter); 31 | 32 | std::unique_ptr postprocess(InferenceResult& infResult) override; 33 | 34 | virtual std::unique_ptr infer(const ImageInputData& inputData); 35 | virtual std::vector> inferBatch( 36 | const std::vector& inputImgs); 37 | 38 | static std::string ModelType; 39 | 40 | protected: 41 | bool apply_softmax = true; 42 | 43 | void prepareInputsOutputs(std::shared_ptr& model) override; 44 | void updateModelInfo() override; 45 | void init_from_config(const ov::AnyMap& top_priority, const ov::AnyMap& mid_priority); 46 | }; 47 | -------------------------------------------------------------------------------- /src/cpp/models/include/models/segmentation_model.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | #include 9 | #include 10 | 11 | #include "models/base_model.h" 12 | 13 | namespace ov { 14 | class Model; 15 | } // namespace ov 16 | struct InferenceResult; 17 | struct ResultBase; 18 | struct ImageResult; 19 | struct ImageResultWithSoftPrediction; 20 | struct ImageInputData; 21 | struct Contour; 22 | 23 | class SegmentationModel : public BaseModel { 24 | public: 25 | SegmentationModel(std::shared_ptr& model, const ov::AnyMap& configuration); 26 | SegmentationModel(std::shared_ptr& adapter, const ov::AnyMap& configuration = {}); 27 | 28 | static std::unique_ptr create_model(const std::string& modelFile, 29 | const ov::AnyMap& configuration = {}, 30 | bool preload = true, 31 | const std::string& device = "AUTO"); 32 | static std::unique_ptr create_model(std::shared_ptr& adapter); 33 | 34 | std::unique_ptr postprocess(InferenceResult& infResult) override; 35 | 36 | virtual std::unique_ptr infer(const ImageInputData& inputData); 37 | virtual std::vector> inferBatch(const std::vector& inputImgs); 38 | 39 | static std::string ModelType; 40 | std::vector getContours(const ImageResultWithSoftPrediction& imageResult); 41 | 42 | protected: 43 | void prepareInputsOutputs(std::shared_ptr& model) override; 44 | void updateModelInfo() override; 45 | void init_from_config(const ov::AnyMap& top_priority, const ov::AnyMap& mid_priority); 46 | 47 | int blur_strength = -1; 48 | float soft_threshold = -std::numeric_limits::infinity(); 49 | bool return_soft_prediction = true; 50 | }; 51 | 52 | cv::Mat create_hard_prediction_from_soft_prediction(const cv::Mat& soft_prediction, 53 | float soft_threshold, 54 | int blur_strength); 55 | -------------------------------------------------------------------------------- /src/cpp/models/src/detection_model_ext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | #include "models/detection_model_ext.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "models/base_model.h" 13 | #include "models/input_data.h" 14 | #include "models/results.h" 15 | 16 | DetectionModelExt::DetectionModelExt(std::shared_ptr& model, const ov::AnyMap& configuration) 17 | : DetectionModel(model, configuration) { 18 | auto iou_threshold_iter = configuration.find("iou_threshold"); 19 | if (iou_threshold_iter != configuration.end()) { 20 | iou_threshold = iou_threshold_iter->second.as(); 21 | } else { 22 | if (model->has_rt_info("model_info", "iou_threshold")) { 23 | iou_threshold = model->get_rt_info("model_info", "iou_threshold"); 24 | } 25 | } 26 | } 27 | 28 | DetectionModelExt::DetectionModelExt(std::shared_ptr& adapter) : DetectionModel(adapter) { 29 | const ov::AnyMap& configuration = adapter->getModelConfig(); 30 | auto iou_threshold_iter = configuration.find("iou_threshold"); 31 | if (iou_threshold_iter != configuration.end()) { 32 | iou_threshold = iou_threshold_iter->second.as(); 33 | } 34 | } 35 | 36 | void DetectionModelExt::updateModelInfo() { 37 | DetectionModel::updateModelInfo(); 38 | 39 | model->set_rt_info(iou_threshold, "model_info", "iou_threshold"); 40 | } 41 | -------------------------------------------------------------------------------- /src/cpp/py_bindings/.gitignore: -------------------------------------------------------------------------------- 1 | *.whl 2 | *.dll 3 | *.so* 4 | -------------------------------------------------------------------------------- /src/cpp/py_bindings/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2025 Intel Corporation 2 | # SPDX-License-Identifier: Apache-2.0 3 | # 4 | 5 | cmake_minimum_required(VERSION 3.26) 6 | 7 | if(WIN32) 8 | set(CMAKE_GENERATOR_TOOLSET "v142") 9 | endif() 10 | 11 | 12 | add_subdirectory(../ model_api/cpp) 13 | 14 | set(Python_FIND_VIRTUALENV FIRST) 15 | project(_vision_api LANGUAGES CXX) 16 | find_package(Python COMPONENTS Interpreter Development REQUIRED) 17 | 18 | execute_process( 19 | COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir 20 | OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT) 21 | find_package(nanobind CONFIG REQUIRED) 22 | 23 | 24 | file(GLOB BINDINGS_SOURCES src/vision_api/*.cpp) 25 | file(GLOB BINDINGS_HEADERS src/vision_api/*.hpp) 26 | 27 | message(INFO ${BINDINGS_SOURCES}) 28 | 29 | nanobind_add_module(_vision_api NB_STATIC STABLE_ABI LTO ${BINDINGS_SOURCES} ${BINDINGS_HEADERS}) 30 | 31 | set_target_properties(_vision_api PROPERTIES 32 | LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" 33 | ) 34 | 35 | target_link_libraries(_vision_api PRIVATE model_api) 36 | 37 | install(TARGETS _vision_api 38 | LIBRARY DESTINATION vision_api # Same place relative to package 39 | ) 40 | -------------------------------------------------------------------------------- /src/cpp/py_bindings/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["scikit-build-core >=0.4.3", "nanobind >=1.3.2"] 3 | build-backend = "scikit_build_core.build" 4 | 5 | [project] 6 | name = "vision_api" 7 | version = "0.3.0.2" 8 | requires-python = ">=3.9" 9 | authors = [ 10 | {name = "Intel(R) Corporation"}, 11 | ] 12 | maintainers = [ 13 | {name = "Intel(R) Corporation"}, 14 | ] 15 | description = "Model API: model wrappers and pipelines for inference with OpenVINO" 16 | readme = "../../python/README.md" 17 | classifiers = [ 18 | "License :: OSI Approved :: Apache Software License", 19 | "Programming Language :: Python :: 3.9" 20 | ] 21 | 22 | [project.urls] 23 | Homepage = "https://github.com/open-edge-platform/model_api" 24 | 25 | [tool.scikit-build] 26 | # Protect the configuration against future changes in scikit-build-core 27 | minimum-version = "0.4" 28 | # Setuptools-style build caching in a local directory 29 | build-dir = "build/{wheel_tag}" 30 | # Build stable ABI wheels for CPython 3.12+ 31 | wheel.py-api = "cp312" 32 | sdist.include = ["*.so*"] 33 | -------------------------------------------------------------------------------- /src/cpp/py_bindings/src/vision_api/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2024 Intel Corporation 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | try: 5 | from openvino import Core 6 | 7 | _ = Core() # Triggers loading of shared libs like libopenvino.so 8 | except Exception as e: 9 | raise ImportError(f"Failed to initialize OpenVINO runtime: {e}") 10 | 11 | from ._vision_api import ClassificationModel 12 | 13 | __all__ = [ClassificationModel] 14 | -------------------------------------------------------------------------------- /src/cpp/py_bindings/src/vision_api/py_base.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include "models/base_model.h" 12 | #include "models/results.h" 13 | 14 | namespace nb = nanobind; 15 | 16 | void init_base_modules(nb::module_& m) { 17 | nb::class_(m, "ResultBase").def(nb::init<>()); 18 | 19 | nb::class_(m, "BaseModel") 20 | .def("load", [](BaseModel& self, const std::string& device, size_t num_infer_requests) { 21 | auto core = ov::Core(); 22 | self.load(core, device, num_infer_requests); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /src/cpp/py_bindings/src/vision_api/py_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #include "py_utils.hpp" 7 | 8 | namespace vision::nanobind::utils { 9 | 10 | cv::Mat wrap_np_mat(const nb::ndarray<>& input) { 11 | if (input.ndim() != 3 || input.shape(2) != 3 || input.dtype() != nb::dtype()) { 12 | throw std::runtime_error("Input image should have HWC_8U layout"); 13 | } 14 | 15 | int height = input.shape(0); 16 | int width = input.shape(1); 17 | 18 | return cv::Mat(height, width, CV_8UC3, input.data()); 19 | } 20 | 21 | ov::Any py_object_to_any(const nb::object& py_obj, const std::string& property_name) { 22 | if (nb::isinstance(py_obj)) { 23 | return ov::Any(std::string(static_cast(py_obj).c_str())); 24 | } else if (nb::isinstance(py_obj)) { 25 | return ov::Any(static_cast(static_cast(py_obj))); 26 | } else if (nb::isinstance(py_obj)) { 27 | return ov::Any(static_cast(static_cast(py_obj))); 28 | } else { 29 | OPENVINO_THROW("Property \"" + property_name + "\" has unsupported type."); 30 | } 31 | } 32 | 33 | } // namespace vision::nanobind::utils 34 | -------------------------------------------------------------------------------- /src/cpp/py_bindings/src/vision_api/py_utils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace nb = nanobind; 13 | 14 | namespace vision::nanobind::utils { 15 | cv::Mat wrap_np_mat(const nb::ndarray<>& input); 16 | ov::Any py_object_to_any(const nb::object& py_obj, const std::string& property_name); 17 | } // namespace vision::nanobind::utils 18 | -------------------------------------------------------------------------------- /src/cpp/py_bindings/src/vision_api/py_vision_api.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #include 7 | 8 | namespace nb = nanobind; 9 | 10 | void init_classification(nb::module_& m); 11 | void init_base_modules(nb::module_& m); 12 | 13 | NB_MODULE(_vision_api, m) { 14 | m.doc() = "Nanobind binding for OpenVINO Vision API library"; 15 | init_base_modules(m); 16 | init_classification(m); 17 | } 18 | -------------------------------------------------------------------------------- /src/cpp/tilers/include/tilers/detection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | 9 | struct DetectionResult; 10 | 11 | class DetectionTiler : public TilerBase { 12 | public: 13 | DetectionTiler(const std::shared_ptr& model, 14 | const ov::AnyMap& configuration, 15 | ExecutionMode exec_mode = ExecutionMode::sync); 16 | virtual ~DetectionTiler() = default; 17 | 18 | virtual std::unique_ptr run(const ImageInputData& inputData); 19 | 20 | protected: 21 | virtual std::unique_ptr postprocess_tile(std::unique_ptr, const cv::Rect&); 22 | virtual std::unique_ptr merge_results(const std::vector>&, 23 | const cv::Size&, 24 | const std::vector&); 25 | ov::Tensor merge_saliency_maps(const std::vector>&, 26 | const cv::Size&, 27 | const std::vector&); 28 | 29 | size_t max_pred_number = 200; 30 | }; 31 | -------------------------------------------------------------------------------- /src/cpp/tilers/include/tilers/instance_segmentation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | 9 | struct InstanceSegmentationResult; 10 | 11 | class InstanceSegmentationTiler : public TilerBase { 12 | /*InstanceSegmentationTiler tiler works with MaskRCNNModel model only*/ 13 | public: 14 | InstanceSegmentationTiler(std::shared_ptr model, 15 | const ov::AnyMap& configuration, 16 | ExecutionMode exec_mode = ExecutionMode::sync); 17 | virtual std::unique_ptr run(const ImageInputData& inputData); 18 | virtual ~InstanceSegmentationTiler() = default; 19 | bool postprocess_semantic_masks = true; 20 | 21 | protected: 22 | virtual std::unique_ptr postprocess_tile(std::unique_ptr, const cv::Rect&); 23 | virtual std::unique_ptr merge_results(const std::vector>&, 24 | const cv::Size&, 25 | const std::vector&); 26 | 27 | std::vector> merge_saliency_maps(const std::vector>&, 28 | const cv::Size&, 29 | const std::vector&); 30 | 31 | size_t max_pred_number = 200; 32 | }; 33 | -------------------------------------------------------------------------------- /src/cpp/tilers/include/tilers/semantic_segmentation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | 9 | struct ImageResult; 10 | struct ImageResultWithSoftPrediction; 11 | 12 | class SemanticSegmentationTiler : public TilerBase { 13 | public: 14 | SemanticSegmentationTiler(std::shared_ptr model, 15 | const ov::AnyMap& configuration, 16 | ExecutionMode exec_mode = ExecutionMode::sync); 17 | virtual std::unique_ptr run(const ImageInputData& inputData); 18 | virtual ~SemanticSegmentationTiler() = default; 19 | 20 | protected: 21 | virtual std::unique_ptr postprocess_tile(std::unique_ptr, const cv::Rect&); 22 | virtual std::unique_ptr merge_results(const std::vector>&, 23 | const cv::Size&, 24 | const std::vector&); 25 | 26 | int blur_strength = -1; 27 | float soft_threshold = -std::numeric_limits::infinity(); 28 | bool return_soft_prediction = true; 29 | }; 30 | -------------------------------------------------------------------------------- /src/cpp/tilers/include/tilers/tiler_base.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | struct ResultBase; 18 | 19 | enum class ExecutionMode { sync, async }; 20 | 21 | class TilerBase { 22 | public: 23 | TilerBase(const std::shared_ptr& model, 24 | const ov::AnyMap& configuration, 25 | ExecutionMode exec_mode = ExecutionMode::sync); 26 | 27 | virtual ~TilerBase() = default; 28 | 29 | protected: 30 | virtual std::unique_ptr run_impl(const ImageInputData& inputData); 31 | std::vector tile(const cv::Size&); 32 | std::vector filter_tiles(const cv::Mat&, const std::vector&); 33 | std::unique_ptr predict_sync(const cv::Mat&, const std::vector&); 34 | std::unique_ptr predict_async(const cv::Mat&, const std::vector&); 35 | cv::Mat crop_tile(const cv::Mat&, const cv::Rect&); 36 | virtual std::unique_ptr postprocess_tile(std::unique_ptr, const cv::Rect&) = 0; 37 | virtual std::unique_ptr merge_results(const std::vector>&, 38 | const cv::Size&, 39 | const std::vector&) = 0; 40 | 41 | std::shared_ptr model; 42 | size_t tile_size = 400; 43 | float tiles_overlap = 0.5f; 44 | float iou_threshold = 0.45f; 45 | bool tile_with_full_img = true; 46 | ExecutionMode run_mode = ExecutionMode::sync; 47 | }; 48 | -------------------------------------------------------------------------------- /src/cpp/utils/include/utils/args_helper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018-2024 Intel Corporation 2 | // SPDX-License-Identifier: Apache-2.0 3 | // 4 | 5 | /** 6 | * @brief a header file with common samples functionality 7 | * @file args_helper.hpp 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | std::vector split(const std::string& s, char delim); 20 | 21 | std::vector parseDevices(const std::string& device_string); 22 | 23 | std::map parseValuePerDevice(const std::set& devices, 24 | const std::string& values_string); 25 | 26 | std::map parseLayoutString(const std::string& layout_string); 27 | 28 | std::string formatLayouts(const std::map& layouts); 29 | 30 | template 31 | Type get_from_any_maps(const std::string& key, 32 | const ov::AnyMap& top_priority, 33 | const ov::AnyMap& mid_priority, 34 | Type low_priority) { 35 | auto topk_iter = top_priority.find(key); 36 | if (topk_iter != top_priority.end()) { 37 | return topk_iter->second.as(); 38 | } 39 | topk_iter = mid_priority.find(key); 40 | if (topk_iter != mid_priority.end()) { 41 | return topk_iter->second.as(); 42 | } 43 | return low_priority; 44 | } 45 | 46 | template <> 47 | inline bool get_from_any_maps(const std::string& key, 48 | const ov::AnyMap& top_priority, 49 | const ov::AnyMap& mid_priority, 50 | bool low_priority) { 51 | auto topk_iter = top_priority.find(key); 52 | if (topk_iter != top_priority.end()) { 53 | const std::string& val = topk_iter->second.as(); 54 | return val == "True" || val == "YES"; 55 | } 56 | topk_iter = mid_priority.find(key); 57 | if (topk_iter != mid_priority.end()) { 58 | const std::string& val = topk_iter->second.as(); 59 | return val == "True" || val == "YES"; 60 | } 61 | return low_priority; 62 | } 63 | -------------------------------------------------------------------------------- /src/cpp/utils/include/utils/async_infer_queue.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (C) 2024 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | class AsyncInferQueue { 24 | public: 25 | AsyncInferQueue() = default; 26 | AsyncInferQueue(ov::CompiledModel& model, size_t jobs); 27 | ~AsyncInferQueue() = default; 28 | 29 | bool is_ready(); 30 | size_t get_idle_request_id(); 31 | void wait_all(); 32 | void set_default_callbacks(); 33 | void set_custom_callbacks( 34 | std::function callback_args)> f_callback); 35 | size_t size() const; 36 | void start_async(const ov::Tensor& input, std::shared_ptr userdata = nullptr); 37 | void start_async(const std::map& input, std::shared_ptr userdata = nullptr); 38 | ov::InferRequest operator[](size_t i); 39 | 40 | // AsyncInferQueue is not the sole owner of infer requests, although it calls create_infer_request() method. 41 | // ov::InferRequest contains a shared pointer internally, and therefore requests can be copied by clients of 42 | // AsyncInferQueue. 43 | protected: 44 | std::vector m_requests; 45 | std::queue m_idle_handles; 46 | std::vector> m_user_ids; 47 | std::mutex m_mutex; 48 | std::condition_variable m_cv; 49 | std::queue> m_errors; 50 | }; 51 | -------------------------------------------------------------------------------- /src/cpp/utils/include/utils/common.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018-2024 Intel Corporation 2 | // SPDX-License-Identifier: Apache-2.0 3 | // 4 | 5 | /** 6 | * @brief a header file with common samples functionality 7 | * @file common.hpp 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "utils/slog.hpp" 19 | 20 | template 21 | constexpr std::size_t arraySize(const T (&)[N]) noexcept { 22 | return N; 23 | } 24 | 25 | template 26 | T clamp(T value, T low, T high) { 27 | return value < low ? low : (value > high ? high : value); 28 | } 29 | 30 | static inline void logBasicModelInfo(const std::shared_ptr& model) { 31 | slog::info << "Model name: " << model->get_friendly_name() << slog::endl; 32 | 33 | // Dump information about model inputs/outputs 34 | ov::OutputVector inputs = model->inputs(); 35 | ov::OutputVector outputs = model->outputs(); 36 | 37 | slog::info << "\tInputs: " << slog::endl; 38 | for (const ov::Output& input : inputs) { 39 | const std::string name = input.get_any_name(); 40 | const ov::element::Type type = input.get_element_type(); 41 | const ov::PartialShape shape = input.get_partial_shape(); 42 | const ov::Layout layout = ov::layout::get_layout(input); 43 | 44 | slog::info << "\t\t" << name << ", " << type << ", " << shape << ", " << layout.to_string() << slog::endl; 45 | } 46 | 47 | slog::info << "\tOutputs: " << slog::endl; 48 | for (const ov::Output& output : outputs) { 49 | const std::string name = output.get_names().size() ? output.get_any_name() : ""; 50 | const ov::element::Type type = output.get_element_type(); 51 | const ov::PartialShape shape = output.get_partial_shape(); 52 | const ov::Layout layout = ov::layout::get_layout(output); 53 | 54 | slog::info << "\t\t" << name << ", " << type << ", " << shape << ", " << layout.to_string() << slog::endl; 55 | } 56 | 57 | return; 58 | } 59 | -------------------------------------------------------------------------------- /src/cpp/utils/include/utils/image_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2024 Intel Corporation 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | enum RESIZE_MODE { 12 | RESIZE_FILL, 13 | RESIZE_KEEP_ASPECT, 14 | RESIZE_KEEP_ASPECT_LETTERBOX, 15 | RESIZE_CROP, 16 | NO_RESIZE, 17 | }; 18 | 19 | inline std::string formatResizeMode(RESIZE_MODE mode) { 20 | switch (mode) { 21 | case RESIZE_FILL: 22 | return "standard"; 23 | case RESIZE_KEEP_ASPECT: 24 | return "fit_to_window"; 25 | case RESIZE_KEEP_ASPECT_LETTERBOX: 26 | return "fit_to_window_letterbox"; 27 | case RESIZE_CROP: 28 | return "crop"; 29 | default: 30 | return "unknown"; 31 | } 32 | } 33 | 34 | cv::Mat resizeImageExt(const cv::Mat& mat, 35 | int width, 36 | int height, 37 | RESIZE_MODE resizeMode = RESIZE_FILL, 38 | cv::InterpolationFlags interpolationMode = cv::INTER_LINEAR, 39 | cv::Rect* roi = nullptr, 40 | cv::Scalar BorderConstant = cv::Scalar(0, 0, 0)); 41 | 42 | ov::preprocess::PostProcessSteps::CustomPostprocessOp createResizeGraph(RESIZE_MODE resizeMode, 43 | const ov::Shape& size, 44 | const cv::InterpolationFlags interpolationMode, 45 | uint8_t pad_value); 46 | -------------------------------------------------------------------------------- /src/cpp/utils/include/utils/kuhn_munkres.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018-2024 Intel Corporation 2 | // SPDX-License-Identifier: Apache-2.0 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | #include "opencv2/core.hpp" 11 | 12 | /// 13 | /// \brief The KuhnMunkres class 14 | /// 15 | /// Solves the assignment problem. 16 | /// 17 | class KuhnMunkres { 18 | public: 19 | /// 20 | /// \brief Initializes the class for assignment problem solving. 21 | /// \param[in] greedy If a faster greedy matching algorithm should be used. 22 | explicit KuhnMunkres(bool greedy = false); 23 | 24 | /// 25 | /// \brief Solves the assignment problem for given dissimilarity matrix. 26 | /// It returns a vector that where each element is a column index for 27 | /// corresponding row (e.g. result[0] stores optimal column index for very 28 | /// first row in the dissimilarity matrix). 29 | /// \param dissimilarity_matrix CV_32F dissimilarity matrix. 30 | /// \return Optimal column index for each row. -1 means that there is no 31 | /// column for row. 32 | /// 33 | std::vector Solve(const cv::Mat& dissimilarity_matrix); 34 | 35 | private: 36 | static constexpr int kStar = 1; 37 | static constexpr int kPrime = 2; 38 | 39 | cv::Mat dm_; 40 | cv::Mat marked_; 41 | std::vector points_; 42 | 43 | std::vector is_row_visited_; 44 | std::vector is_col_visited_; 45 | 46 | int n_; 47 | bool greedy_; 48 | 49 | void TrySimpleCase(); 50 | bool CheckIfOptimumIsFound(); 51 | cv::Point FindUncoveredMinValPos(); 52 | void UpdateDissimilarityMatrix(float val); 53 | int FindInRow(int row, int what); 54 | int FindInCol(int col, int what); 55 | void Run(); 56 | }; 57 | -------------------------------------------------------------------------------- /src/cpp/utils/include/utils/performance_metrics.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2020-2024 Intel Corporation 2 | // SPDX-License-Identifier: Apache-2.0 3 | // 4 | 5 | /** 6 | * @brief a header file for performance metrics calculation class 7 | * @file performance_metrics.hpp 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "utils/ocv_common.hpp" 18 | 19 | class PerformanceMetrics { 20 | public: 21 | using Clock = std::chrono::steady_clock; 22 | using TimePoint = std::chrono::time_point; 23 | using Duration = Clock::duration; 24 | using Ms = std::chrono::duration>; 25 | using Sec = std::chrono::duration>; 26 | 27 | struct Metrics { 28 | double latency; 29 | double fps; 30 | }; 31 | 32 | enum MetricTypes { ALL, FPS, LATENCY }; 33 | 34 | PerformanceMetrics(Duration timeWindow = std::chrono::seconds(1)); 35 | void update(TimePoint lastRequestStartTime, 36 | const cv::Mat& frame, 37 | cv::Point position = {15, 30}, 38 | int fontFace = cv::FONT_HERSHEY_COMPLEX, 39 | double fontScale = 0.75, 40 | cv::Scalar color = {200, 10, 10}, 41 | int thickness = 2, 42 | MetricTypes metricType = ALL); 43 | void update(TimePoint lastRequestStartTime); 44 | 45 | /// Paints metrics over provided mat 46 | /// @param frame frame to paint over 47 | /// @param position left top corner of text block 48 | /// @param fontScale font scale 49 | /// @param color font color 50 | /// @param thickness font thickness 51 | void paintMetrics(const cv::Mat& frame, 52 | cv::Point position = {15, 30}, 53 | int fontFace = cv::FONT_HERSHEY_COMPLEX, 54 | double fontScale = 0.75, 55 | cv::Scalar color = {200, 10, 10}, 56 | int thickness = 2, 57 | MetricTypes metricType = ALL) const; 58 | 59 | Metrics getLast() const; 60 | Metrics getTotal() const; 61 | void logTotal() const; 62 | 63 | private: 64 | struct Statistic { 65 | Duration latency; 66 | Duration period; 67 | int frameCount; 68 | 69 | Statistic() { 70 | latency = Duration::zero(); 71 | period = Duration::zero(); 72 | frameCount = 0; 73 | } 74 | 75 | void combine(const Statistic& other) { 76 | latency += other.latency; 77 | period += other.period; 78 | frameCount += other.frameCount; 79 | } 80 | }; 81 | 82 | Duration timeWindowSize; 83 | Statistic lastMovingStatistic; 84 | Statistic currentMovingStatistic; 85 | Statistic totalStatistic; 86 | TimePoint lastUpdateTime; 87 | bool firstFrameProcessed; 88 | }; 89 | -------------------------------------------------------------------------------- /src/cpp/utils/include/utils/slog.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018-2024 Intel Corporation 2 | // SPDX-License-Identifier: Apache-2.0 3 | // 4 | 5 | /** 6 | * @brief a header file with logging facility for common samples 7 | * @file log.hpp 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | namespace slog { 16 | 17 | /** 18 | * @class LogStreamEndLine 19 | * @brief The LogStreamEndLine class implements an end line marker for a log stream 20 | */ 21 | class LogStreamEndLine {}; 22 | 23 | static constexpr LogStreamEndLine endl; 24 | 25 | /** 26 | * @class LogStreamBoolAlpha 27 | * @brief The LogStreamBoolAlpha class implements bool printing for a log stream 28 | */ 29 | class LogStreamBoolAlpha {}; 30 | 31 | static constexpr LogStreamBoolAlpha boolalpha; 32 | 33 | /** 34 | * @class LogStream 35 | * @brief The LogStream class implements a stream for sample logging 36 | */ 37 | class LogStream { 38 | std::string _prefix; 39 | std::ostream* _log_stream; 40 | bool _new_line; 41 | 42 | public: 43 | /** 44 | * @brief A constructor. Creates a LogStream object 45 | * @param prefix The prefix to print 46 | */ 47 | LogStream(const std::string& prefix, std::ostream& log_stream) : _prefix(prefix), _new_line(true) { 48 | _log_stream = &log_stream; 49 | } 50 | 51 | /** 52 | * @brief A stream output operator to be used within the logger 53 | * @param arg Object for serialization in the logger message 54 | */ 55 | template 56 | LogStream& operator<<(const T& arg) { 57 | if (_new_line) { 58 | (*_log_stream) << "[ " << _prefix << " ] "; 59 | _new_line = false; 60 | } 61 | 62 | (*_log_stream) << arg; 63 | return *this; 64 | } 65 | 66 | // Specializing for LogStreamEndLine to support slog::endl 67 | LogStream& operator<<(const LogStreamEndLine& /*arg*/) { 68 | _new_line = true; 69 | 70 | (*_log_stream) << std::endl; 71 | return *this; 72 | } 73 | 74 | // Specializing for LogStreamBoolAlpha to support slog::boolalpha 75 | LogStream& operator<<(const LogStreamBoolAlpha& /*arg*/) { 76 | (*_log_stream) << std::boolalpha; 77 | return *this; 78 | } 79 | 80 | // Specializing for std::vector and std::list 81 | template