prior_box_op.cc 2.7 KB
Newer Older
Y
Yan Chunwei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
// 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/operators/prior_box_op.h"
#include "lite/core/op_registry.h"

namespace paddle {
namespace lite {
namespace operators {

bool PriorBoxOpLite::CheckShape() const {
  CHECK_OR_FALSE(param_.input);
  CHECK_OR_FALSE(param_.image);
  CHECK_OR_FALSE(param_.boxes);
  CHECK_OR_FALSE(param_.variances);
  return true;
}

bool PriorBoxOpLite::InferShape() const { return true; }

bool PriorBoxOpLite::AttachImpl(const cpp::OpDesc& opdesc, lite::Scope* scope) {
  auto input = opdesc.Input("Input").front();
  auto image = opdesc.Input("Image").front();
  auto boxes = opdesc.Output("Boxes").front();
  auto variances = opdesc.Output("Variances").front();

  param_.input = scope->FindVar(input)->GetMutable<lite::Tensor>();
  param_.image = scope->FindVar(image)->GetMutable<lite::Tensor>();
  param_.boxes = scope->FindVar(boxes)->GetMutable<lite::Tensor>();
  param_.variances = scope->FindVar(variances)->GetMutable<lite::Tensor>();

  param_.clip = opdesc.GetAttr<bool>("clip");
  param_.min_sizes = opdesc.GetAttr<std::vector<float>>("min_sizes");
  param_.max_sizes = opdesc.GetAttr<std::vector<float>>("max_sizes");
  param_.aspect_ratios = opdesc.GetAttr<std::vector<float>>("aspect_ratios");
  param_.variances_ = opdesc.GetAttr<std::vector<float>>("variances");
T
TianXiaogang 已提交
48 49 50
  if (opdesc.HasAttr("flip")) {
    param_.flip = opdesc.GetAttr<bool>("flip");
  }
Y
Yan Chunwei 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
  if (opdesc.HasAttr("img_w")) {
    param_.img_w = opdesc.GetAttr<int>("img_w");
  }
  if (opdesc.HasAttr("img_h")) {
    param_.img_h = opdesc.GetAttr<int>("img_h");
  }
  if (opdesc.HasAttr("step_w")) {
    param_.step_w = opdesc.GetAttr<float>("step_w");
  }
  if (opdesc.HasAttr("step_h")) {
    param_.step_h = opdesc.GetAttr<float>("step_h");
  }
  param_.offset = opdesc.GetAttr<float>("offset");
  if (opdesc.HasAttr("prior_num")) {
    param_.prior_num = opdesc.GetAttr<int>("prior_num");
  }
  if (opdesc.HasAttr("order")) {
    param_.order = opdesc.GetAttr<std::vector<std::string>>("order");
  }
  return true;
}

}  // namespace operators
}  // namespace lite
}  // namespace paddle

REGISTER_LITE_OP(prior_box, paddle::lite::operators::PriorBoxOpLite);