-
Notifications
You must be signed in to change notification settings - Fork 18
CPP Python bindings accuracy tests #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RHeckerIntel
wants to merge
41
commits into
open-edge-platform:master
Choose a base branch
from
RHeckerIntel:rhecker/py-bindings-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
7c89b2a
Add tests for py bindings
sovrasov 12c7e0d
Fix linter
sovrasov 18d1cb9
Del outdated OMZ model
sovrasov 75ffbf8
Disable yolo python tests
sovrasov 7829746
Disable cpp yolo tests as well
sovrasov df10b25
Minor fixes in cpp samples
sovrasov 9dd9fcb
Update cmake in tests
sovrasov ae532aa
Revert py OV in tests cmake
sovrasov ad192ab
Use python from venv only
sovrasov 6d2de0c
Specify python dir manually
sovrasov 0e2f3cb
Merge remote-tracking branch 'origin/master' into vs/bindings_tests
sovrasov 16c7bbd
Enable bindings in cpp accuracy tests
sovrasov 6cbce37
Merge remote-tracking branch 'origin/master' into vs/bindings_tests
sovrasov 6ef53ed
Merge ModelBase into ImageModel
RHeckerIntel d029524
Merge branch 'master' into rhecker/refactor
RHeckerIntel 7bc1bbe
Fix clang linter
RHeckerIntel a068643
Merge branch 'master' into rhecker/refactor
RHeckerIntel ccbfcbb
Rename ImageModel to BaseModel
RHeckerIntel 312a2dc
Python binding compilation test area
RHeckerIntel fb07cb5
Working with openvino from python package.
RHeckerIntel 0ec186d
Add Dockerfile for building the python bindings from c++
RHeckerIntel 4decb8f
Working python wheel package with only opencv as dependency
RHeckerIntel fbed5dd
Clean up the Dockerfile.ubuntu for building the python package
RHeckerIntel bc001ff
Remove rpath setting
RHeckerIntel ffc65ea
Extract opencv dependencies and setup windows part too
RHeckerIntel 3fb1326
Clean up cmakelists, sadly its been broken since last couple commits
RHeckerIntel 0a81303
Revert "Clean up cmakelists, sadly its been broken since last couple …
RHeckerIntel cb0020c
Revert "Extract opencv dependencies and setup windows part too"
RHeckerIntel 0d655cb
Fix cmake file properly now for ubuntu
RHeckerIntel a229e7f
Fixing windows build again
RHeckerIntel bd0f4a5
Merge remote-tracking branch 'vlad/vs/bindings_tests' into rhecker/py…
RHeckerIntel cd9bf79
Fix tests for cpp-py so that they run, not working yet
RHeckerIntel 230547e
Merge branch 'master' into rhecker/py-bindings-tests
RHeckerIntel ff67f11
Try to fix workflow
RHeckerIntel a263dd9
Remove cpp tests and use venv for building package
RHeckerIntel df0a356
Remove the broken test and enable cpp tests again
RHeckerIntel 09765a7
Clean up a bit
RHeckerIntel dd7383c
make sure the .so's are included.
RHeckerIntel 35ade26
Apply feedback, remove docker files
RHeckerIntel 831f18b
Rename the py project for py bindings to vision api
RHeckerIntel 4f793e4
Debug why model api is not found
RHeckerIntel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.whl | ||
*.dll | ||
*.so* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
find_package(OpenCV REQUIRED COMPONENTS core imgproc) | ||
|
||
if (MSVC) | ||
set(DEPENDENCIES_TO_COPY | ||
"${__location_release}" | ||
) | ||
else() | ||
find_package(PkgConfig REQUIRED) | ||
find_package(TBB "2021.5.0" EXACT REQUIRED) | ||
pkg_check_modules(TBB REQUIRED tbb) | ||
|
||
set(DEPENDENCIES_TO_COPY | ||
${OpenCV_DIR}/../../libopencv_core.so.4.5d | ||
${OpenCV_DIR}/../../libopencv_imgproc.so.4.5d | ||
${pkgcfg_lib_TBB_tbb}.2 # ubuntu system package uses tbb.so.2 | ||
) | ||
endif() | ||
|
||
set(PYTHON_PACKAGE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/vision_api) | ||
foreach(lib ${DEPENDENCIES_TO_COPY}) | ||
add_custom_command( | ||
TARGET _vision_api POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy | ||
${lib} | ||
${PYTHON_PACKAGE_DIR} | ||
COMMENT "Copying ${lib} to ${PYTHON_PACKAGE_DIR}" | ||
) | ||
endforeach() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[build-system] | ||
requires = ["scikit-build-core >=0.4.3", "nanobind >=1.3.2"] | ||
build-backend = "scikit_build_core.build" | ||
|
||
[project] | ||
name = "vision_api" | ||
version = "0.3.0.2" | ||
requires-python = ">=3.9" | ||
authors = [ | ||
sovrasov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{name = "Intel(R) Corporation"}, | ||
] | ||
maintainers = [ | ||
{name = "Intel(R) Corporation"}, | ||
] | ||
description = "Model API: model wrappers and pipelines for inference with OpenVINO" | ||
readme = "../../python/README.md" | ||
classifiers = [ | ||
"License :: OSI Approved :: Apache Software License", | ||
"Programming Language :: Python :: 3.9" | ||
] | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/open-edge-platform/model_api" | ||
|
||
[tool.scikit-build] | ||
# Protect the configuration against future changes in scikit-build-core | ||
minimum-version = "0.4" | ||
# Setuptools-style build caching in a local directory | ||
build-dir = "build/{wheel_tag}" | ||
# Build stable ABI wheels for CPython 3.12+ | ||
wheel.py-api = "cp312" | ||
sdist.include = ["*.so*"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env python3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we actually need that sample? Can be moved to tests as well |
||
|
||
from vision_api import ClassificationModel | ||
import cv2 | ||
|
||
import sys | ||
|
||
if len(sys.argv) != 3: | ||
raise RuntimeError(f"Usage: {sys.argv[0]} <path_to_model> <path_to_image>") | ||
|
||
model_path = sys.argv[1] | ||
image_path = sys.argv[2] | ||
|
||
model = ClassificationModel.create_model(model_path) | ||
image = cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB) | ||
model(image) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
try: | ||
from openvino import Core | ||
|
||
_ = Core() # Triggers loading of shared libs like libopenvino.so | ||
except Exception as e: | ||
raise ImportError(f"Failed to initialize OpenVINO runtime: {e}") | ||
|
||
from ._vision_api import ClassificationModel | ||
|
||
__all__ = [ClassificationModel] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# Copyright (C) 2025 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption("--data", action="store", help="data folder with dataset") | ||
parser.addoption("--config", action="store", help="path to models config") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# | ||
# Copyright (C) 2025 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
import pytest | ||
import json | ||
from pathlib import Path | ||
|
||
import cv2 | ||
|
||
from model_api.models import Model | ||
from vision_api import ClassificationModel | ||
|
||
|
||
def read_config(models_config: str, model_type: str): | ||
with open(models_config, "r") as f: | ||
data = json.load(f) | ||
for item in data: | ||
if item["type"] == model_type: | ||
yield item | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def data(pytestconfig) -> str: | ||
return pytestconfig.getoption("data") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def models_config(pytestconfig) -> str: | ||
return pytestconfig.getoption("config") | ||
|
||
|
||
@pytest.fixture() | ||
def classification_configs(models_config: str): | ||
return read_config(models_config, "ClassificationModel") | ||
|
||
|
||
def test_classification_models(data: str, classification_configs): | ||
for model_data in classification_configs: | ||
name = model_data["name"] | ||
if ".xml" not in name: | ||
continue | ||
if name.endswith(".xml") or name.endswith(".onnx"): | ||
name = f"{data}/{name}" | ||
|
||
model = Model.create_model(name, preload=True) | ||
cpp_model = ClassificationModel.create_model(name, preload=True) | ||
|
||
image_path = Path(data) / next(iter(model_data["test_data"]))["image"] | ||
image = cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB) | ||
|
||
py_result = model(image) | ||
cpp_result = cpp_model(image) | ||
|
||
assert str(py_result) == str(cpp_result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Binaries are dumped to the source dir, which looks a bit weird. Can we use the build dir for that?