2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "kernels/ResizeNearestNeighbor.h"
20 #include "kernels/Utils.h"
22 #include <tensorflow/lite/kernels/internal/reference/resize_nearest_neighbor.h>
23 #include "PALResizeNearestNeighbor.h"
25 namespace luci_interpreter
30 ResizeNearestNeighbor::ResizeNearestNeighbor(const Tensor *input, const Tensor *size,
32 const ResizeNearestNeighborParams ¶ms)
33 : KernelWithParams<ResizeNearestNeighborParams>({input, size}, {output}, params)
37 void ResizeNearestNeighbor::configure()
39 LUCI_INTERPRETER_CHECK(input()->shape().num_dims() == 4);
40 LUCI_INTERPRETER_CHECK(size()->shape().num_dims() == 1);
41 LUCI_INTERPRETER_CHECK(size()->element_type() == DataType::S32);
42 LUCI_INTERPRETER_CHECK(size()->shape().dim(0) == 2);
43 Shape output_shape(4);
44 output_shape.dim(0) = input()->shape().dim(0);
45 output_shape.dim(1) = getTensorData<int32_t>(size())[0];
46 output_shape.dim(2) = getTensorData<int32_t>(size())[1];
47 output_shape.dim(3) = input()->shape().dim(3);
48 output()->resize(output_shape);
51 void ResizeNearestNeighbor::execute() const
53 tflite::ResizeNearestNeighborParams op_params{};
54 op_params.align_corners = params().align_corners;
55 op_params.half_pixel_centers = params().half_pixel_centers;
56 switch (output()->element_type())
58 case DataType::FLOAT32:
59 tflite::reference_ops::ResizeNearestNeighbor(
60 op_params, getTensorShape(input()), getTensorData<int32_t>(input()), getTensorShape(size()),
61 getTensorData<int32_t>(size()), getTensorShape(output()), getTensorData<int32_t>(output()));
64 luci_interpreter_pal::ResizeNearestNeighbor(
65 op_params, getTensorShape(input()), getTensorData<uint8_t>(input()), getTensorShape(size()),
66 getTensorData<int32_t>(size()), getTensorShape(output()), getTensorData<uint8_t>(output()));
69 throw std::runtime_error("Unsupported type.");
73 } // namespace kernels
74 } // namespace luci_interpreter