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.
16 from ..biases import Biases
17 from ..weights import Weights
22 '<layer name="{name}" type="{type}" precision="FP32" id="{id}">'
37 weights: Weights = None,
38 biases: Biases = None):
43 self._input_dims = input_dims
44 self._output_dims = output_dims
45 self._weights = weights
53 def type(self) -> str:
57 def name(self) -> str:
61 def params(self) -> dict:
65 def input_dims(self) -> list:
66 return self._input_dims
69 def output_dims(self) -> list:
70 return self._output_dims
73 def weights(self) -> Weights:
77 def biases(self) -> Biases:
80 def _output_dims_to_xml(self) -> str:
82 if len(self._output_dims) == 2:
89 '</output>').format(self._output_dims[0], self._output_dims[1])
90 elif len(self._output_dims) == 4:
99 '</output>').format(self._output_dims[0], self._output_dims[1], self._output_dims[2], self._output_dims[3])
101 raise NotImplementedError("{} dimensions for outputs (layer name '{}', type '{}') are not supported".format(
102 len(self._output_dims),
109 def _input_dims_to_xml(self) -> str:
111 if len(self._input_dims) == 2:
118 '</input>').format(self._input_dims[0], self._input_dims[1])
119 elif len(self._input_dims) == 4:
128 '</input>').format(self._input_dims[0], self._input_dims[1], self._input_dims[2], self._input_dims[3])
130 raise NotImplementedError("{} dimensions for inputs (layer name '{}', type '{}') are not supported".format(
131 len(self._input_dims),
139 def __str__(self) -> str:
142 for param_key in self._params.keys():
143 data_xml += '{}="{}" '.format(param_key, self._params[param_key])
148 return self.TEMPLATE.format(
152 data=(data_xml if data_xml else ''),
153 input=(self._input_dims_to_xml() if self._input_dims else ''),
154 output=(self._output_dims_to_xml() if self._output_dims else ''),
155 weights=('<weights offset="{offset}" size="{size}"/>'.format(offset=self._weights.offset, size=self._weights.size) if self._weights else ''),
156 biases=('<biases offset="{offset}" size="{size}"/>'.format(offset=self._biases.offset, size=self._biases.size) if self._biases else '')