Add a section of how to link IE with CMake project (#99)
[platform/upstream/dldt.git] / inference-engine / ie_bridges / python / src / openvino / inference_engine / dnn_builder / dnn_builder_impl.hpp
1 // Copyright (c) 2018 Intel Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //        http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #pragma once
16
17 #include <ie_blob.h>
18
19 #include <iterator>
20
21 #include <string>
22 #include <iostream>
23 #include <algorithm>
24 #include <vector>
25 #include <map>
26
27 #include <sstream>
28 #include <ie_builders.hpp>
29 #include <inference_engine.hpp>
30
31 #include <ie_api_impl.hpp>
32
33
34 // namespace IE Python
35 namespace InferenceEnginePython {
36 struct LayerBuilder;
37
38 struct Port {
39     Port() = default;
40
41     explicit Port(const std::vector<size_t> &shapes);
42
43     InferenceEngine::Port actual;
44     std::vector<size_t> shape;
45 };
46
47 struct ILayer {
48     InferenceEngine::ILayer::CPtr layer_ptr;
49     std::string name;
50     size_t id;
51     std::string type;
52     std::map<std::string, std::string> parameters;
53     std::map<std::string, InferenceEngine::Blob::Ptr> constant_data;
54     std::vector<Port> in_ports;
55     std::vector<Port> out_ports;
56 };
57
58 struct PortInfo {
59     PortInfo(size_t layer_id, size_t port_id);
60
61     PortInfo() : actual(0, 0) {}
62
63     InferenceEngine::PortInfo actual;
64     size_t layer_id;
65     size_t port_id;
66 };
67
68 struct Connection {
69     Connection() : actual(InferenceEngine::PortInfo(0), InferenceEngine::PortInfo(0)) {}
70
71     Connection(PortInfo input, PortInfo output);
72
73     InferenceEngine::Connection actual;
74     PortInfo _from;
75     PortInfo to;
76 };
77
78 struct INetwork {
79     InferenceEngine::INetwork::Ptr actual;
80     std::string name;
81     size_t size;
82     std::vector<ILayer> layers;
83     std::vector<ILayer> inputs;
84     std::vector<ILayer> outputs;
85
86     std::vector<Connection> getLayerConnections(size_t layer_id);
87
88     IENetwork to_ie_network();
89 };
90
91 struct NetworkBuilder {
92     InferenceEngine::Builder::Network::Ptr network_ptr;
93
94     explicit NetworkBuilder(const std::string &name);
95
96     NetworkBuilder() = default;
97
98     NetworkBuilder from_ie_network(const InferenceEnginePython::IENetwork &icnn_net);
99
100     INetwork build();
101
102     std::vector<LayerBuilder> getLayers();
103
104     LayerBuilder getLayer(size_t layer_id);
105
106     void removeLayer(const LayerBuilder &layer);
107
108     size_t addLayer(const LayerBuilder &layer);
109
110     size_t addAndConnectLayer(const std::vector<PortInfo> &input, const LayerBuilder &layer);
111
112     const std::vector<Connection> getLayerConnections(const LayerBuilder &layer);
113
114     void disconnect(const Connection &connection);
115
116     void connect(const PortInfo &input, const PortInfo &output);
117 };
118
119 struct LayerBuilder {
120     InferenceEngine::Builder::Layer actual;
121     size_t id;
122
123     LayerBuilder(const std::string &type, const std::string &name);
124
125     LayerBuilder() : actual("", "") {}
126
127     LayerBuilder from_ilayer(const ILayer &ilayer);
128
129     const std::string &getName();
130
131     void setName(const std::string &name);
132
133     const std::string &getType();
134
135     void setType(const std::string &type);
136
137     std::vector<Port> getInputPorts();
138
139     void setInputPorts(const std::vector<Port> ports);
140
141     std::vector<Port> getOutputPorts();
142
143     void setOutputPorts(const std::vector<Port> ports);
144
145
146     std::map<std::string, std::string> getParameters();
147
148     void setParameters(std::map<std::string, std::string> params_map);
149
150     ILayer build();
151
152     std::map<std::string, InferenceEngine::Blob::Ptr> getConstantData();
153
154     InferenceEngine::Blob::Ptr allocateBlob(std::vector<size_t> dims, const std::string &precision);
155
156     void setConstantData(const std::map<std::string, InferenceEngine::Blob::Ptr> &const_data);
157
158 // TODO(  ): Fix LAyerBuilder object copying - pass by reference
159 //    void addConstantData(const std::string & name, InferenceEngine::Blob::Ptr data);
160 };
161 }  // namespace InferenceEnginePython