Publishing 2019 R1.1 content and Myriad plugin sources (#162)
[platform/upstream/dldt.git] / inference-engine / src / vpu / graph_transformer / src / stages / prelu.cpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include <vpu/frontend/frontend.hpp>
6
7 #include <vector>
8 #include <memory>
9
10 #include <vpu/sw/post_op_stage.hpp>
11
12 namespace vpu {
13
14 namespace {
15
16 class PReluStage final : public PostOpStage {
17 private:
18     StagePtr cloneImpl() const override {
19         return std::make_shared<PReluStage>(*this);
20     }
21
22     void serializeParamsImpl(BlobSerializer&) const override {
23     }
24 };
25
26 }  // namespace
27
28 void FrontEnd::parsePReLU(
29         const Model::Ptr& model,
30         const ie::CNNLayerPtr& layer,
31         const DataVector& inputs,
32         const DataVector& outputs) {
33     IE_ASSERT(inputs.size() == 1);
34     IE_ASSERT(outputs.size() == 1);
35
36     auto weightsIt = layer->blobs.find("weights");
37     if (weightsIt == layer->blobs.end()) {
38         THROW_IE_EXCEPTION << "[VPU] PReLU doesn't have weights";
39     }
40
41     auto weightsBlob = weightsIt->second;
42     IE_ASSERT(weightsBlob != nullptr);
43
44     auto channelShared = layer->GetParamAsInt("channel_shared", 0);
45
46     auto output = outputs[0];
47
48     auto weights = model->addConstData(
49         layer->name + "@weights",
50         DataDesc({output->desc().dim(Dim::C)}),
51         ieBlobContent(
52             weightsBlob,
53             channelShared ? output->desc().dim(Dim::C) : 1));
54
55     model->addNewStage<PReluStage>(
56         layer->name,
57         StageType::PRelu,
58         layer,
59         {inputs[0], weights},
60         outputs);
61 }
62
63 }  // namespace vpu