@@ -46,13 +46,6 @@ inline void ExpandAspectRatios(const std::vector<float>& input_aspect_ratior,
46
46
}
47
47
}
48
48
49
- template <typename T>
50
- struct ClipFunctor {
51
- HOSTDEVICE inline T operator ()(T in) const {
52
- return std::min<T>(std::max<T>(in, 0 .), 1 .);
53
- }
54
- };
55
-
56
49
template <typename T>
57
50
class PriorBoxOpKernel : public framework ::OpKernel<T> {
58
51
public:
@@ -101,31 +94,30 @@ class PriorBoxOpKernel : public framework::OpKernel<T> {
101
94
boxes->mutable_data <T>(ctx.GetPlace ());
102
95
vars->mutable_data <T>(ctx.GetPlace ());
103
96
104
- auto e_boxes = framework::EigenTensor<T, 4 >:: From (*boxes );
97
+ T* b_t = boxes-> data <T>( );
105
98
for (int h = 0 ; h < feature_height; ++h) {
106
99
for (int w = 0 ; w < feature_width; ++w) {
107
100
T center_x = (w + offset) * step_width;
108
101
T center_y = (h + offset) * step_height;
109
102
T box_width, box_height;
110
- int idx = 0 ;
111
103
for (size_t s = 0 ; s < min_sizes.size (); ++s) {
112
104
auto min_size = min_sizes[s];
113
105
if (min_max_aspect_ratios_order) {
114
106
box_width = box_height = min_size / 2 .;
115
- e_boxes (h, w, idx, 0 ) = (center_x - box_width) / img_width;
116
- e_boxes (h, w, idx, 1 ) = (center_y - box_height) / img_height;
117
- e_boxes (h, w, idx, 2 ) = (center_x + box_width) / img_width;
118
- e_boxes (h, w, idx, 3 ) = (center_y + box_height) / img_height;
119
- idx++ ;
107
+ b_t [ 0 ] = (center_x - box_width) / img_width;
108
+ b_t [ 1 ] = (center_y - box_height) / img_height;
109
+ b_t [ 2 ] = (center_x + box_width) / img_width;
110
+ b_t [ 3 ] = (center_y + box_height) / img_height;
111
+ b_t += 4 ;
120
112
if (max_sizes.size () > 0 ) {
121
113
auto max_size = max_sizes[s];
122
114
// square prior with size sqrt(minSize * maxSize)
123
115
box_width = box_height = sqrt (min_size * max_size) / 2 .;
124
- e_boxes (h, w, idx, 0 ) = (center_x - box_width) / img_width;
125
- e_boxes (h, w, idx, 1 ) = (center_y - box_height) / img_height;
126
- e_boxes (h, w, idx, 2 ) = (center_x + box_width) / img_width;
127
- e_boxes (h, w, idx, 3 ) = (center_y + box_height) / img_height;
128
- idx++ ;
116
+ b_t [ 0 ] = (center_x - box_width) / img_width;
117
+ b_t [ 1 ] = (center_y - box_height) / img_height;
118
+ b_t [ 2 ] = (center_x + box_width) / img_width;
119
+ b_t [ 3 ] = (center_y + box_height) / img_height;
120
+ b_t += 4 ;
129
121
}
130
122
// priors with different aspect ratios
131
123
for (size_t r = 0 ; r < aspect_ratios.size (); ++r) {
@@ -135,45 +127,44 @@ class PriorBoxOpKernel : public framework::OpKernel<T> {
135
127
}
136
128
box_width = min_size * sqrt (ar) / 2 .;
137
129
box_height = min_size / sqrt (ar) / 2 .;
138
- e_boxes (h, w, idx, 0 ) = (center_x - box_width) / img_width;
139
- e_boxes (h, w, idx, 1 ) = (center_y - box_height) / img_height;
140
- e_boxes (h, w, idx, 2 ) = (center_x + box_width) / img_width;
141
- e_boxes (h, w, idx, 3 ) = (center_y + box_height) / img_height;
142
- idx++ ;
130
+ b_t [ 0 ] = (center_x - box_width) / img_width;
131
+ b_t [ 1 ] = (center_y - box_height) / img_height;
132
+ b_t [ 2 ] = (center_x + box_width) / img_width;
133
+ b_t [ 3 ] = (center_y + box_height) / img_height;
134
+ b_t += 4 ;
143
135
}
144
136
} else {
145
137
// priors with different aspect ratios
146
138
for (size_t r = 0 ; r < aspect_ratios.size (); ++r) {
147
139
float ar = aspect_ratios[r];
148
140
box_width = min_size * sqrt (ar) / 2 .;
149
141
box_height = min_size / sqrt (ar) / 2 .;
150
- e_boxes (h, w, idx, 0 ) = (center_x - box_width) / img_width;
151
- e_boxes (h, w, idx, 1 ) = (center_y - box_height) / img_height;
152
- e_boxes (h, w, idx, 2 ) = (center_x + box_width) / img_width;
153
- e_boxes (h, w, idx, 3 ) = (center_y + box_height) / img_height;
154
- idx++ ;
142
+ b_t [ 0 ] = (center_x - box_width) / img_width;
143
+ b_t [ 1 ] = (center_y - box_height) / img_height;
144
+ b_t [ 2 ] = (center_x + box_width) / img_width;
145
+ b_t [ 3 ] = (center_y + box_height) / img_height;
146
+ b_t += 4 ;
155
147
}
156
148
if (max_sizes.size () > 0 ) {
157
149
auto max_size = max_sizes[s];
158
150
// square prior with size sqrt(minSize * maxSize)
159
151
box_width = box_height = sqrt (min_size * max_size) / 2 .;
160
- e_boxes (h, w, idx, 0 ) = (center_x - box_width) / img_width;
161
- e_boxes (h, w, idx, 1 ) = (center_y - box_height) / img_height;
162
- e_boxes (h, w, idx, 2 ) = (center_x + box_width) / img_width;
163
- e_boxes (h, w, idx, 3 ) = (center_y + box_height) / img_height;
164
- idx++ ;
152
+ b_t [ 0 ] = (center_x - box_width) / img_width;
153
+ b_t [ 1 ] = (center_y - box_height) / img_height;
154
+ b_t [ 2 ] = (center_x + box_width) / img_width;
155
+ b_t [ 3 ] = (center_y + box_height) / img_height;
156
+ b_t += 4 ;
165
157
}
166
158
}
167
159
}
168
160
}
169
161
}
170
162
171
163
if (clip) {
172
- platform::Transform<platform::CPUDeviceContext> trans;
173
- ClipFunctor<T> clip_func;
174
- trans (ctx.template device_context <platform::CPUDeviceContext>(),
175
- boxes->data <T>(), boxes->data <T>() + boxes->numel (),
176
- boxes->data <T>(), clip_func);
164
+ T* dt = boxes->data <T>();
165
+ std::transform (dt, dt + boxes->numel (), dt, [](T v) -> T {
166
+ return std::min<T>(std::max<T>(v, 0 .), 1 .);
167
+ });
177
168
}
178
169
179
170
framework::Tensor var_t ;
0 commit comments