interpolate_compute.cc 4.0 KB
Newer Older
Y
Yan Chunwei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "lite/kernels/arm/interpolate_compute.h"
#include <string>
#include <vector>
18
#include "lite/backends/arm/math/funcs.h"
Y
Yan Chunwei 已提交
19 20 21 22 23 24 25 26 27 28 29 30
#include "lite/core/op_registry.h"
#include "lite/core/tensor.h"

namespace paddle {
namespace lite {
namespace kernels {
namespace arm {

void BilinearInterpCompute::Run() {
  auto& param = Param<operators::InterpolateParam>();
  lite::Tensor* X = param.X;
  lite::Tensor* OutSize = param.OutSize;
L
liu zhengxi 已提交
31 32
  auto SizeTensor = param.SizeTensor;
  auto Scale = param.Scale;
Y
Yan Chunwei 已提交
33 34 35 36 37
  lite::Tensor* Out = param.Out;
  float scale = param.scale;
  int out_w = param.out_w;
  int out_h = param.out_h;
  bool align_corners = param.align_corners;
38
  bool align_mode = param.align_mode;
Y
Yan Chunwei 已提交
39 40 41
  std::string interp_method = "Bilinear";
  lite::arm::math::interpolate(X,
                               OutSize,
L
liu zhengxi 已提交
42 43
                               SizeTensor,
                               Scale,
Y
Yan Chunwei 已提交
44 45 46 47 48
                               Out,
                               out_h,
                               out_w,
                               scale,
                               align_corners,
49
                               align_mode,
Y
Yan Chunwei 已提交
50 51 52 53 54 55 56
                               interp_method);
}

void NearestInterpCompute::Run() {
  auto& param = Param<operators::InterpolateParam>();
  lite::Tensor* X = param.X;
  lite::Tensor* OutSize = param.OutSize;
L
liu zhengxi 已提交
57 58
  auto SizeTensor = param.SizeTensor;
  auto Scale = param.Scale;
Y
Yan Chunwei 已提交
59 60 61 62 63
  lite::Tensor* Out = param.Out;
  float scale = param.scale;
  int out_w = param.out_w;
  int out_h = param.out_h;
  bool align_corners = param.align_corners;
64
  bool align_mode = param.align_mode;
Y
Yan Chunwei 已提交
65 66 67
  std::string interp_method = "Nearest";
  lite::arm::math::interpolate(X,
                               OutSize,
L
liu zhengxi 已提交
68 69
                               SizeTensor,
                               Scale,
Y
Yan Chunwei 已提交
70 71 72 73 74
                               Out,
                               out_h,
                               out_w,
                               scale,
                               align_corners,
75
                               align_mode,
Y
Yan Chunwei 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
                               interp_method);
}

} /* namespace arm */
} /* namespace kernels */
} /* namespace lite */
} /* namespace paddle */

REGISTER_LITE_KERNEL(bilinear_interp,
                     kARM,
                     kFloat,
                     kNCHW,
                     paddle::lite::kernels::arm::BilinearInterpCompute,
                     def)
    .BindInput("X", {LiteType::GetTensorTy(TARGET(kARM))})
J
juncaipeng 已提交
91 92 93 94
    .BindInput("OutSize",
               {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt32))})
    .BindInput("SizeTensor",
               {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt32))})
L
liu zhengxi 已提交
95
    .BindInput("Scale", {LiteType::GetTensorTy(TARGET(kARM))})
Y
Yan Chunwei 已提交
96 97 98 99 100 101 102 103 104 105
    .BindOutput("Out", {LiteType::GetTensorTy(TARGET(kARM))})
    .Finalize();

REGISTER_LITE_KERNEL(nearest_interp,
                     kARM,
                     kFloat,
                     kNCHW,
                     paddle::lite::kernels::arm::NearestInterpCompute,
                     def)
    .BindInput("X", {LiteType::GetTensorTy(TARGET(kARM))})
J
juncaipeng 已提交
106 107 108 109
    .BindInput("OutSize",
               {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt32))})
    .BindInput("SizeTensor",
               {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt32))})
L
liu zhengxi 已提交
110
    .BindInput("Scale", {LiteType::GetTensorTy(TARGET(kARM))})
Y
Yan Chunwei 已提交
111 112
    .BindOutput("Out", {LiteType::GetTensorTy(TARGET(kARM))})
    .Finalize();