Conversation
qingqing01
left a comment
There was a problem hiding this comment.
Only part of the code is reviewed.
paddle/operators/box_coder_op.cc
Outdated
| @@ -0,0 +1,106 @@ | |||
| /* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. | |||
paddle/operators/box_coder_op.cc
Outdated
| AddInput( | ||
| "PriorBox", | ||
| "(Tensor, default Tensor<float>) " | ||
| "Box list PriorBox is a 2-D Tensor with shape [M, 4] holds N boxes, " |
paddle/operators/box_coder_op.cc
Outdated
| "coordinate of the anchor box."); | ||
| AddInput("PriorBoxVar", | ||
| "(Tensor, default Tensor<float>) " | ||
| "PriorBoxVar is a 2-D Tensor with shape [M, 4] holds N group " |
There was a problem hiding this comment.
M, 4] holds N group -> M, 4] holds M group
paddle/operators/box_coder_op.cc
Outdated
| auto prior_box_var_dims = ctx->GetInputDim("PriorBoxVar"); | ||
| auto target_box_dims = ctx->GetInputDim("TargetBox"); | ||
|
|
||
| PADDLE_ENFORCE_EQ(prior_box_dims.size(), 2UL, |
There was a problem hiding this comment.
The type of prior_box_dims.size() is int, comparing with 2UL will generate warnings. Just 2 is ok. The same as below.
paddle/operators/box_coder_op.cc
Outdated
| 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]"); |
There was a problem hiding this comment.
change line 38 - line 41 to:
PADDLE_ENFORCE_EQ(prior_box_dims, prior_box_var_dims);
paddle/operators/box_coder_op.cc
Outdated
|
|
||
| AddComment(R"DOC( | ||
| Bounding Box Coder Operator. | ||
| Encode/Decode the priorbox information with the target bounding box. |
There was a problem hiding this comment.
Need more detailed description for encode and decode.
paddle/operators/box_coder_op.h
Outdated
| 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."); |
There was a problem hiding this comment.
All these checks have been done in the InferShape, can be removed here.
| 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>(); |
There was a problem hiding this comment.
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.
paddle/operators/box_coder_op.h
Outdated
|
|
||
| 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]; |
There was a problem hiding this comment.
Do not use 4 directly, 4 can be got by the column of prior_box.
paddle/operators/box_coder_op.h
Outdated
| 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."); |
paddle/operators/box_coder_op.cu
Outdated
| namespace paddle { | ||
| namespace operators { | ||
|
|
||
| using platform::PADDLE_CUDA_NUM_THREADS; |
There was a problem hiding this comment.
It seems PADDLE_CUDA_NUM_THREADS is not used.
| 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] |
There was a problem hiding this comment.
Maybe short naming makes the code clearly.
另外,这里也可以看下是否可以用向量直接操作,而不是 for i in range(target_box.shape[0]):
There was a problem hiding this comment.
向量操作改完了,名字的话和上面的最后看情况一起改吧
paddle/operators/box_coder_op.cc
Outdated
| "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"), |
There was a problem hiding this comment.
PADDLE_ENFORCE(ctx->HasInput("TargetBox"),| 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."); |
There was a problem hiding this comment.
Also need to check output var:
PADDLE_ENFORCE(ctx->HasOutput("OutputBox"), ...);
| def setUp(self): | ||
| self.op_type = "box_coder" | ||
| lod = [[0, 20]] | ||
| prior_box = np.random.random((10, 4)).astype('float32') |
There was a problem hiding this comment.
Actually, [xmin, ymin, xmax, ymax] in prior box should follow: xmin < xmax, ymin < ymax. 这里,我觉得等box_coder, hard_example_mine, nms_op merge之后统一改下,写成一个函数,这几个op的单测复用。 这里随机生成,测正确性没有问题,就暂时不改了。
paddle/operators/box_coder_op.h
Outdated
| namespace operators { | ||
|
|
||
| using Tensor = framework::Tensor; | ||
| using LoDTensor = framework::LoDTensor; |
There was a problem hiding this comment.
Remove these two lines, use framework::Tensor and framework::LoDTensordirectly in following code.
Fix #7794