Skip to content

Commit 54e4c4d

Browse files
newstzpzfacebook-github-bot
authored andcommitted
Removed obsolete argument correct_transform_coords in bbox_transform op. (pytorch#16723)
Summary: Pull Request resolved: pytorch#16723 Removed obsolete argument correct_transform_coords in bbox_transform op. * It was only for backward compatibility. We should not have models using it now. Differential Revision: D13937430 fbshipit-source-id: 504bb066137ce408c12dc9dcc2e0a513bad9b7ee
1 parent 075c7b1 commit 54e4c4d

8 files changed

+20
-63
lines changed

caffe2/operators/bbox_transform_op.cc

+3-11
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ Transform proposal bounding boxes to target bounding box using bounding box
2121
" after applying the bbox deltas."
2222
"Set to false to match the detectron code, set to true for keypoint"
2323
" models and for backward compatibility")
24-
.Arg(
25-
"correct_transform_coords",
26-
"bool (default false), Correct bounding box transform coordates,"
27-
" see bbox_transform() in boxes.py "
28-
"Set to true to match the detectron code, set to false for backward"
29-
" compatibility")
3024
.Arg(
3125
"rotated",
3226
"bool (default false). If true, then boxes (rois and deltas) include "
@@ -160,7 +154,6 @@ bool BBoxTransformOp<float, CPUContext>::RunOnDevice() {
160154
cur_deltas,
161155
weights_,
162156
utils::BBOX_XFORM_CLIP_DEFAULT,
163-
correct_transform_coords_,
164157
angle_bound_on_,
165158
angle_bound_lo_,
166159
angle_bound_hi_);
@@ -188,7 +181,8 @@ bool BBoxTransformOp<float, CPUContext>::RunOnDevice() {
188181

189182
} // namespace caffe2
190183

191-
using BBoxTransformOpFloatCPU = caffe2::BBoxTransformOp<float, caffe2::CPUContext>;
184+
using BBoxTransformOpFloatCPU =
185+
caffe2::BBoxTransformOp<float, caffe2::CPUContext>;
192186

193187
C10_REGISTER_CAFFE2_OPERATOR_CPU(
194188
BBoxTransform,
@@ -198,7 +192,6 @@ C10_REGISTER_CAFFE2_OPERATOR_CPU(
198192
c10::Argument("im_info"),
199193
c10::Argument("weights", ListType::create(FloatType::get())),
200194
c10::Argument("apply_scale", BoolType::get()),
201-
c10::Argument("correct_transform_coords", BoolType::get()),
202195
c10::Argument("rotated", BoolType::get()),
203196
c10::Argument("angle_bound_on", BoolType::get()),
204197
c10::Argument("angle_bound_lo", IntType::get()),
@@ -209,5 +202,4 @@ C10_REGISTER_CAFFE2_OPERATOR_CPU(
209202
c10::Argument("output_0"),
210203
c10::Argument("output_1"),
211204
}),
212-
BBoxTransformOpFloatCPU
213-
);
205+
BBoxTransformOpFloatCPU);

caffe2/operators/bbox_transform_op.h

-7
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ class BBoxTransformOp final : public Operator<Context> {
2323
vector<T>{1.0f, 1.0f, 1.0f, 1.0f})),
2424
apply_scale_(
2525
this->template GetSingleArgument<bool>("apply_scale", true)),
26-
correct_transform_coords_(this->template GetSingleArgument<bool>(
27-
"correct_transform_coords",
28-
false)),
2926
rotated_(this->template GetSingleArgument<bool>("rotated", false)),
3027
angle_bound_on_(
3128
this->template GetSingleArgument<bool>("angle_bound_on", true)),
@@ -52,10 +49,6 @@ class BBoxTransformOp final : public Operator<Context> {
5249
// Set to false to match the detectron code, set to true for the keypoint
5350
// model and for backward compatibility
5451
bool apply_scale_{true};
55-
// Correct bounding box transform coordates, see bbox_transform() in boxes.py
56-
// Set to true to match the detectron code, set to false for backward
57-
// compatibility
58-
bool correct_transform_coords_{false};
5952
// Set for RRPN case to handle rotated boxes. Inputs should be in format
6053
// [ctr_x, ctr_y, width, height, angle (in degrees)].
6154
bool rotated_{false};

caffe2/operators/generate_proposals_op.cc

+1-10
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ void GenerateProposalsOp<CPUContext>::ProposalsForOneImage(
228228
bbox_deltas_sorted,
229229
bbox_weights,
230230
utils::BBOX_XFORM_CLIP_DEFAULT,
231-
correct_transform_coords_,
232231
angle_bound_on_,
233232
angle_bound_lo_,
234233
angle_bound_hi_);
@@ -363,12 +362,6 @@ non-maximum suppression is applied to generate the final bounding boxes.
363362
.Arg("post_nms_topN", "(int) RPN_POST_NMS_TOP_N")
364363
.Arg("nms_thresh", "(float) RPN_NMS_THRESH")
365364
.Arg("min_size", "(float) RPN_MIN_SIZE")
366-
.Arg(
367-
"correct_transform_coords",
368-
"bool (default false), Correct bounding box transform coordates,"
369-
" see bbox_transform() in boxes.py "
370-
"Set to true to match the detectron code, set to false for backward"
371-
" compatibility")
372365
.Arg(
373366
"angle_bound_on",
374367
"bool (default true). If set, for rotated boxes, angle is "
@@ -425,7 +418,6 @@ C10_REGISTER_CAFFE2_OPERATOR_CPU(
425418
c10::Argument("post_nms_topN", IntType::get()),
426419
c10::Argument("nms_thresh", FloatType::get()),
427420
c10::Argument("min_size", FloatType::get()),
428-
c10::Argument("correct_transform_coords", BoolType::get()),
429421
c10::Argument("angle_bound_on", BoolType::get()),
430422
c10::Argument("angle_bound_lo", IntType::get()),
431423
c10::Argument("angle_bound_hi", IntType::get()),
@@ -435,5 +427,4 @@ C10_REGISTER_CAFFE2_OPERATOR_CPU(
435427
c10::Argument("output_0"),
436428
c10::Argument("output_1"),
437429
}),
438-
caffe2::GenerateProposalsOp<caffe2::CPUContext>
439-
);
430+
caffe2::GenerateProposalsOp<caffe2::CPUContext>);

caffe2/operators/generate_proposals_op.cu

+2-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ __global__ void GeneratePreNMSUprightBoxesKernel(
2323
const float* d_img_info_vec,
2424
const int num_images,
2525
const float bbox_xform_clip,
26-
const bool correct_transform,
2726
float4* d_out_boxes,
2827
const int prenms_nboxes, // leading dimension of out_boxes
2928
float* d_inout_scores,
@@ -87,19 +86,14 @@ __global__ void GeneratePreNMSUprightBoxesKernel(
8786
const float pred_ctr_x = ctr_x + width * dx; // TODO fuse madd
8887
const float pred_w = width * expf(dw);
8988
x1 = pred_ctr_x - 0.5f * pred_w;
90-
x2 = pred_ctr_x + 0.5f * pred_w;
89+
x2 = pred_ctr_x + 0.5f * pred_w - 1.0f;
9190

9291
float height = y2 - y1 + 1.0f;
9392
const float ctr_y = y1 + 0.5f * height;
9493
const float pred_ctr_y = ctr_y + height * dy;
9594
const float pred_h = height * expf(dh);
9695
y1 = pred_ctr_y - 0.5f * pred_h;
97-
y2 = pred_ctr_y + 0.5f * pred_h;
98-
99-
if (correct_transform) {
100-
x2 -= 1.0f;
101-
y2 -= 1.0f;
102-
}
96+
y2 = pred_ctr_y + 0.5f * pred_h - 1.0f;
10397

10498
// Clipping box to image
10599
const float img_height = d_img_info_vec[3 * image_index + 0];
@@ -491,7 +485,6 @@ bool GenerateProposalsOp<CUDAContext>::RunOnDevice() {
491485
d_im_info_vec,
492486
num_images,
493487
utils::BBOX_XFORM_CLIP_DEFAULT,
494-
correct_transform_coords_,
495488
reinterpret_cast<float4*>(d_boxes),
496489
nboxes_to_generate,
497490
d_sorted_scores,

caffe2/operators/generate_proposals_op.h

-7
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ class GenerateProposalsOp final : public Operator<Context> {
9191
rpn_nms_thresh_(
9292
this->template GetSingleArgument<float>("nms_thresh", 0.7f)),
9393
rpn_min_size_(this->template GetSingleArgument<float>("min_size", 16)),
94-
correct_transform_coords_(this->template GetSingleArgument<bool>(
95-
"correct_transform_coords",
96-
false)),
9794
angle_bound_on_(
9895
this->template GetSingleArgument<bool>("angle_bound_on", true)),
9996
angle_bound_lo_(
@@ -135,10 +132,6 @@ class GenerateProposalsOp final : public Operator<Context> {
135132
float rpn_nms_thresh_{0.7};
136133
// RPN_MIN_SIZE
137134
float rpn_min_size_{16};
138-
// Correct bounding box transform coordates, see bbox_transform() in boxes.py
139-
// Set to true to match the detectron code, set to false for backward
140-
// compatibility
141-
bool correct_transform_coords_{false};
142135
// If set, for rotated boxes in RRPN, output angles are normalized to be
143136
// within [angle_bound_lo, angle_bound_hi].
144137
bool angle_bound_on_{true};

caffe2/operators/generate_proposals_op_util_boxes.h

+4-9
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ EArrXXt<typename Derived1::Scalar> bbox_transform_upright(
3939
const Eigen::ArrayBase<Derived2>& deltas,
4040
const std::vector<typename Derived2::Scalar>& weights =
4141
std::vector<typename Derived2::Scalar>{1.0, 1.0, 1.0, 1.0},
42-
const float bbox_xform_clip = BBOX_XFORM_CLIP_DEFAULT,
43-
const bool correct_transform_coords = false) {
42+
const float bbox_xform_clip = BBOX_XFORM_CLIP_DEFAULT) {
4443
using T = typename Derived1::Scalar;
4544
using EArrXX = EArrXXt<T>;
4645
using EArrX = EArrXt<T>;
@@ -70,17 +69,15 @@ EArrXXt<typename Derived1::Scalar> bbox_transform_upright(
7069
EArrX pred_w = dw.exp() * widths;
7170
EArrX pred_h = dh.exp() * heights;
7271

73-
T offset(correct_transform_coords ? 1.0 : 0.0);
74-
7572
EArrXX pred_boxes = EArrXX::Zero(deltas.rows(), deltas.cols());
7673
// x1
7774
pred_boxes.col(0) = pred_ctr_x - T(0.5) * pred_w;
7875
// y1
7976
pred_boxes.col(1) = pred_ctr_y - T(0.5) * pred_h;
8077
// x2
81-
pred_boxes.col(2) = pred_ctr_x + T(0.5) * pred_w - offset;
78+
pred_boxes.col(2) = pred_ctr_x + T(0.5) * pred_w - T(1.0);
8279
// y2
83-
pred_boxes.col(3) = pred_ctr_y + T(0.5) * pred_h - offset;
80+
pred_boxes.col(3) = pred_ctr_y + T(0.5) * pred_h - T(1.0);
8481

8582
return pred_boxes;
8683
}
@@ -169,15 +166,13 @@ EArrXXt<typename Derived1::Scalar> bbox_transform(
169166
const std::vector<typename Derived2::Scalar>& weights =
170167
std::vector<typename Derived2::Scalar>{1.0, 1.0, 1.0, 1.0},
171168
const float bbox_xform_clip = BBOX_XFORM_CLIP_DEFAULT,
172-
const bool correct_transform_coords = false,
173169
const bool angle_bound_on = true,
174170
const int angle_bound_lo = -90,
175171
const int angle_bound_hi = 90) {
176172
CAFFE_ENFORCE(boxes.cols() == 4 || boxes.cols() == 5);
177173
if (boxes.cols() == 4) {
178174
// Upright boxes
179-
return bbox_transform_upright(
180-
boxes, deltas, weights, bbox_xform_clip, correct_transform_coords);
175+
return bbox_transform_upright(boxes, deltas, weights, bbox_xform_clip);
181176
} else {
182177
// Rotated boxes with angle info
183178
return bbox_transform_rotated(

caffe2/operators/generate_proposals_op_util_boxes_test.cc

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ TEST(UtilsBoxesTest, TestBboxTransformRandom) {
3131
bbox.array(),
3232
deltas.array(),
3333
std::vector<float>{1.0, 1.0, 1.0, 1.0},
34-
BBOX_XFORM_CLIP,
35-
true);
34+
BBOX_XFORM_CLIP);
3635
EXPECT_NEAR((result.matrix() - result_gt).norm(), 0.0, 1e-4);
3736
}
3837

@@ -65,7 +64,6 @@ TEST(UtilsBoxesTest, TestBboxTransformRotated) {
6564
deltas.array(),
6665
std::vector<float>{1.0, 1.0, 1.0, 1.0},
6766
BBOX_XFORM_CLIP,
68-
true, /* correct_transform_coords */
6967
false /* angle_bound_on */);
7068
EXPECT_NEAR((result.matrix() - result_gt).norm(), 0.0, 1e-2);
7169
}
@@ -98,7 +96,6 @@ TEST(UtilsBoxesTest, TestBboxTransformRotatedNormalized) {
9896
deltas.array(),
9997
std::vector<float>{1.0, 1.0, 1.0, 1.0},
10098
BBOX_XFORM_CLIP,
101-
true, /* correct_transform_coords */
10299
true, /* angle_bound_on */
103100
-90, /* angle_bound_lo */
104101
90 /* angle_bound_hi */);

caffe2/python/operator_test/torch_integration_test.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import hypothesis.strategies as st
1111
import numpy as np
1212

13+
1314
def generate_rois(roi_counts, im_dims):
1415
assert len(roi_counts) == len(im_dims)
1516
all_rois = []
@@ -36,6 +37,7 @@ def generate_rois(roi_counts, im_dims):
3637
return np.vstack(all_rois)
3738
return np.empty((0, 5)).astype(np.float32)
3839

40+
3941
def generate_rois_rotated(roi_counts, im_dims):
4042
rois = generate_rois(roi_counts, im_dims)
4143
# [batch_id, ctr_x, ctr_y, w, h, angle]
@@ -48,6 +50,7 @@ def generate_rois_rotated(roi_counts, im_dims):
4850
rotated_rois[:, 5] = np.random.uniform(-90.0, 90.0) # angle in degrees
4951
return rotated_rois
5052

53+
5154
class TorchIntegration(hu.HypothesisTestCase):
5255

5356
@given(
@@ -58,15 +61,16 @@ class TorchIntegration(hu.HypothesisTestCase):
5861
clip_angle_thresh=st.sampled_from([-1.0, 1.0]),
5962
**hu.gcs_cpu_only
6063
)
61-
def test_bbox_transform(self,
64+
def test_bbox_transform(
65+
self,
6266
roi_counts,
6367
num_classes,
6468
rotated,
6569
angle_bound_on,
6670
clip_angle_thresh,
6771
gc,
6872
dc,
69-
):
73+
):
7074
"""
7175
Test with rois for multiple images in a batch
7276
"""
@@ -91,7 +95,6 @@ def bbox_transform_ref():
9195
["rois", "deltas", "im_info"],
9296
["box_out"],
9397
apply_scale=False,
94-
correct_transform_coords=True,
9598
rotated=rotated,
9699
angle_bound_on=angle_bound_on,
97100
clip_angle_thresh=clip_angle_thresh,
@@ -107,7 +110,7 @@ def bbox_transform_ref():
107110
torch.tensor(rois), torch.tensor(deltas),
108111
torch.tensor(im_info),
109112
[1.0, 1.0, 1.0, 1.0],
110-
False, True, rotated, angle_bound_on,
113+
False, rotated, angle_bound_on,
111114
-90, 90, clip_angle_thresh)
112115

113116
torch.testing.assert_allclose(box_out, a)
@@ -117,7 +120,7 @@ def bbox_transform_ref():
117120
H=st.integers(min_value=10, max_value=10),
118121
W=st.integers(min_value=8, max_value=8),
119122
img_count=st.integers(min_value=3, max_value=3),
120-
)
123+
)
121124
def test_generate_proposals(self, A, H, W, img_count):
122125
scores = np.ones((img_count, A, H, W)).astype(np.float32)
123126
bbox_deltas = np.linspace(0, 10, num=img_count*4*A*H*W).reshape(
@@ -145,6 +148,6 @@ def generate_proposals_ref():
145148
a, b = torch.ops._caffe2.GenerateProposals(
146149
torch.tensor(scores), torch.tensor(bbox_deltas),
147150
torch.tensor(im_info), torch.tensor(anchors),
148-
2.0, 6000, 300, 0.7, 16, False, True, -90, 90, 1.0)
151+
2.0, 6000, 300, 0.7, 16, True, -90, 90, 1.0)
149152
torch.testing.assert_allclose(rois, a)
150153
torch.testing.assert_allclose(rois_probs, b)

0 commit comments

Comments
 (0)