1 /**
2 * Copyright 2021-2023 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "nnacl/infer/crop_and_resize_infer.h"
18 #include "nnacl/infer/infer_register.h"
19 #include "nnacl/tensor_c_utils.h"
20
CropAndResizeInferShape(const TensorC * const * inputs,size_t inputs_size,TensorC ** outputs,size_t outputs_size,OpParameter * parameter)21 int CropAndResizeInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
22 OpParameter *parameter) {
23 int check_ret = CheckAugmentNullInputSize(inputs, inputs_size, outputs, outputs_size, parameter, 4);
24 if (check_ret != NNACL_OK) {
25 return check_ret;
26 }
27 if (outputs_size < 1) {
28 return NNACL_INPUT_TENSOR_ERROR;
29 }
30
31 const TensorC *input = inputs[0];
32 TensorC *output = outputs[0];
33 SetDataTypeFormat(output, input);
34 if (!InferFlag(inputs, inputs_size)) {
35 return NNACL_INFER_INVALID;
36 }
37 if (input->shape_size_ != 0 && input->shape_size_ != 4) {
38 return NNACL_ERR;
39 }
40 int output_shape[MAX_SHAPE_SIZE] = {0};
41 size_t output_shape_size = 0;
42 if (GetBatch(input) == 0) {
43 ShapePush(output_shape, &output_shape_size, 0);
44 } else if (inputs[1]->data_ != NULL) {
45 const TensorC *boxes_tensor = inputs[1];
46 if (boxes_tensor->shape_size_ < 1) {
47 return NNACL_INPUT_TENSOR_ERROR;
48 }
49 ShapePush(output_shape, &output_shape_size, boxes_tensor->shape_[0]);
50 } else {
51 return NNACL_INFER_INVALID;
52 }
53
54 const TensorC *shape_tensor = inputs[3];
55 int32_t *data = (int32_t *)(shape_tensor->data_);
56 if (data == NULL) {
57 return NNACL_INFER_INVALID;
58 }
59 if (GetElementNum(shape_tensor) < 2) {
60 return NNACL_INPUT_TENSOR_ERROR;
61 }
62 ShapePush(output_shape, &output_shape_size, data[0]);
63 ShapePush(output_shape, &output_shape_size, data[1]);
64 ShapePush(output_shape, &output_shape_size, GetChannel(input));
65 SetShapeArray(output, output_shape, output_shape_size);
66 return NNACL_OK;
67 }
68
69 REG_INFER(CropAndResize, PrimType_CropAndResize, CropAndResizeInferShape)
70