Skip to content

Commit ca2e96f

Browse files
committed
update code
1 parent 534cf74 commit ca2e96f

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

paddle/operators/prior_box_op.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,14 @@ class PriorBoxOpMaker : public framework::OpProtoAndCheckerMaker {
9898
"the input image data of PriorBoxOp, The layout is NCHW.");
9999
AddOutput("Boxes",
100100
"(Tensor, default Tensor<float>), the output prior boxes of "
101-
"PriorBoxOp. The layout is [layer_height, layer_width, "
102-
"num_priors, 4]. layer_height is the height of input, "
103-
"layer_width is the width of input, num_priors is the box "
104-
"count of each position.");
101+
"PriorBoxOp. The layout is [H, W, num_priors, 4]. "
102+
"H is the height of input, W is the width of input, num_priors "
103+
"is the box count of each position.");
105104
AddOutput("Variances",
106105
"(Tensor, default Tensor<float>), the expanded variances of "
107-
"PriorBoxOp. The layout is [layer_height, layer_width, "
108-
"num_priors, 4]. layer_height is the height of input, "
109-
"layer_width is the width of input, num_priors is the box "
110-
"count of each position.");
106+
"PriorBoxOp. The layout is [H, W, num_priors, 4]. "
107+
"H is the height of input, W is the width of input, num_priors "
108+
"is the box count of each position.");
111109
AddAttr<std::vector<int>>("min_sizes", "(vector<int>) ",
112110
"List of min sizes of generated prior boxes.");
113111
AddAttr<std::vector<int>>("max_sizes", "(vector<int>) ",

paddle/operators/prior_box_op.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ class PriorBoxOpKernel : public framework::OpKernel<T> {
7777
auto img_width = image->dims()[3];
7878
auto img_height = image->dims()[2];
7979

80-
auto layer_width = input->dims()[3];
81-
auto layer_height = input->dims()[2];
80+
auto feature_width = input->dims()[3];
81+
auto feature_height = input->dims()[2];
8282

8383
T step_width, step_height;
8484
if (step_w == 0 || step_h == 0) {
85-
step_width = static_cast<T>(img_width) / layer_width;
86-
step_height = static_cast<T>(img_height) / layer_height;
85+
step_width = static_cast<T>(img_width) / feature_width;
86+
step_height = static_cast<T>(img_height) / feature_height;
8787
} else {
8888
step_width = step_w;
8989
step_height = step_h;
@@ -98,8 +98,8 @@ class PriorBoxOpKernel : public framework::OpKernel<T> {
9898
vars->mutable_data<T>(ctx.GetPlace());
9999

100100
auto e_boxes = framework::EigenTensor<T, 4>::From(*boxes);
101-
for (int h = 0; h < layer_height; ++h) {
102-
for (int w = 0; w < layer_width; ++w) {
101+
for (int h = 0; h < feature_height; ++h) {
102+
for (int w = 0; w < feature_width; ++w) {
103103
T center_x = (w + offset) * step_width;
104104
T center_y = (h + offset) * step_height;
105105
T box_width, box_height;
@@ -164,12 +164,16 @@ class PriorBoxOpKernel : public framework::OpKernel<T> {
164164
boxes->data<T>(), clip_func);
165165
}
166166

167-
Eigen::Tensor<T, 2, Eigen::RowMajor> var_et(1, variances.size());
167+
framework::Tensor var_t;
168+
var_t.mutable_data<T>(
169+
framework::make_ddim({1, static_cast<int>(variances.size())}),
170+
ctx.GetPlace());
171+
auto var_et = framework::EigenTensor<T, 2>::From(var_t);
168172
for (size_t i = 0; i < variances.size(); ++i) {
169173
var_et(0, i) = variances[i];
170174
}
171175

172-
int box_num = layer_height * layer_width * num_priors;
176+
int box_num = feature_height * feature_width * num_priors;
173177
auto var_dim = vars->dims();
174178
vars->Resize({box_num, static_cast<int>(variances.size())});
175179

0 commit comments

Comments
 (0)