def distill(pairs, weight): """ Add 3 pairs of distillation losses, each pair of feature maps is the input of teacher and student's yolov3_loss respectively """ loss = l2_loss(pairs[0][0], pairs[0][1]) weighted_loss = loss * weight return weighted_loss
def l2_distill(pairs, weight): """ Add l2 distillation losses composed of multi pairs of feature maps, each pair of feature maps is the input of teacher and student's yolov3_loss respectively """ loss = [] for pair in pairs: loss.append(l2_loss(pair[0], pair[1])) loss = fluid.layers.sum(loss) weighted_loss = loss * weight return weighted_loss