1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
7 #include "ie_built_in_impl.hpp"
13 namespace InferenceEngine {
14 namespace ShapeInfer {
17 *@brief Implementation of Shape inference for Crop layer
19 class CropShapeProp : public BuiltInShapeInferImpl {
21 explicit CropShapeProp(const std::string& type) : BuiltInShapeInferImpl(type) {}
23 void inferShapesImpl(const std::vector<Blob::CPtr>& inBlobs,
24 const std::map<std::string, std::string>& params,
25 const std::map<std::string, Blob::Ptr>& blobs,
26 std::vector<SizeVector>& outShapes) override {
28 CropLayer cropLayer(lp);
29 cropLayer.params = params;
30 cropLayer.type = _type;
31 validate(&cropLayer, inBlobs, params, blobs);
33 outShapes.push_back(inShapes[0]);
34 if (inShapes.size() == 2) {
35 SizeVector cropShapes = inShapes[1];
36 for (int axis : cropLayer.axis) {
37 outShapes[0][axis] = cropShapes[axis];
40 std::vector<int> crop_end;
41 bool isDim = cropLayer.params.find("dim") != cropLayer.params.end();
42 if (!isDim) crop_end = cropLayer.GetParamAsInts("crop_end");
43 for (size_t i = 0; i < cropLayer.axis.size(); i++) {
44 outShapes[0][cropLayer.axis[i]] = isDim
46 : inShapes[0][cropLayer.axis[i]] - cropLayer.offset[i] - crop_end[i];
52 } // namespace ShapeInfer
53 } // namespace InferenceEngine