Skip to content

Commit 56e21c5

Browse files
committed
add comments and docs. test=develop
1 parent 577424e commit 56e21c5

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

paddle/fluid/operators/yolov3_loss_op.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Yolov3LossOpMaker : public framework::OpProtoAndCheckerMaker {
9898
"This is a 4-D tensor with shape of [N, C, H, W]."
9999
"H and W should be same, and the second dimention(C) stores"
100100
"box locations, confidence score and classification one-hot"
101-
"key of each anchor box");
101+
"keys of each anchor box");
102102
AddInput("GTBox",
103103
"The input tensor of ground truth boxes, "
104104
"This is a 3-D tensor with shape of [N, max_box_num, 5], "
@@ -179,6 +179,11 @@ class Yolov3LossOpMaker : public framework::OpProtoAndCheckerMaker {
179179
box coordinates (w, h), and sigmoid cross entropy loss is used for box
180180
coordinates (x, y), confidence score loss and classification loss.
181181
182+
Each groud truth box find a best matching anchor box in all anchors,
183+
prediction of this anchor box will incur all three parts of losses, and
184+
prediction of anchor boxes with no GT box matched will only incur objectness
185+
loss.
186+
182187
In order to trade off box coordinate losses between big boxes and small
183188
boxes, box coordinate losses will be mutiplied by scale weight, which is
184189
calculated as follow.

paddle/fluid/operators/yolov3_loss_op.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,15 @@ class Yolov3LossKernel : public framework::OpKernel<T> {
308308
}
309309
}
310310

311+
// If best IoU is greater then ignore_thresh,
312+
// ignore the objectness loss.
311313
if (best_iou > ignore_thresh) {
312314
int obj_idx = (i * mask_num + j) * stride + k * w + l;
313315
obj_mask_data[obj_idx] = static_cast<T>(-1);
314316
}
315-
// TODO(dengkaipeng): all losses should be calculated if best IoU
316-
// is bigger then truth thresh should be calculated here, but
317-
// currently, truth thresh is an unreachable value as 1.0.
317+
// all losses should be calculated if best IoU
318+
// is bigger then truth thresh, but currently,
319+
// truth thresh is an unreachable value as 1.0.
318320
}
319321
}
320322
}
@@ -341,8 +343,6 @@ class Yolov3LossKernel : public framework::OpKernel<T> {
341343
an_box.w = anchors[2 * an_idx] / static_cast<T>(input_size);
342344
an_box.h = anchors[2 * an_idx + 1] / static_cast<T>(input_size);
343345
float iou = CalcBoxIoU<T>(an_box, gt_shift);
344-
// TODO(dengkaipeng): In paper, objectness loss is ignore when
345-
// best IoU > 0.5, but darknet code didn't implement this.
346346
if (iou > best_iou) {
347347
best_iou = iou;
348348
best_n = an_idx;

0 commit comments

Comments
 (0)