Publishing 2019 R1 content
[platform/upstream/dldt.git] / tools / accuracy_checker / accuracy_checker / launcher / dummy_launcher.py
1 """
2 Copyright (c) 2019 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 from ..utils import get_path
18 from ..logging import print_info
19 from ..adapters import Adapter
20 from ..config import PathField, StringField
21 from .loaders import Loader
22 from .launcher import Launcher, LauncherConfig
23
24
25 class DummyLauncherConfig(LauncherConfig):
26     """
27     Specifies configuration structure for Dummy launcher.
28     """
29
30     loader = StringField(choices=Loader.providers)
31     data_path = PathField()
32     adapter = StringField(choices=Adapter.providers, optional=True)
33
34
35 class DummyLauncher(Launcher):
36     """
37     Class for using predictions from another tool.
38     """
39
40     __provider__ = 'dummy'
41
42     def __init__(self, config_entry: dict, adapter, *args, **kwargs):
43         super().__init__(config_entry, adapter, *args, **kwargs)
44
45         dummy_launcher_config = DummyLauncherConfig('Dummy_Launcher')
46         dummy_launcher_config.validate(self._config)
47
48         self.data_path = get_path(self._config['data_path'])
49
50         self._loader = Loader.provide(self._config['loader'], self.data_path)
51         if self.adapter:
52             self.adapter.output_blob = self.adapter.output_blob or self.data_path
53             self._loader.data = self.adapter(self._loader.data)
54
55         print_info("{} predictions objects loaded from {}".format(len(self._loader), self.data_path))
56
57     def predict(self, identifiers, *args, **kwargs):
58         return [self._loader[identifier] for identifier in identifiers]
59
60     def release(self):
61         pass
62
63     @property
64     def batch(self):
65         return 1
66
67     @property
68     def inputs(self):
69         return None