Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / shape_infer / built-in / ie_region_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 RegionYolo layer
20  */
21 class RegionYoloShapeProp : public BuiltInShapeInferImpl {
22 public:
23     explicit RegionYoloShapeProp(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 layer(lp);
31         layer.params = params;
32         int classes;
33         int coords;
34         int num;
35         bool do_softmax;
36         std::vector<int> mask;
37         classes = layer.GetParamAsInt("classes", 1);
38         coords = layer.GetParamAsInt("coords", 1);
39         num = layer.GetParamAsInt("num", 1);
40         do_softmax = static_cast<bool>(layer.GetParamAsInt("do_softmax", 1));
41         mask = layer.GetParamAsInts("mask", {});
42         unsigned int axis = layer.GetParamAsUInt("axis", 1);
43         int end_axis = layer.GetParamAsInt("end_axis", 1);
44         if (end_axis < 0) end_axis += inShapes[0].size();
45
46         SizeVector outShape;
47         if (do_softmax) {
48             size_t flat_dim = 1;
49             for (size_t i = 0; i < axis; i++) {
50                 outShape.push_back(inShapes[0][i]);
51             }
52             for (size_t i = axis; i < end_axis + 1; i++) {
53                 flat_dim *= inShapes[0][i];
54             }
55             outShape.push_back(flat_dim);
56             for (size_t i = end_axis + 1; i < inShapes[0].size(); i++) {
57                 outShape.push_back(inShapes[0][i]);
58             }
59         } else {
60             outShape = {inShapes[0][0], (classes + coords + 1) * mask.size(), inShapes[0][2], inShapes[0][3]};
61         }
62         outShapes.push_back({outShape});
63     }
64 };
65
66 }  // namespace ShapeInfer
67 }  // namespace InferenceEngine