Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / shape_infer / built-in / ie_reorg_yolo_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 <ie_layers.h>
10 #include <map>
11 #include <memory>
12 #include <string>
13 #include <vector>
14
15 namespace InferenceEngine {
16 namespace ShapeInfer {
17
18 /**
19  *@brief Implementation of Shape inference for ReorgYolo layer
20  */
21 class ReorgYoloShapeProp : public BuiltInShapeInferImpl {
22 public:
23     explicit ReorgYoloShapeProp(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         CNNLayer cnnLayer(lp);
31         cnnLayer.params = params;
32         cnnLayer.type = _type;
33         validate(&cnnLayer, inBlobs, params, blobs);
34         size_t stride = static_cast<size_t>(cnnLayer.GetParamAsInt("stride"));
35         SizeVector outShape;
36         for (size_t i = 0; i < inShapes[0].size(); i++) {
37             outShape.push_back(inShapes[0][i]);
38             if (i == 1) {
39                 outShape[outShape.size() - 1] *= stride * stride;
40             } else if (i > 1) {
41                 outShape[outShape.size() - 1] /= stride;
42             }
43         }
44         outShapes.push_back(outShape);
45     }
46 };
47
48 }  // namespace ShapeInfer
49 }  // namespace InferenceEngine