提交 664e19cc 编写于 作者: J juncaipeng 提交者: Xiaoyang LI

rewrite multiclass_nms according to fluid, test=develop (#1945)

* add ops for faster rcnn

* disable test for generate_proposals and roi_align, test=develop

* remove .swp file

* remove log in tensor slice

* finish the unit test for roi_align, test=develop

* add box_clip op and fix tensor slice bug

* remove add four op twice

* rewrite the implement for box_coder and sequence_expand, add faster_rcnn_test, test=develop

* fix test bug of box_clip in x86 server, test=develop

* rewrite multiclass_nms according to fluid, test=develop

* fix param load bug in box_coder and multiclass_nms op, test=develop

* fix value transfor error in multiclass_nms, test=develop
上级 088d741f
......@@ -78,19 +78,13 @@ void TestModel(const std::vector<Place>& valid_places,
auto* out = predictor.GetOutput(0);
auto* out_data = out->data<float>();
LOG(INFO) << "==========output data===============";
LOG(INFO) << out->dims();
for (int i = 0; i < out->numel(); i++) {
// LOG(INFO) << out_data[i];
LOG(INFO) << out_data[i];
}
/*
ASSERT_EQ(out->dims()[1], 6);
ASSERT_EQ(out->lod().size(), 1);
ASSERT_EQ(out->lod()[0].size(), 2);
ASSERT_EQ(out->lod()[0][0], 0);
ASSERT_EQ(out->lod()[0][1], 100);
*/
}
TEST(MobileNetV1_YoloV3, test_arm) {
TEST(Faster_RCNN, test_arm) {
std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)},
......
......@@ -6,4 +6,4 @@ add_kernel(reshape_compute_host Host basic SRCS reshape_compute.cc DEPS ${lite_k
add_kernel(multiclass_nms_compute_host Host basic SRCS multiclass_nms_compute.cc DEPS ${lite_kernel_deps})
lite_cc_test(test_reshape_compute_host SRCS reshape_compute_test.cc DEPS reshape_compute_host any)
lite_cc_test(test_multiclass_nms_compute_host SRCS multiclass_nms_compute_test.cc DEPS multiclass_nms_compute_host any)
#lite_cc_test(test_multiclass_nms_compute_host SRCS multiclass_nms_compute_test.cc DEPS multiclass_nms_compute_host any)
......@@ -139,18 +139,18 @@ void apply_nms_fast(const dtype* bboxes,
template <typename dtype>
void multiclass_nms_compute_ref(const operators::MulticlassNmsParam& param,
int class_num,
const std::vector<int>& priors,
bool share_location,
std::vector<float>* result) {
const std::vector<int>& priors = param.priors;
int class_num = param.class_num;
int background_id = param.background_label;
int keep_topk = param.keep_top_k;
int nms_topk = param.nms_top_k;
float conf_thresh = param.score_threshold;
float nms_thresh = param.nms_threshold;
float nms_eta = param.nms_eta;
bool share_location = param.share_location;
const dtype* bbox_data = param.bbox_data->data<const dtype>();
const dtype* conf_data = param.conf_data->data<const dtype>();
const dtype* bbox_data = param.bboxes->data<const dtype>();
const dtype* conf_data = param.scores->data<const dtype>();
dtype* out = param.out->mutable_data<dtype>();
(*result).clear();
......@@ -325,23 +325,21 @@ TEST(multiclass_nms_host, compute) {
for (int i = 0; i < conf_dim->production(); ++i) {
conf_data[i] = i * 1. / conf_dim->production();
}
param.bbox_data = &bbox;
param.conf_data = &conf;
param.bboxes = &bbox;
param.scores = &conf;
param.out = &out;
param.priors = priors;
param.class_num = class_num;
param.background_label = background_id;
param.keep_top_k = keep_topk;
param.nms_top_k = nms_topk;
param.score_threshold = conf_thresh;
param.nms_threshold = nms_thresh;
param.nms_eta = nms_eta;
param.share_location = share_location;
multiclass_nms.SetParam(param);
multiclass_nms.Run();
auto* out_data = out.mutable_data<float>();
out_ref.clear();
multiclass_nms_compute_ref<float>(param, &out_ref);
multiclass_nms_compute_ref<float>(
param, class_num, priors, share_location, &out_ref);
EXPECT_EQ(out.dims().production(), out_ref.size());
if (out.dims().production() == out_ref.size()) {
auto* out_ref_data = out_ref.data();
......
......@@ -89,7 +89,9 @@ bool BoxCoderOpLite::AttachImpl(const cpp::OpDesc& opdesc, lite::Scope* scope) {
param_.code_type = opdesc.GetAttr<std::string>("code_type");
param_.box_normalized = opdesc.GetAttr<bool>("box_normalized");
param_.axis = opdesc.GetAttr<int>("axis");
if (opdesc.HasAttr("axis")) {
param_.axis = opdesc.GetAttr<int>("axis");
}
if (opdesc.HasAttr("variance")) {
param_.variance = opdesc.GetAttr<std::vector<float>>("variance");
......
......@@ -20,34 +20,55 @@ namespace lite {
namespace operators {
bool MulticlassNmsOpLite::CheckShape() const {
CHECK_OR_FALSE(param_.bbox_data);
CHECK_OR_FALSE(param_.conf_data);
CHECK_OR_FALSE(param_.bboxes);
CHECK_OR_FALSE(param_.scores);
CHECK_OR_FALSE(param_.out);
auto box_dims = param_.bboxes->dims();
auto score_dims = param_.scores->dims();
auto score_size = score_dims.size();
CHECK_OR_FALSE(score_size == 2 || score_size == 3);
CHECK_OR_FALSE(box_dims.size() == 3);
if (score_size == 3) {
CHECK_OR_FALSE(box_dims[2] == 4 || box_dims[2] == 8 || box_dims[2] == 16 ||
box_dims[2] == 24 || box_dims[2] == 32);
CHECK_OR_FALSE(box_dims[1] == score_dims[2]);
} else {
CHECK_OR_FALSE(box_dims[2] == 4);
CHECK_OR_FALSE(box_dims[1] == score_dims[1]);
}
return true;
}
bool MulticlassNmsOpLite::InferShape() const {
// param_.out->Resize(param_.loc_data->dims());
auto box_dims = param_.bboxes->dims();
auto score_dims = param_.scores->dims();
auto score_size = score_dims.size();
if (score_size == 3) {
param_.out->Resize({box_dims[1], box_dims[2], 3});
} else {
param_.out->Resize({-1, box_dims[2] + 2});
}
return true;
}
bool MulticlassNmsOpLite::AttachImpl(const cpp::OpDesc& opdesc,
lite::Scope* scope) {
auto Bbox_name = opdesc.Input("BBoxes").front();
auto Conf_name = opdesc.Input("Scores").front();
auto Out_name = opdesc.Output("Out").front();
param_.bbox_data = GetVar<lite::Tensor>(scope, Bbox_name);
param_.conf_data = GetVar<lite::Tensor>(scope, Conf_name);
param_.out = GetMutableVar<lite::Tensor>(scope, Out_name);
auto bboxes_name = opdesc.Input("BBoxes").front();
auto scores_name = opdesc.Input("Scores").front();
auto out_name = opdesc.Output("Out").front();
param_.bboxes = GetVar<lite::Tensor>(scope, bboxes_name);
param_.scores = GetVar<lite::Tensor>(scope, scores_name);
param_.out = GetMutableVar<lite::Tensor>(scope, out_name);
param_.background_label = opdesc.GetAttr<int>("background_label");
param_.keep_top_k = opdesc.GetAttr<int>("keep_top_k");
param_.nms_top_k = opdesc.GetAttr<int>("nms_top_k");
param_.score_threshold = opdesc.GetAttr<float>("score_threshold");
param_.nms_threshold = opdesc.GetAttr<float>("nms_threshold");
param_.nms_eta = opdesc.GetAttr<float>("nms_eta");
if (opdesc.HasAttr("share_location")) {
param_.share_location = opdesc.GetAttr<bool>("share_location");
if (opdesc.HasAttr("normalized")) {
param_.normalized = opdesc.GetAttr<bool>("normalized");
}
return true;
}
......
......@@ -499,18 +499,16 @@ struct BoxCoderParam {
/// ----------------------- multiclass_nms operators ----------------------
struct MulticlassNmsParam {
const lite::Tensor* bbox_data{};
const lite::Tensor* conf_data{};
lite::Tensor* out;
std::vector<int> priors;
int class_num;
int background_label;
const lite::Tensor* bboxes{};
const lite::Tensor* scores{};
lite::Tensor* out{};
int background_label{0};
float score_threshold{};
int nms_top_k{};
float nms_threshold{0.3};
float nms_eta{1.0};
int keep_top_k;
int nms_top_k;
float score_threshold;
float nms_threshold;
float nms_eta;
bool share_location{true};
bool normalized{true};
};
/// ----------------------- priorbox operators ----------------------
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册