Skip to content
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

Prevent AcLauncher for OpenVINO 2024.0 #1450

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## May 2024 Release 1.6.1

### Enhancements
- Prevent AcLauncher for OpenVINO 2024.0
(<https://github.com/openvinotoolkit/datumaro/pull/1450>)

### Bug fixes
- Relax Pillow dependency constraint
(<https://github.com/openvinotoolkit/datumaro/pull/1436>)
Expand Down
2 changes: 1 addition & 1 deletion requirements-core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ requests
pandas~=1.4.0

# OpenVINO
openvino>=2023.2.0,<2024.0.0 # Accuracy checker is deprecated >=2024.0.0
openvino>=2023.2.0
tokenizers

# Encryption
Expand Down
4 changes: 2 additions & 2 deletions src/datumaro/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ You need to add Python decorator to specify extra deps for the plugin class defi
This is required during the built-in plugin registration step to determine if a plugin is available by checking if its dependencies are installed on the system.

For example, `AcLauncher` plugin needs `tensorflow` and `openvino.tools` extra dependencies.
Therefore, it added `@extra_deps("tensorflow", "openvino.tools")` to its class definition as follows.
Therefore, it added `@extra_deps("tensorflow", "openvino.tools.accuracy_checker")` to its class definition as follows.

```python
from datumaro.components.lazy_plugin import extra_deps

@extra_deps("tensorflow", "openvino.tools")
@extra_deps("tensorflow", "openvino.tools.accuracy_checker")
class AcLauncher(Launcher, CliPlugin):
...
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .details.ac import GenericAcLauncher as _GenericAcLauncher


@extra_deps("openvino.tools", "tensorflow")
@extra_deps("tensorflow", "openvino.tools.accuracy_checker")
class AcLauncher(Launcher, CliPlugin):
"""
Generic model launcher with Accuracy Checker backend.
Expand Down
179 changes: 94 additions & 85 deletions src/datumaro/plugins/accuracy_checker_plugin/details/ac.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,109 +4,118 @@

from itertools import groupby

from openvino.tools.accuracy_checker.adapters import create_adapter
from openvino.tools.accuracy_checker.data_readers import DataRepresentation
from openvino.tools.accuracy_checker.launcher import InputFeeder, create_launcher
from openvino.tools.accuracy_checker.postprocessor import PostprocessingExecutor
from openvino.tools.accuracy_checker.preprocessor import PreprocessingExecutor
from openvino.tools.accuracy_checker.utils import extract_image_representations

from datumaro.components.annotation import AnnotationType, LabelCategories

from .representation import import_predictions


class _FakeDataset:
def __init__(self, metadata=None):
self.metadata = metadata or {}


class GenericAcLauncher:
@staticmethod
def from_config(config):
launcher_config = config["launcher"]
launcher = create_launcher(launcher_config)

dataset = _FakeDataset()
adapter_config = config.get("adapter") or launcher_config.get("adapter")
label_config = adapter_config.get("labels") if isinstance(adapter_config, dict) else None
if label_config:
assert isinstance(label_config, (list, dict))
if isinstance(label_config, list):
label_config = dict(enumerate(label_config))

dataset.metadata = {
"label_map": {int(key): label for key, label in label_config.items()}
}
adapter = create_adapter(adapter_config, launcher, dataset)

preproc_config = config.get("preprocessing")
preproc = None
if preproc_config:
preproc = PreprocessingExecutor(
preproc_config,
dataset_meta=dataset.metadata,
input_shapes=launcher.inputs_info_for_meta(),
try:
from openvino.tools.accuracy_checker.adapters import create_adapter
from openvino.tools.accuracy_checker.data_readers import DataRepresentation
from openvino.tools.accuracy_checker.launcher import InputFeeder, create_launcher
from openvino.tools.accuracy_checker.postprocessor import PostprocessingExecutor
from openvino.tools.accuracy_checker.preprocessor import PreprocessingExecutor
from openvino.tools.accuracy_checker.utils import extract_image_representations

Check warning on line 17 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L11-L17

Added lines #L11 - L17 were not covered by tests

class _FakeDataset:
def __init__(self, metadata=None):
self.metadata = metadata or {}

Check warning on line 21 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L19-L21

Added lines #L19 - L21 were not covered by tests

class GenericAcLauncher:
@staticmethod
def from_config(config):
launcher_config = config["launcher"]
launcher = create_launcher(launcher_config)

Check warning on line 27 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L23-L27

Added lines #L23 - L27 were not covered by tests

dataset = _FakeDataset()
adapter_config = config.get("adapter") or launcher_config.get("adapter")
label_config = (

Check warning on line 31 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L29-L31

Added lines #L29 - L31 were not covered by tests
adapter_config.get("labels") if isinstance(adapter_config, dict) else None
)

postproc_config = config.get("postprocessing")
postproc = None
if postproc_config:
postproc = PostprocessingExecutor(
postproc_config,
dataset_meta=dataset.metadata,
if label_config:
assert isinstance(label_config, (list, dict))

Check warning on line 35 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L35

Added line #L35 was not covered by tests
if isinstance(label_config, list):
label_config = dict(enumerate(label_config))

Check warning on line 37 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L37

Added line #L37 was not covered by tests

dataset.metadata = {
"label_map": {int(key): label for key, label in label_config.items()}
}
adapter = create_adapter(adapter_config, launcher, dataset)

Check warning on line 42 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L42

Added line #L42 was not covered by tests

preproc_config = config.get("preprocessing")
preproc = None

Check warning on line 45 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L44-L45

Added lines #L44 - L45 were not covered by tests
if preproc_config:
preproc = PreprocessingExecutor(

Check warning on line 47 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L47

Added line #L47 was not covered by tests
preproc_config,
dataset_meta=dataset.metadata,
input_shapes=launcher.inputs_info_for_meta(),
)

postproc_config = config.get("postprocessing")
postproc = None

Check warning on line 54 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L53-L54

Added lines #L53 - L54 were not covered by tests
if postproc_config:
postproc = PostprocessingExecutor(

Check warning on line 56 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L56

Added line #L56 was not covered by tests
postproc_config,
dataset_meta=dataset.metadata,
)

return __class__(launcher, adapter=adapter, preproc=preproc, postproc=postproc)

Check warning on line 61 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L61

Added line #L61 was not covered by tests

def __init__(self, launcher, adapter=None, preproc=None, postproc=None, input_feeder=None):
self._launcher = launcher
self._input_feeder = input_feeder or InputFeeder(

Check warning on line 65 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L63-L65

Added lines #L63 - L65 were not covered by tests
launcher.config.get("inputs", []),
launcher.inputs,
launcher.fit_to_input,
launcher.default_layout,
)
self._adapter = adapter
self._preproc = preproc
self._postproc = postproc

Check warning on line 73 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L71-L73

Added lines #L71 - L73 were not covered by tests

return __class__(launcher, adapter=adapter, preproc=preproc, postproc=postproc)
self._categories = self._init_categories()

Check warning on line 75 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L75

Added line #L75 was not covered by tests

def __init__(self, launcher, adapter=None, preproc=None, postproc=None, input_feeder=None):
self._launcher = launcher
self._input_feeder = input_feeder or InputFeeder(
launcher.config.get("inputs", []),
launcher.inputs,
launcher.fit_to_input,
launcher.default_layout,
)
self._adapter = adapter
self._preproc = preproc
self._postproc = postproc
def launch_raw(self, inputs):
ids = range(len(inputs))

Check warning on line 78 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L77-L78

Added lines #L77 - L78 were not covered by tests
inputs = [DataRepresentation(inp, identifier=id) for id, inp in zip(ids, inputs)]
_, batch_meta = extract_image_representations(inputs)

Check warning on line 80 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L80

Added line #L80 was not covered by tests

self._categories = self._init_categories()
if self._preproc:
inputs = self._preproc.process(inputs)

Check warning on line 83 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L83

Added line #L83 was not covered by tests

def launch_raw(self, inputs):
ids = range(len(inputs))
inputs = [DataRepresentation(inp, identifier=id) for id, inp in zip(ids, inputs)]
_, batch_meta = extract_image_representations(inputs)
inputs = self._input_feeder.fill_inputs(inputs)
outputs = self._launcher.predict(inputs, batch_meta)

Check warning on line 86 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L85-L86

Added lines #L85 - L86 were not covered by tests

if self._preproc:
inputs = self._preproc.process(inputs)
if self._adapter:
outputs = self._adapter.process(outputs, ids, batch_meta)

Check warning on line 89 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L89

Added line #L89 was not covered by tests

inputs = self._input_feeder.fill_inputs(inputs)
outputs = self._launcher.predict(inputs, batch_meta)
if self._postproc:
outputs = self._postproc.process(outputs)

Check warning on line 92 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L92

Added line #L92 was not covered by tests

if self._adapter:
outputs = self._adapter.process(outputs, ids, batch_meta)
return outputs

Check warning on line 94 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L94

Added line #L94 was not covered by tests

if self._postproc:
outputs = self._postproc.process(outputs)
def launch(self, inputs):
outputs = self.launch_raw(inputs)

Check warning on line 97 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L96-L97

Added lines #L96 - L97 were not covered by tests
return [import_predictions(g) for _, g in groupby(outputs, key=lambda o: o.identifier)]

return outputs
def categories(self):
return self._categories

Check warning on line 101 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L100-L101

Added lines #L100 - L101 were not covered by tests

def launch(self, inputs):
outputs = self.launch_raw(inputs)
return [import_predictions(g) for _, g in groupby(outputs, key=lambda o: o.identifier)]
def _init_categories(self):

Check warning on line 103 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L103

Added line #L103 was not covered by tests
if self._adapter is None or self._adapter.label_map is None:
return None

Check warning on line 105 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L105

Added line #L105 was not covered by tests

def categories(self):
return self._categories
label_map = sorted(self._adapter.label_map.items(), key=lambda e: e[0])

def _init_categories(self):
if self._adapter is None or self._adapter.label_map is None:
return None
label_cat = LabelCategories()

Check warning on line 109 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L109

Added line #L109 was not covered by tests
for _, label in label_map:
label_cat.add(label)

Check warning on line 111 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L111

Added line #L111 was not covered by tests

label_map = sorted(self._adapter.label_map.items(), key=lambda e: e[0])
return {AnnotationType.label: label_cat}

Check warning on line 113 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L113

Added line #L113 was not covered by tests

label_cat = LabelCategories()
for _, label in label_map:
label_cat.add(label)
except ImportError:

Check warning on line 115 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L115

Added line #L115 was not covered by tests

return {AnnotationType.label: label_cat}
class GenericAcLauncher:
def __init__(self):
raise ImportError(

Check warning on line 119 in src/datumaro/plugins/accuracy_checker_plugin/details/ac.py

View check run for this annotation

Codecov / codecov/patch

src/datumaro/plugins/accuracy_checker_plugin/details/ac.py#L117-L119

Added lines #L117 - L119 were not covered by tests
"Accuracy Checker was deprecated from OpenVINO 2024.0. Please use lower OpenVINO version."
)
4 changes: 2 additions & 2 deletions src/datumaro/plugins/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"plugin_name": "ac",
"plugin_type": "Launcher",
"extra_deps": [
"openvino.tools",
"tensorflow"
"tensorflow",
"openvino.tools.accuracy_checker"
]
},
{
Expand Down
Loading