2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "OperationUtils.h"
17 #include "ResizeBilinearLayer.h"
18 #include "cker/operation/ResizeBilinear.h"
19 #include <cker/Types.h>
30 ResizeBilinearLayer::ResizeBilinearLayer()
31 : _input(nullptr), _output(nullptr), _size(nullptr), _output_height(0), _output_width(0),
32 _align_corners(false), _half_pixel_centers(false)
37 void ResizeBilinearLayer::configure(const IPortableTensor *input, IPortableTensor *output,
38 const IPortableTensor *size, bool align_corners,
39 bool half_pixel_centers)
41 assert(!size->is_constant());
45 _align_corners = align_corners;
46 _half_pixel_centers = half_pixel_centers;
49 void ResizeBilinearLayer::configure(const IPortableTensor *input, IPortableTensor *output,
50 int32_t output_height, int32_t output_width, bool align_corners,
51 bool half_pixel_centers)
53 assert(_size == nullptr);
54 if (output_height < 0)
56 throw std::runtime_error{"ResizeBilinear: size value must be positive value, output_height = " +
57 std::to_string(output_height)};
61 throw std::runtime_error{"ResizeBilinear: size value must be positive value, output_width = " +
62 std::to_string(output_width)};
66 _output_height = output_height;
67 _output_width = output_width;
68 _align_corners = align_corners;
69 _half_pixel_centers = half_pixel_centers;
72 void ResizeBilinearLayer::run()
74 nnfw::cker::ResizeBilinearParams params;
77 params.output_height = _output_height;
78 params.output_width = _output_width;
82 const auto size_buf = getBuffer<int32_t>(_size);
83 params.output_height = size_buf[0];
84 params.output_width = size_buf[1];
86 params.align_corners = _align_corners;
87 params.half_pixel_centers = _half_pixel_centers;
89 switch (_input->data_type())
91 case OperandType::FLOAT32:
92 nnfw::cker::ResizeBilinear(params, getShape(_input), getBuffer<float>(_input),
93 getShape(_output), getBuffer<float>(_output));
96 case OperandType::QUANT_UINT8_ASYMM:
97 nnfw::cker::ResizeBilinear(params, getShape(_input), getBuffer<uint8_t>(_input),
98 getShape(_output), getBuffer<uint8_t>(_output));
101 case OperandType::QUANT_INT8_ASYMM:
102 nnfw::cker::ResizeBilinear(params, getShape(_input), getBuffer<int8_t>(_input),
103 getShape(_output), getBuffer<int8_t>(_output));
106 case OperandType::UINT8:
107 case OperandType::BOOL8:
108 case OperandType::FLOAT16:
109 case OperandType::INT32:
110 case OperandType::INT64:
111 case OperandType::QUANT_INT8_SYMM:
112 std::runtime_error("ResizeBilinear NYI");
115 std::runtime_error("ResizeBilinear unsupported data type");
121 } // namespace backend