interpolate_compute.cc 3.7 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 38 39 40
  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;
  std::string interp_method = "Bilinear";
  lite::arm::math::interpolate(X,
                               OutSize,
L
liu zhengxi 已提交
41 42
                               SizeTensor,
                               Scale,
Y
Yan Chunwei 已提交
43 44 45 46 47 48 49 50 51 52 53 54
                               Out,
                               out_h,
                               out_w,
                               scale,
                               align_corners,
                               interp_method);
}

void NearestInterpCompute::Run() {
  auto& param = Param<operators::InterpolateParam>();
  lite::Tensor* X = param.X;
  lite::Tensor* OutSize = param.OutSize;
L
liu zhengxi 已提交
55 56
  auto SizeTensor = param.SizeTensor;
  auto Scale = param.Scale;
Y
Yan Chunwei 已提交
57 58 59 60 61 62 63 64
  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;
  std::string interp_method = "Nearest";
  lite::arm::math::interpolate(X,
                               OutSize,
L
liu zhengxi 已提交
65 66
                               SizeTensor,
                               Scale,
Y
Yan Chunwei 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
                               Out,
                               out_h,
                               out_w,
                               scale,
                               align_corners,
                               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))})
    .BindInput("OutSize", {LiteType::GetTensorTy(TARGET(kARM))})
L
liu zhengxi 已提交
88 89
    .BindInput("SizeTensor", {LiteType::GetTensorTy(TARGET(kARM))})
    .BindInput("Scale", {LiteType::GetTensorTy(TARGET(kARM))})
Y
Yan Chunwei 已提交
90 91 92 93 94 95 96 97 98 99 100
    .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))})
    .BindInput("OutSize", {LiteType::GetTensorTy(TARGET(kARM))})
L
liu zhengxi 已提交
101 102
    .BindInput("SizeTensor", {LiteType::GetTensorTy(TARGET(kARM))})
    .BindInput("Scale", {LiteType::GetTensorTy(TARGET(kARM))})
Y
Yan Chunwei 已提交
103 104
    .BindOutput("Out", {LiteType::GetTensorTy(TARGET(kARM))})
    .Finalize();