@@ -14,6 +14,7 @@ limitations under the License. */
14
14
#include < string>
15
15
#include < vector>
16
16
#include " paddle/fluid/framework/op_registry.h"
17
+ #include " paddle/fluid/operators/detection/bbox_util.h"
17
18
#include " paddle/fluid/operators/gather.h"
18
19
#include " paddle/fluid/operators/math/concat.h"
19
20
#include " paddle/fluid/operators/math/math_function.h"
@@ -133,31 +134,6 @@ void BboxOverlaps(const Tensor& r_boxes, const Tensor& c_boxes,
133
134
}
134
135
}
135
136
136
- template <typename T>
137
- void BoxToDelta (int box_num, const Tensor& ex_boxes, const Tensor& gt_boxes,
138
- const std::vector<float >& weights, Tensor* box_delta) {
139
- auto ex_boxes_et = framework::EigenTensor<T, 2 >::From (ex_boxes);
140
- auto gt_boxes_et = framework::EigenTensor<T, 2 >::From (gt_boxes);
141
- auto box_delta_et = framework::EigenTensor<T, 2 >::From (*box_delta);
142
- T ex_w, ex_h, ex_ctr_x, ex_ctr_y, gt_w, gt_h, gt_ctr_x, gt_ctr_y;
143
- for (int64_t i = 0 ; i < box_num; ++i) {
144
- ex_w = ex_boxes_et (i, 2 ) - ex_boxes_et (i, 0 ) + 1 ;
145
- ex_h = ex_boxes_et (i, 3 ) - ex_boxes_et (i, 1 ) + 1 ;
146
- ex_ctr_x = ex_boxes_et (i, 0 ) + 0.5 * ex_w;
147
- ex_ctr_y = ex_boxes_et (i, 1 ) + 0.5 * ex_h;
148
-
149
- gt_w = gt_boxes_et (i, 2 ) - gt_boxes_et (i, 0 ) + 1 ;
150
- gt_h = gt_boxes_et (i, 3 ) - gt_boxes_et (i, 1 ) + 1 ;
151
- gt_ctr_x = gt_boxes_et (i, 0 ) + 0.5 * gt_w;
152
- gt_ctr_y = gt_boxes_et (i, 1 ) + 0.5 * gt_h;
153
-
154
- box_delta_et (i, 0 ) = (gt_ctr_x - ex_ctr_x) / ex_w / weights[0 ];
155
- box_delta_et (i, 1 ) = (gt_ctr_y - ex_ctr_y) / ex_h / weights[1 ];
156
- box_delta_et (i, 2 ) = log (gt_w / ex_w) / ex_w / weights[2 ];
157
- box_delta_et (i, 3 ) = log (gt_h / ex_h) / ex_h / weights[3 ];
158
- }
159
- }
160
-
161
137
template <typename T>
162
138
std::vector<std::vector<int >> SampleFgBgGt (
163
139
const platform::CPUDeviceContext& context, Tensor* iou,
@@ -243,12 +219,11 @@ void GatherBoxesLabels(const platform::CPUDeviceContext& context,
243
219
Tensor* sampled_labels, Tensor* sampled_gts) {
244
220
int fg_num = fg_inds.size ();
245
221
int bg_num = bg_inds.size ();
246
- int gt_num = fg_num + bg_num;
247
222
Tensor fg_inds_t , bg_inds_t , gt_box_inds_t , gt_label_inds_t ;
248
223
int * fg_inds_data = fg_inds_t .mutable_data <int >({fg_num}, context.GetPlace ());
249
224
int * bg_inds_data = bg_inds_t .mutable_data <int >({bg_num}, context.GetPlace ());
250
225
int * gt_box_inds_data =
251
- gt_box_inds_t .mutable_data <int >({gt_num }, context.GetPlace ());
226
+ gt_box_inds_t .mutable_data <int >({fg_num }, context.GetPlace ());
252
227
int * gt_label_inds_data =
253
228
gt_label_inds_t .mutable_data <int >({fg_num}, context.GetPlace ());
254
229
std::copy (fg_inds.begin (), fg_inds.end (), fg_inds_data);
@@ -303,18 +278,20 @@ std::vector<Tensor> SampleRoisForOneImage(
303
278
304
279
// Gather boxes and labels
305
280
Tensor sampled_boxes, sampled_labels, sampled_gts;
306
- int boxes_num = fg_inds.size () + bg_inds.size ();
281
+ int fg_num = fg_inds.size ();
282
+ int bg_num = bg_inds.size ();
283
+ int boxes_num = fg_num + bg_num;
307
284
framework::DDim bbox_dim ({boxes_num, kBoxDim });
308
285
sampled_boxes.mutable_data <T>(bbox_dim, context.GetPlace ());
309
286
sampled_labels.mutable_data <int >({boxes_num}, context.GetPlace ());
310
- sampled_gts.mutable_data <T>(bbox_dim , context.GetPlace ());
287
+ sampled_gts.mutable_data <T>({fg_num, kBoxDim } , context.GetPlace ());
311
288
GatherBoxesLabels<T>(context, boxes, *gt_boxes, *gt_classes, fg_inds, bg_inds,
312
289
gt_inds, &sampled_boxes, &sampled_labels, &sampled_gts);
313
290
314
291
// Compute targets
315
292
Tensor bbox_targets_single;
316
293
bbox_targets_single.mutable_data <T>(bbox_dim, context.GetPlace ());
317
- BoxToDelta<T>(boxes_num , sampled_boxes, sampled_gts, bbox_reg_weights ,
294
+ BoxToDelta<T>(fg_num , sampled_boxes, sampled_gts, nullptr , false ,
318
295
&bbox_targets_single);
319
296
320
297
// Scale rois
@@ -427,7 +404,7 @@ class GenerateProposalLabelsKernel : public framework::OpKernel<T> {
427
404
auto rpn_rois_lod = rpn_rois->lod ().back ();
428
405
auto gt_classes_lod = gt_classes->lod ().back ();
429
406
auto gt_boxes_lod = gt_boxes->lod ().back ();
430
- for (size_t i = 0 ; i < n; ++i) {
407
+ for (int i = 0 ; i < n; ++i) {
431
408
Tensor rpn_rois_slice =
432
409
rpn_rois->Slice (rpn_rois_lod[i], rpn_rois_lod[i + 1 ]);
433
410
Tensor gt_classes_slice =
0 commit comments