Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / builders / ie_reshape_layer.cpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include <builders/ie_reshape_layer.hpp>
6 #include <ie_cnn_layer_builder.h>
7
8 #include <vector>
9 #include <string>
10
11 using namespace InferenceEngine;
12
13 Builder::ReshapeLayer::ReshapeLayer(const std::string& name): LayerDecorator("Reshape", name) {
14     getLayer()->getOutputPorts().resize(1);
15     getLayer()->getInputPorts().resize(1);
16 }
17
18 Builder::ReshapeLayer::ReshapeLayer(const Layer::Ptr& layer): LayerDecorator(layer) {
19     checkType("Reshape");
20 }
21
22 Builder::ReshapeLayer::ReshapeLayer(const Layer::CPtr& layer): LayerDecorator(layer) {
23     checkType("Reshape");
24 }
25
26 Builder::ReshapeLayer& Builder::ReshapeLayer::setName(const std::string& name) {
27     getLayer()->setName(name);
28     return *this;
29 }
30
31 const Port& Builder::ReshapeLayer::getInputPort() const {
32     return getLayer()->getInputPorts()[0];
33 }
34
35 Builder::ReshapeLayer& Builder::ReshapeLayer::setInputPort(const Port &port) {
36     getLayer()->getInputPorts()[0] = port;
37     return *this;
38 }
39
40 const Port& Builder::ReshapeLayer::getOutputPort() const {
41     return getLayer()->getOutputPorts()[0];
42 }
43
44 Builder::ReshapeLayer& Builder::ReshapeLayer::setOutputPort(const Port &port) {
45     getLayer()->getOutputPorts()[0] = port;
46     return *this;
47 }
48
49 const std::vector<int> Builder::ReshapeLayer::getDims() const {
50     return getLayer()->getParameters().at("dim");
51 }
52
53 Builder::ReshapeLayer& Builder::ReshapeLayer::setDims(const std::vector<int>& dims) {
54     getLayer()->getParameters()["dim"] = dims;
55     return *this;
56 }
57
58 REG_CONVERTER_FOR(Flatten, [](const CNNLayerPtr& cnnLayer, Builder::Layer& layer) {
59     layer.getParameters()["axis"] = static_cast<size_t>(cnnLayer->GetParamAsUInt("axis", 0));
60     layer.getParameters()["dim"] = cnnLayer->GetParamAsInts("dim", {});
61 });
62 REG_CONVERTER_FOR(Reshape, [](const CNNLayerPtr& cnnLayer, Builder::Layer& layer) {
63     layer.getParameters()["axis"] = static_cast<size_t>(cnnLayer->GetParamAsUInt("axis", 0));
64     layer.getParameters()["dim"] = cnnLayer->GetParamAsInts("dim", {});
65 });