Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / shape_infer / built-in / ie_rnn_cell_shape_infer.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <description_buffer.hpp>
8 #include "ie_built_in_impl.hpp"
9 #include <map>
10 #include <memory>
11 #include <string>
12 #include <vector>
13
14 namespace InferenceEngine {
15 namespace ShapeInfer {
16
17 /**
18  *@brief Implementation of Shape inference for DetectionOutput layer
19  */
20 template<class CELL, int S>
21 class RNNBaseCellShapeProp : public BuiltInShapeInferImpl {
22 public:
23     explicit RNNBaseCellShapeProp(const std::string& type) : BuiltInShapeInferImpl(type) {}
24
25     void inferShapesImpl(const std::vector<Blob::CPtr>& inBlobs,
26                          const std::map<std::string, std::string>& params,
27                          const std::map<std::string, Blob::Ptr>& blobs,
28                          std::vector<SizeVector>& outShapes) override {
29         LayerParams lp{};
30         CELL cnnLayer(lp);
31         cnnLayer.params = params;
32         cnnLayer.type = _type;
33         validate(&cnnLayer, inBlobs, params, blobs);
34
35         auto state_dims = inShapes[1];
36         for (int i = 0; i < S; i++)
37             outShapes.push_back(state_dims);
38     }
39 };
40
41 using RNNCellShapeProp  = RNNBaseCellShapeProp<RNNCell,  1>;
42 using GRUCellShapeProp  = RNNBaseCellShapeProp<GRUCell,  1>;
43 using LSTMCellShapeProp = RNNBaseCellShapeProp<LSTMCell, 2>;
44
45 }  // namespace ShapeInfer
46 }  // namespace InferenceEngine