@@ -144,6 +144,15 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
144144 }
145145 }
146146
147+ inline void ClipBBox (const Box& bbox, Box* clipped_bbox) const {
148+ T one = static_cast <T>(1.0 );
149+ T zero = static_cast <T>(0.0 );
150+ clipped_bbox->xmin = std::max (std::min (bbox.xmin , one), zero);
151+ clipped_bbox->ymin = std::max (std::min (bbox.ymin , one), zero);
152+ clipped_bbox->xmax = std::max (std::min (bbox.xmax , one), zero);
153+ clipped_bbox->ymax = std::max (std::min (bbox.ymax , one), zero);
154+ }
155+
147156 void GetBoxes (const framework::LoDTensor& input_label,
148157 const framework::LoDTensor& input_detect,
149158 std::vector<std::map<int , std::vector<Box>>>& gt_boxes,
@@ -360,7 +369,9 @@ class DetectionMAPOpKernel : public framework::OpKernel<T> {
360369 size_t max_idx = 0 ;
361370 auto score = pred_boxes[i].first ;
362371 for (size_t j = 0 ; j < matched_bboxes.size (); ++j) {
363- T overlap = JaccardOverlap (pred_boxes[i].second , matched_bboxes[j]);
372+ Box& pred_box = pred_boxes[i].second ;
373+ ClipBBox (pred_box, &pred_box);
374+ T overlap = JaccardOverlap (pred_box, matched_bboxes[j]);
364375 if (overlap > max_overlap) {
365376 max_overlap = overlap;
366377 max_idx = j;
0 commit comments