Publishing R3
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / shape_infer / built-in / ie_crop_shape_infer.hpp
1 // Copyright (C) 2018 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5
6 #pragma once
7
8 #include "ie_built_in_holder.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 Crop layer
19  */
20 class CropShapeProp : public BuiltInShapeInferImpl {
21 public:
22     explicit CropShapeProp(const std::string& type) : BuiltInShapeInferImpl(type) {}
23
24     void inferShapesImpl(const std::vector<SizeVector>& inShapes,
25                          const std::map<std::string, std::string>& params,
26                          const std::map<std::string, Blob::Ptr>& blobs,
27                          std::vector<SizeVector>& outShapes) override {
28         LayerParams lp{};
29         CropLayer cropLayer(lp);
30         cropLayer.params = params;
31         cropLayer.type = _type;
32         validate(&cropLayer, inShapes, params, blobs);
33
34         if (inShapes.size() != 2)
35             THROW_IE_EXCEPTION << "second input is required to infer shapes, re-generate IR with latest MO";
36         SizeVector cropShapes = inShapes[1];
37         outShapes.push_back(inShapes[0]);
38         for (size_t i = 0; i < cropLayer.axis.size(); i++) {
39             if (cropLayer.axis[i] >= outShapes[0].size())
40                 THROW_IE_EXCEPTION << "Axis can't be more then number of output shapes";
41             outShapes[0][cropLayer.axis[i]] = cropShapes[cropLayer.axis[i]];
42         }
43     }
44 };
45
46 }  // namespace ShapeInfer
47 }  // namespace InferenceEngine