2 Copyright (C) 2018-2019 Intel Corporation
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
19 from .biases import Biases
20 from .weights import Weights
21 from .port import Port
25 def __init__(self, data: dict):
26 self._id = int(data['id'])
27 self._name = data['name']
28 self._precision = data['precision']
29 self._type = data['type']
31 self._input_ports = Layer.__init_ports(data, 'input')
32 self._output_ports = Layer.__init_ports(data, 'output')
35 self._outputs = list()
37 blobs = data['blobs'] if 'blobs' in data else data
38 self._weights = Weights(int(blobs['weights']['offset']), int(blobs['weights']['size'])) if 'weights' in blobs else Weights(0, 0)
39 self._biases = Biases(int(blobs['biases']['offset']), int(blobs['biases']['size'])) if 'biases' in blobs else Biases(0, 0)
42 def __init_ports(data: dict, key: str) -> dict:
44 if (key in data) and ('port' in data[key]):
45 ports = data[key]['port']
46 if type(ports) is list:
47 for port_dict in ports:
48 id = int(port_dict['id'])
49 result_ports[id] = Port(id, list(map(int, port_dict['dim'])))
50 elif type(ports) is collections.OrderedDict:
52 result_ports[id] = Port(id, list(map(int, ports['dim'])))
54 raise ValueError("unexpected ports type '{}'".format(type(ports)))
57 def init(self, inputs: list, outputs: list):
59 self._outputs = outputs
66 def name(self) -> str:
70 def precision(self) -> str:
71 return self._precision
74 def type(self) -> str:
78 def input_ports(self):
79 return self._input_ports
82 def output_ports(self):
83 return self._output_ports
86 def inputs(self) -> list:
90 def outputs(self) -> list: