single_layer_network.py 2.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
"""
Copyright (C) 2018-2019 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from openvino.inference_engine import IENetwork, ExecutableNetwork, InferRequest


# TODO: network and request are not used
# TODO: refactor: create network before inference only
class SingleLayerNetwork:
    '''
    One layer network description
    '''

    def __init__(
        self,
        network: IENetwork,
        exec_network: ExecutableNetwork,
        input_layer_name: str,
        layer_name: str,
        output_layer_name: str,
        reference_output_layer_name: str):

        self._network = network
        self._exec_network = exec_network
        self._input_layer_name = input_layer_name
        self._layer_name = layer_name
        self._output_layer_name = output_layer_name
        self._reference_output_layer_name = reference_output_layer_name
        self._int8_accuracy_list = list()

    def __enter__(self):
        return self

    def __exit__(self, type, value, tb):
        self.release()

    def release(self):
        if self._network:
            del self._network
            self._network = None

        if self._exec_network:
            del self._exec_network
            self._exec_network = None

    @property
    def network(self) -> IENetwork:
        return self._network

    @property
    def exec_network(self) -> ExecutableNetwork:
        return self._exec_network

    @property
    def input_layer_name(self) -> str:
        return self._input_layer_name

    @property
    def layer_name(self) -> str:
        return self._layer_name

    @property
    def output_layer_name(self) -> str:
        return self._output_layer_name

    @property
    def reference_output_layer_name(self) -> str:
        return self._reference_output_layer_name

    @property
    def int8_accuracy_list(self) -> list:
        return self._int8_accuracy_list