Publishing 2019 R1 content
[platform/upstream/dldt.git] / tools / utils / building / network_builder.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
18 # TODO: limitations:
19 # - one input
20 # - one output
21 # - dims size is 4
22 class NetworkBuilder:
23
24     EDGES_TEMPLATE2 = (
25         '<edges>'
26             '<edge from-layer="0" from-port="1" to-layer="1" to-port="0"/>'
27             '<edge from-layer="1" from-port="1" to-layer="2" to-port="0"/>'
28         '</edges>')
29
30     EDGES_TEMPLATE3 = (
31         '<edges>'
32             '<edge from-layer="0" from-port="1" to-layer="1" to-port="0"/>'
33             '<edge from-layer="1" from-port="1" to-layer="2" to-port="0"/>'
34             '<edge from-layer="2" from-port="1" to-layer="3" to-port="0"/>'
35         '</edges>')
36
37     def __init__(self, version: int = 3):
38         self._layers = list()
39
40     def __str__(self):
41         # xml = '<net name="one_layer_calibtation_network" version="2" batch="1"><layers>'
42         xml = '<net name="one_layer_calibtation_network" version="3" batch="1"><layers>'
43         for layer in self._layers:
44             xml = xml + str(layer)
45
46         xml = xml + "</layers>" + (NetworkBuilder.EDGES_TEMPLATE2 if len(self._layers) == 3 else NetworkBuilder.EDGES_TEMPLATE3) + "</net>"
47         return xml
48
49     def sequential(self, layers):
50         self._layers = layers
51         return self