ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ResizeNearestNeighbor.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17
19
20#include "kernels/Utils.h"
21
22#include <tensorflow/lite/kernels/internal/reference/resize_nearest_neighbor.h>
23#include "PALResizeNearestNeighbor.h"
24
25namespace luci_interpreter
26{
27namespace kernels
28{
29
36
38{
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);
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);
49}
50
52{
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())
57 {
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()));
62 break;
63 case DataType::U8:
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()));
67 break;
68 default:
69 throw std::runtime_error("luci-intp ResizeNearestNeighbor Unsupported type.");
70 }
71}
72
73} // namespace kernels
74} // namespace luci_interpreter
const ResizeNearestNeighborParams & params() const
Definition Kernel.h:67
int32_t dim(int i) const
Definition Tensor.h:41
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
const Shape & shape() const
Definition Tensor.h:107
ResizeNearestNeighbor(const Tensor *input, const Tensor *shape, Tensor *output, const ResizeNearestNeighborParams &params)
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
const luci_interpreter::RuntimeShape output_shape
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194
int32_t size[5]
Definition Slice.cpp:35