Skip to content

Commit 2d1a6f8

Browse files
authored
Fix cpplint issues in Detection_map_op (#9969)
* Fix conv_op.h * Fix conv_mkldnn_op * Fix cpplint issues in detection_map_op
1 parent d08791d commit 2d1a6f8

File tree

5 files changed

+67
-55
lines changed

5 files changed

+67
-55
lines changed

paddle/fluid/operators/conv_mkldnn_op.cc

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
7272
auto dst_md = platform::MKLDNNMemDesc(
7373
dst_tz, mkldnn::memory::data_type::f32, mkldnn::memory::format::nchw);
7474

75-
auto src_memory =
76-
mkldnn::memory({src_md, mkldnn_engine}, (void*)input_data);
77-
auto weights_memory =
78-
mkldnn::memory({weights_md, mkldnn_engine}, (void*)filter_data);
75+
auto src_memory = mkldnn::memory({src_md, mkldnn_engine},
76+
reinterpret_cast<void*>(input_data));
77+
auto weights_memory = mkldnn::memory({weights_md, mkldnn_engine},
78+
reinterpret_cast<void*>(filter_data));
7979
auto dst_memory = mkldnn::memory({dst_md, mkldnn_engine}, output_data);
8080

8181
std::shared_ptr<mkldnn::convolution_forward::primitive_desc> conv_pd =
@@ -180,8 +180,9 @@ class ConvMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
180180
dst_tz, mkldnn::memory::data_type::f32, mkldnn::memory::format::nchw);
181181

182182
// create memory
183-
auto diff_dst_memory = mkldnn::memory({diff_weights_md, mkldnn_engine},
184-
(void*)output_grad_data);
183+
auto diff_dst_memory =
184+
mkldnn::memory({diff_weights_md, mkldnn_engine},
185+
reinterpret_cast<void*>(output_grad_data));
185186
// Retrieve conv_pd from device context
186187
auto conv_pd =
187188
std::static_pointer_cast<mkldnn::convolution_forward::primitive_desc>(
@@ -198,10 +199,11 @@ class ConvMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
198199
mkldnn_engine);
199200

200201
// create memory
201-
auto diff_weights_memory = mkldnn::memory(
202-
{diff_weights_md, mkldnn_engine}, (void*)filter_grad_data);
203-
auto src_memory =
204-
mkldnn::memory({src_md, mkldnn_engine}, (void*)input_data);
202+
auto diff_weights_memory =
203+
mkldnn::memory({diff_weights_md, mkldnn_engine},
204+
reinterpret_cast<void*>(filter_grad_data));
205+
auto src_memory = mkldnn::memory({src_md, mkldnn_engine},
206+
reinterpret_cast<void*>(input_data));
205207

206208
// create backward conv primitive for weights
207209
auto conv_bwd_weights_prim = mkldnn::convolution_backward_weights(
@@ -221,9 +223,10 @@ class ConvMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
221223

222224
// create memory
223225
auto diff_src_memory =
224-
mkldnn::memory({diff_src_md, mkldnn_engine}, (void*)input_grad_data);
225-
auto weights_memory =
226-
mkldnn::memory({weights_md, mkldnn_engine}, (void*)filter_data);
226+
mkldnn::memory({diff_src_md, mkldnn_engine},
227+
reinterpret_cast<void*>(input_grad_data));
228+
auto weights_memory = mkldnn::memory(
229+
{weights_md, mkldnn_engine}, reinterpret_cast<void*>(filter_data));
227230

228231
// create backward conv primitive for data
229232
auto conv_bwd_data_prim = mkldnn::convolution_backward_data(

paddle/fluid/operators/conv_op.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ limitations under the License. */
1414

1515
#pragma once
1616

17+
#include <vector>
1718
#include "paddle/fluid/framework/eigen.h"
1819
#include "paddle/fluid/framework/op_registry.h"
1920
#include "paddle/fluid/operators/math/depthwise_conv.h"
@@ -41,9 +42,10 @@ inline int ConvOutputSize(int input_size, int filter_size, int dilation,
4142

4243
return output_size;
4344
}
44-
inline bool IsExpand(std::vector<int64_t>& filter_dim,
45-
std::vector<int>& strides, std::vector<int>& paddings,
46-
std::vector<int>& dilations) {
45+
inline bool IsExpand(const std::vector<int64_t>& filter_dim,
46+
const std::vector<int>& strides,
47+
const std::vector<int>& paddings,
48+
const std::vector<int>& dilations) {
4749
bool filter_1 = true, strides_1 = true, padding_0 = true, dilation_1 = true;
4850
for (size_t j = 0; j < strides.size(); ++j) {
4951
filter_1 = filter_1 && (static_cast<int>(filter_dim[j + 2]) == 1);

paddle/fluid/operators/detection_map_op.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#include "paddle/fluid/operators/detection_map_op.h"
16+
#include <string>
1617

1718
namespace paddle {
1819
namespace operators {

paddle/fluid/operators/detection_map_op.h

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#pragma once
16+
#include <algorithm>
17+
#include <map>
18+
#include <string>
19+
#include <utility>
20+
#include <vector>
1621
#include "paddle/fluid/framework/eigen.h"
1722
#include "paddle/fluid/framework/op_registry.h"
1823

@@ -82,7 +87,7 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
8287
std::vector<std::map<int, std::vector<Box>>> gt_boxes;
8388
std::vector<std::map<int, std::vector<std::pair<T, Box>>>> detect_boxes;
8489

85-
GetBoxes(*in_label, *in_detect, gt_boxes, detect_boxes);
90+
GetBoxes(*in_label, *in_detect, &gt_boxes, detect_boxes);
8691

8792
std::map<int, int> label_pos_count;
8893
std::map<int, std::vector<std::pair<T, int>>> true_pos;
@@ -95,20 +100,20 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
95100
}
96101

97102
if (in_pos_count != nullptr && state) {
98-
GetInputPos(*in_pos_count, *in_true_pos, *in_false_pos, label_pos_count,
99-
true_pos, false_pos, class_num);
103+
GetInputPos(*in_pos_count, *in_true_pos, *in_false_pos, &label_pos_count,
104+
&true_pos, &false_pos, class_num);
100105
}
101106

102107
CalcTrueAndFalsePositive(gt_boxes, detect_boxes, evaluate_difficult,
103-
overlap_threshold, label_pos_count, true_pos,
104-
false_pos);
108+
overlap_threshold, &label_pos_count, &true_pos,
109+
&false_pos);
105110

106111
int background_label = ctx.Attr<int>("background_label");
107112
T map = CalcMAP(ap_type, label_pos_count, true_pos, false_pos,
108113
background_label);
109114

110-
GetOutputPos(ctx, label_pos_count, true_pos, false_pos, *out_pos_count,
111-
*out_true_pos, *out_false_pos, class_num);
115+
GetOutputPos(ctx, label_pos_count, true_pos, false_pos, out_pos_count,
116+
out_true_pos, out_false_pos, class_num);
112117

113118
T* map_data = out_map->mutable_data<T>(ctx.GetPlace());
114119
map_data[0] = map;
@@ -155,7 +160,7 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
155160

156161
void GetBoxes(const framework::LoDTensor& input_label,
157162
const framework::LoDTensor& input_detect,
158-
std::vector<std::map<int, std::vector<Box>>>& gt_boxes,
163+
std::vector<std::map<int, std::vector<Box>>>* gt_boxes,
159164
std::vector<std::map<int, std::vector<std::pair<T, Box>>>>&
160165
detect_boxes) const {
161166
auto labels = framework::EigenTensor<T, 2>::From(input_label);
@@ -179,7 +184,7 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
179184
box.is_difficult = true;
180185
boxes[label].push_back(box);
181186
}
182-
gt_boxes.push_back(boxes);
187+
gt_boxes->push_back(boxes);
183188
}
184189

185190
auto detect_index = detect_lod[0];
@@ -200,9 +205,9 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
200205
const std::map<int, int>& label_pos_count,
201206
const std::map<int, std::vector<std::pair<T, int>>>& true_pos,
202207
const std::map<int, std::vector<std::pair<T, int>>>& false_pos,
203-
framework::Tensor& output_pos_count,
204-
framework::LoDTensor& output_true_pos,
205-
framework::LoDTensor& output_false_pos, const int class_num) const {
208+
framework::Tensor* output_pos_count,
209+
framework::LoDTensor* output_true_pos,
210+
framework::LoDTensor* output_false_pos, const int class_num) const {
206211
int true_pos_count = 0;
207212
int false_pos_count = 0;
208213
for (auto it = true_pos.begin(); it != true_pos.end(); ++it) {
@@ -214,12 +219,12 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
214219
false_pos_count += fp.size();
215220
}
216221

217-
int* pos_count_data = output_pos_count.mutable_data<int>(
222+
int* pos_count_data = output_pos_count->mutable_data<int>(
218223
framework::make_ddim({class_num, 1}), ctx.GetPlace());
219224

220-
T* true_pos_data = output_true_pos.mutable_data<T>(
225+
T* true_pos_data = output_true_pos->mutable_data<T>(
221226
framework::make_ddim({true_pos_count, 2}), ctx.GetPlace());
222-
T* false_pos_data = output_false_pos.mutable_data<T>(
227+
T* false_pos_data = output_false_pos->mutable_data<T>(
223228
framework::make_ddim({false_pos_count, 2}), ctx.GetPlace());
224229
true_pos_count = 0;
225230
false_pos_count = 0;
@@ -261,21 +266,21 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
261266
framework::LoD false_pos_lod;
262267
false_pos_lod.emplace_back(false_pos_starts);
263268

264-
output_true_pos.set_lod(true_pos_lod);
265-
output_false_pos.set_lod(false_pos_lod);
269+
output_true_pos->set_lod(true_pos_lod);
270+
output_false_pos->set_lod(false_pos_lod);
266271
return;
267272
}
268273

269274
void GetInputPos(const framework::Tensor& input_pos_count,
270275
const framework::LoDTensor& input_true_pos,
271276
const framework::LoDTensor& input_false_pos,
272-
std::map<int, int>& label_pos_count,
273-
std::map<int, std::vector<std::pair<T, int>>>& true_pos,
274-
std::map<int, std::vector<std::pair<T, int>>>& false_pos,
277+
std::map<int, int>* label_pos_count,
278+
std::map<int, std::vector<std::pair<T, int>>>* true_pos,
279+
std::map<int, std::vector<std::pair<T, int>>>* false_pos,
275280
const int class_num) const {
276281
const int* pos_count_data = input_pos_count.data<int>();
277282
for (int i = 0; i < class_num; ++i) {
278-
label_pos_count[i] = pos_count_data[i];
283+
(*label_pos_count)[i] = pos_count_data[i];
279284
}
280285

281286
auto SetData = [](const framework::LoDTensor& pos_tensor,
@@ -291,8 +296,8 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
291296
}
292297
};
293298

294-
SetData(input_true_pos, true_pos);
295-
SetData(input_false_pos, false_pos);
299+
SetData(input_true_pos, *true_pos);
300+
SetData(input_false_pos, *false_pos);
296301
return;
297302
}
298303

@@ -301,9 +306,9 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
301306
const std::vector<std::map<int, std::vector<std::pair<T, Box>>>>&
302307
detect_boxes,
303308
bool evaluate_difficult, float overlap_threshold,
304-
std::map<int, int>& label_pos_count,
305-
std::map<int, std::vector<std::pair<T, int>>>& true_pos,
306-
std::map<int, std::vector<std::pair<T, int>>>& false_pos) const {
309+
std::map<int, int>* label_pos_count,
310+
std::map<int, std::vector<std::pair<T, int>>>* true_pos,
311+
std::map<int, std::vector<std::pair<T, int>>>* false_pos) const {
307312
int batch_size = gt_boxes.size();
308313
for (int n = 0; n < batch_size; ++n) {
309314
auto image_gt_boxes = gt_boxes[n];
@@ -320,10 +325,10 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
320325
continue;
321326
}
322327
int label = it->first;
323-
if (label_pos_count.find(label) == label_pos_count.end()) {
324-
label_pos_count[label] = count;
328+
if (label_pos_count->find(label) == label_pos_count->end()) {
329+
(*label_pos_count)[label] = count;
325330
} else {
326-
label_pos_count[label] += count;
331+
(*label_pos_count)[label] += count;
327332
}
328333
}
329334
}
@@ -338,8 +343,8 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
338343
int label = it->first;
339344
for (size_t i = 0; i < pred_boxes.size(); ++i) {
340345
auto score = pred_boxes[i].first;
341-
true_pos[label].push_back(std::make_pair(score, 0));
342-
false_pos[label].push_back(std::make_pair(score, 1));
346+
(*true_pos)[label].push_back(std::make_pair(score, 0));
347+
(*false_pos)[label].push_back(std::make_pair(score, 1));
343348
}
344349
}
345350
continue;
@@ -351,8 +356,8 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
351356
if (image_gt_boxes.find(label) == image_gt_boxes.end()) {
352357
for (size_t i = 0; i < pred_boxes.size(); ++i) {
353358
auto score = pred_boxes[i].first;
354-
true_pos[label].push_back(std::make_pair(score, 0));
355-
false_pos[label].push_back(std::make_pair(score, 1));
359+
(*true_pos)[label].push_back(std::make_pair(score, 0));
360+
(*false_pos)[label].push_back(std::make_pair(score, 1));
356361
}
357362
continue;
358363
}
@@ -381,17 +386,17 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
381386
(!evaluate_difficult && !matched_bboxes[max_idx].is_difficult);
382387
if (match_evaluate_difficult) {
383388
if (!visited[max_idx]) {
384-
true_pos[label].push_back(std::make_pair(score, 1));
385-
false_pos[label].push_back(std::make_pair(score, 0));
389+
(*true_pos)[label].push_back(std::make_pair(score, 1));
390+
(*false_pos)[label].push_back(std::make_pair(score, 0));
386391
visited[max_idx] = true;
387392
} else {
388-
true_pos[label].push_back(std::make_pair(score, 0));
389-
false_pos[label].push_back(std::make_pair(score, 1));
393+
(*true_pos)[label].push_back(std::make_pair(score, 0));
394+
(*false_pos)[label].push_back(std::make_pair(score, 1));
390395
}
391396
}
392397
} else {
393-
true_pos[label].push_back(std::make_pair(score, 0));
394-
false_pos[label].push_back(std::make_pair(score, 1));
398+
(*true_pos)[label].push_back(std::make_pair(score, 0));
399+
(*false_pos)[label].push_back(std::make_pair(score, 1));
395400
}
396401
}
397402
}

paddle/fluid/operators/edit_distance_op.cu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ limitations under the License. */
1414

1515
#include <algorithm>
1616
#include "paddle/fluid/framework/op_registry.h"
17+
#include "paddle/fluid/operators/edit_distance_op.h"
1718
#include "paddle/fluid/operators/math/math_function.h"
1819
#include "paddle/fluid/platform/cuda_helper.h"
1920
#include "paddle/fluid/platform/gpu_info.h"

0 commit comments

Comments
 (0)