forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbox_transform_op.h
73 lines (64 loc) · 2.61 KB
/
bbox_transform_op.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2004-present Facebook. All Rights Reserved.
#ifndef BBOX_TRANSFORM_OP_H_
#define BBOX_TRANSFORM_OP_H_
#include "caffe2/core/context.h"
#include "caffe2/core/export_caffe2_op_to_c10.h"
#include "caffe2/core/logging.h"
#include "caffe2/core/operator.h"
#include "caffe2/utils/math.h"
C10_DECLARE_EXPORT_CAFFE2_OP_TO_C10(BBoxTransform)
namespace caffe2 {
template <typename T, class Context>
class BBoxTransformOp final : public Operator<Context> {
public:
template <class... Args>
explicit BBoxTransformOp(Args&&... args)
: Operator<Context>(std::forward<Args>(args)...),
weights_(this->template GetRepeatedArgument<T>(
"weights",
vector<T>{1.0f, 1.0f, 1.0f, 1.0f})),
apply_scale_(
this->template GetSingleArgument<bool>("apply_scale", true)),
rotated_(this->template GetSingleArgument<bool>("rotated", false)),
angle_bound_on_(
this->template GetSingleArgument<bool>("angle_bound_on", true)),
angle_bound_lo_(
this->template GetSingleArgument<int>("angle_bound_lo", -90)),
angle_bound_hi_(
this->template GetSingleArgument<int>("angle_bound_hi", 90)),
clip_angle_thresh_(
this->template GetSingleArgument<float>("clip_angle_thresh", 1.0)),
legacy_plus_one_(
this->template GetSingleArgument<bool>("legacy_plus_one", true)) {
CAFFE_ENFORCE_EQ(
weights_.size(),
4,
"weights size " + c10::to_string(weights_.size()) + "must be 4.");
}
USE_OPERATOR_CONTEXT_FUNCTIONS;
bool RunOnDevice() override;
protected:
// weights [wx, wy, ww, wh] to apply to the regression target
vector<T> weights_;
// Transform the boxes to the scaled image space after applying the bbox
// deltas.
// Set to false to match the detectron code, set to true for the keypoint
// model and for backward compatibility
bool apply_scale_{true};
// Set for RRPN case to handle rotated boxes. Inputs should be in format
// [ctr_x, ctr_y, width, height, angle (in degrees)].
bool rotated_{false};
// If set, for rotated boxes in RRPN, output angles are normalized to be
// within [angle_bound_lo, angle_bound_hi].
bool angle_bound_on_{true};
int angle_bound_lo_{-90};
int angle_bound_hi_{90};
// For RRPN, clip almost horizontal boxes within this threshold of
// tolerance for backward compatibility. Set to negative value for
// no clipping.
float clip_angle_thresh_{1.0};
// The infamous "+ 1" for box width and height dating back to the DPM days
bool legacy_plus_one_{true};
};
} // namespace caffe2
#endif // BBOX_TRANSFORM_OP_H_