polish the label_smooth (#17138)

* polish the label_smooth

test=develop

* polish code

test=develop
feature/fluid_trt_int8
xiaoting 6 years ago committed by Kaipeng Deng
parent bf4b21fa3d
commit bc48453b73

@ -282,8 +282,9 @@ class Yolov3LossKernel : public framework::OpKernel<T> {
T label_pos = 1.0;
T label_neg = 0.0;
if (use_label_smooth) {
label_pos = 1.0 - 1.0 / static_cast<T>(class_num);
label_neg = 1.0 / static_cast<T>(class_num);
T smooth_weight = std::min(1.0 / static_cast<T>(class_num), 1.0 / 40);
label_pos = 1.0 - smooth_weight;
label_neg = smooth_weight;
}
const T* input_data = input->data<T>();
@ -437,8 +438,9 @@ class Yolov3LossGradKernel : public framework::OpKernel<T> {
T label_pos = 1.0;
T label_neg = 0.0;
if (use_label_smooth) {
label_pos = 1.0 - 1.0 / static_cast<T>(class_num);
label_neg = 1.0 / static_cast<T>(class_num);
T smooth_weight = std::min(1.0 / static_cast<T>(class_num), 1.0 / 40);
label_pos = 1.0 - smooth_weight;
label_neg = smooth_weight;
}
const T* input_data = input->data<T>();

@ -81,8 +81,9 @@ def YOLOv3Loss(x, gtbox, gtlabel, gtscore, attrs):
x = x.reshape((n, mask_num, 5 + class_num, h, w)).transpose((0, 1, 3, 4, 2))
loss = np.zeros((n)).astype('float32')
label_pos = 1.0 - 1.0 / class_num if use_label_smooth else 1.0
label_neg = 1.0 / class_num if use_label_smooth else 0.0
smooth_weight = min(1.0 / class_num, 1.0 / 40)
label_pos = 1.0 - smooth_weight if use_label_smooth else 1.0
label_neg = smooth_weight if use_label_smooth else 0.0
pred_box = x[:, :, :, :, :4].copy()
grid_x = np.tile(np.arange(w).reshape((1, w)), (h, 1))

Loading…
Cancel
Save