Skip to content

Commit

Permalink
Prevent AcLauncher for OpenVINO 2024.0 (#1450)
Browse files Browse the repository at this point in the history
<!-- Contributing guide:
https://github.com/openvinotoolkit/datumaro/blob/develop/CONTRIBUTING.md
-->

### Summary

<!--
Resolves #111 and #222.
Depends on #1000 (for series of dependent commits).

This PR introduces this capability to make the project better in this
and that.

- Added this feature
- Removed that feature
- Fixed the problem #1234
-->

### How to test
<!-- Describe the testing procedure for reviewers, if changes are
not fully covered by unit tests or manual testing can be complicated.
-->

### Checklist
<!-- Put an 'x' in all the boxes that apply -->
- [ ] I have added unit tests to cover my changes.​
- [ ] I have added integration tests to cover my changes.​
- [ ] I have added the description of my changes into
[CHANGELOG](https://github.com/openvinotoolkit/datumaro/blob/develop/CHANGELOG.md).​
- [ ] I have updated the
[documentation](https://github.com/openvinotoolkit/datumaro/tree/develop/docs)
accordingly

### License

- [ ] I submit _my code changes_ under the same [MIT
License](https://github.com/openvinotoolkit/datumaro/blob/develop/LICENSE)
that covers the project.
  Feel free to contact the maintainers if that's a concern.
- [ ] I have updated the license header for each file (see an example
below).

```python
# Copyright (C) 2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
```
  • Loading branch information
wonjuleee committed Apr 17, 2024
1 parent 4cef56b commit 6988d69
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 91 deletions.
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

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
)

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))
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(),
)

postproc_config = config.get("postprocessing")
postproc = None
if postproc_config:
postproc = PostprocessingExecutor(
postproc_config,
dataset_meta=dataset.metadata,
)

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

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

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

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))
inputs = [DataRepresentation(inp, identifier=id) for id, inp in zip(ids, inputs)]
_, batch_meta = extract_image_representations(inputs)

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

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)

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

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

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

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

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

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):
if self._adapter is None or self._adapter.label_map is None:
return None

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()
for _, label in label_map:
label_cat.add(label)

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

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

return {AnnotationType.label: label_cat}
class GenericAcLauncher:
def __init__(self):
raise ImportError(
"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

0 comments on commit 6988d69

Please sign in to comment.