box_coder_op.cpp 2.1 KB
Newer Older
E
eclipsess 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/* Copyright (c) 2018 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. */
E
eclipsess 已提交
14

L
liuruilong 已提交
15 16
#ifdef BOXCODER_OP

E
eclipsess 已提交
17 18 19 20 21 22 23
#include "operators/box_coder_op.h"
#include <vector>
namespace paddle_mobile {
namespace operators {

template <typename Dtype, typename T>
void BoxCoderOp<Dtype, T>::InferShape() const {
L
liuruilong 已提交
24 25 26
  auto input_priorbox_dims = this->param_.InputPriorBox()->dims();
  auto input_priorboxvar_dims = this->param_.InputPriorBoxVar()->dims();
  auto input_targetbox_dims = this->param_.InputTargetBox()->dims();
E
eclipsess 已提交
27

L
liuruilong 已提交
28
  auto code_type = this->param_.CodeType();
E
eclipsess 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

  if (code_type == "encode_center_size") {
    if (input_targetbox_dims.size() != 2) {
      LOG(kLOG_ERROR) << " The rank of Input of TargetBox must be 2";
    }
    if (input_targetbox_dims[1] != 4) {
      LOG(kLOG_ERROR) << " The shape of TargetBox is [M, 4]";
    }
  }
  if (code_type == "decode_center_size") {
    if (input_targetbox_dims.size() != 3) {
      LOG(kLOG_ERROR) << "The rank of Input of TargetBox must be 3";
    }
    if (input_targetbox_dims[1] != input_priorbox_dims[0] ||
        input_targetbox_dims[2] != input_priorbox_dims[1]) {
      LOG(kLOG_ERROR) << " dimension not match";
    }
  }
L
liuruilong 已提交
47
  this->param_.OutputBox()->Resize(framework::make_ddim(
E
eclipsess 已提交
48 49 50 51 52
      {input_targetbox_dims[0], input_priorbox_dims[0], 4}));
}
template class BoxCoderOp<CPU, float>;
}  // namespace operators
}  // namespace paddle_mobile
E
eclipsess 已提交
53 54

namespace ops = paddle_mobile::operators;
L
for  
liuruilong 已提交
55 56 57 58 59 60 61 62
#ifdef PADDLE_MOBILE_CPU
USE_OP_CPU(box_coder);
REGISTER_OPERATOR_CPU(box_coder, ops::BoxCoderOp);
#endif
#ifdef PADDLE_MOBILE_MALI_GPU
#endif
#ifdef PADDLE_MOBILE_FPGA
#endif
L
liuruilong 已提交
63 64

#endif