Publishing 2019 R1 content
[platform/upstream/dldt.git] / tools / calibration / single_layer_network.py
1 """
2 Copyright (C) 2018-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 openvino.inference_engine import IENetwork, ExecutableNetwork, InferRequest
18
19
20 # TODO: network and request are not used
21 # TODO: refactor: create network before inference only
22 class SingleLayerNetwork:
23     '''
24     One layer network description
25     '''
26
27     def __init__(
28         self,
29         network: IENetwork,
30         exec_network: ExecutableNetwork,
31         input_layer_name: str,
32         layer_name: str,
33         output_layer_name: str,
34         reference_output_layer_name: str):
35
36         self._network = network
37         self._exec_network = exec_network
38         self._input_layer_name = input_layer_name
39         self._layer_name = layer_name
40         self._output_layer_name = output_layer_name
41         self._reference_output_layer_name = reference_output_layer_name
42         self._int8_accuracy_list = list()
43
44     def __enter__(self):
45         return self
46
47     def __exit__(self, type, value, tb):
48         self.release()
49
50     def release(self):
51         if self._network:
52             del self._network
53             self._network = None
54
55         if self._exec_network:
56             del self._exec_network
57             self._exec_network = None
58
59     @property
60     def network(self) -> IENetwork:
61         return self._network
62
63     @property
64     def exec_network(self) -> ExecutableNetwork:
65         return self._exec_network
66
67     @property
68     def input_layer_name(self) -> str:
69         return self._input_layer_name
70
71     @property
72     def layer_name(self) -> str:
73         return self._layer_name
74
75     @property
76     def output_layer_name(self) -> str:
77         return self._output_layer_name
78
79     @property
80     def reference_output_layer_name(self) -> str:
81         return self._reference_output_layer_name
82
83     @property
84     def int8_accuracy_list(self) -> list:
85         return self._int8_accuracy_list