Skip to content

Comments

add box coder op#7922

Merged
qingqing01 merged 8 commits intoPaddlePaddle:developfrom
Noplz:box_coder_op
Feb 2, 2018
Merged

add box coder op#7922
qingqing01 merged 8 commits intoPaddlePaddle:developfrom
Noplz:box_coder_op

Conversation

@Noplz
Copy link
Contributor

@Noplz Noplz commented Jan 28, 2018

Fix #7794

Copy link
Contributor

@qingqing01 qingqing01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only part of the code is reviewed.

@@ -0,0 +1,106 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2016 -> 2018.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

AddInput(
"PriorBox",
"(Tensor, default Tensor<float>) "
"Box list PriorBox is a 2-D Tensor with shape [M, 4] holds N boxes, "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N boxes -> M boxes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"coordinate of the anchor box.");
AddInput("PriorBoxVar",
"(Tensor, default Tensor<float>) "
"PriorBoxVar is a 2-D Tensor with shape [M, 4] holds N group "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M, 4] holds N group -> M, 4] holds M group

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

auto prior_box_var_dims = ctx->GetInputDim("PriorBoxVar");
auto target_box_dims = ctx->GetInputDim("TargetBox");

PADDLE_ENFORCE_EQ(prior_box_dims.size(), 2UL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of prior_box_dims.size() is int, comparing with 2UL will generate warnings. Just 2 is ok. The same as below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

PADDLE_ENFORCE_EQ(prior_box_var_dims.size(), 2UL,
"The rank of Input of PriorBoxVar must be 2");
PADDLE_ENFORCE_EQ(prior_box_var_dims[1], 4UL,
"The shape of PriorBoxVar is [N, 4]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change line 38 - line 41 to:

PADDLE_ENFORCE_EQ(prior_box_dims, prior_box_var_dims);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


AddComment(R"DOC(
Bounding Box Coder Operator.
Encode/Decode the priorbox information with the target bounding box.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need more detailed description for encode and decode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

PADDLE_ENFORCE_EQ(prior_box_var.dims().size(), 2,
"The rank of prior_box_var must be 2.");
PADDLE_ENFORCE_EQ(prior_box.dims()[0], prior_box_var.dims()[0],
"The dims of prior_box must equal to prior_box_var.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these checks have been done in the InferShape, can be removed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

int64_t col = prior_box.dims()[0];
auto* target_box_data = target_box.data<T>();
auto* prior_box_data = prior_box.data<T>();
auto* prior_box_var_data = prior_box_var.data<T>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For short name, maybe:

target_box_data -> tbd
prior_box_data -> pbd
prior_box_var_data -> pbv

? I'm not sure, shortly name make code more clearly.

Copy link
Contributor Author

@Noplz Noplz Jan 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkuyym @wanghaox any advice?


for (int64_t i = 0; i < row; ++i) {
for (int64_t j = 0; j < col; ++j) {
T prior_box_width = prior_box_data[j * 4 + 2] - prior_box_data[j * 4];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use 4 directly, 4 can be got by the column of prior_box.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

PADDLE_ENFORCE_EQ(prior_box_var.dims().size(), 2,
"The rank of prior_box_var must be 2.");
PADDLE_ENFORCE_EQ(prior_box.dims()[0], prior_box_var.dims()[0],
"The dims of prior_box must equal to prior_box_var.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

namespace paddle {
namespace operators {

using platform::PADDLE_CUDA_NUM_THREADS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems PADDLE_CUDA_NUM_THREADS is not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

output_box[i,:,2] = np.log(np.fabs(target_box_width[i] / prior_box_width)) / \
prior_box_var[:,2]
output_box[i,:,3] = np.log(np.fabs(target_box_height[i] / prior_box_height)) / \
prior_box_var[:,3]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe short naming makes the code clearly.

另外,这里也可以看下是否可以用向量直接操作,而不是 for i in range(target_box.shape[0]):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

向量操作改完了,名字的话和上面的最后看情况一起改吧

Copy link
Contributor

@qingqing01 qingqing01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost LGTM.

"Input(PriorBox) of BoxCoderOp should not be null.");
PADDLE_ENFORCE(ctx->HasInput("PriorBoxVar"),
"Input(PriorBoxVar) of BoxCoderOp should not be null.");
PADDLE_ENFORCE(ctx->HasInput("PriorBox"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PADDLE_ENFORCE(ctx->HasInput("TargetBox"),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

PADDLE_ENFORCE(ctx->HasInput("PriorBoxVar"),
"Input(PriorBoxVar) of BoxCoderOp should not be null.");
PADDLE_ENFORCE(ctx->HasInput("PriorBox"),
"Input(TargetBox) of BoxCoderOp should not be null.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to check output var:

PADDLE_ENFORCE(ctx->HasOutput("OutputBox"), ...);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

def setUp(self):
self.op_type = "box_coder"
lod = [[0, 20]]
prior_box = np.random.random((10, 4)).astype('float32')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, [xmin, ymin, xmax, ymax] in prior box should follow: xmin < xmax, ymin < ymax. 这里,我觉得等box_coder, hard_example_mine, nms_op merge之后统一改下,写成一个函数,这几个op的单测复用。 这里随机生成,测正确性没有问题,就暂时不改了。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的

namespace operators {

using Tensor = framework::Tensor;
using LoDTensor = framework::LoDTensor;
Copy link
Contributor

@qingqing01 qingqing01 Feb 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these two lines, use framework::Tensor and framework::LoDTensordirectly in following code.

Copy link
Contributor

@qingqing01 qingqing01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@qingqing01 qingqing01 merged commit b7db353 into PaddlePaddle:develop Feb 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants