Skip to content

Commit e083f14

Browse files
authored
soft_label_distiller fix, test=release/1.6 (#20657)
1 parent c054adf commit e083f14

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

python/paddle/fluid/contrib/slim/distillation/distiller.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,14 @@ def apply(self, graph):
264264

265265
student_feature_map = ret_graph.var(self.student_feature_map)._var
266266
teacher_feature_map = ret_graph.var(self.teacher_feature_map)._var
267-
s_fea = student_feature_map / self.student_temperature
268-
t_fea = teacher_feature_map / self.teacher_temperature
267+
s_fea = layers.softmax(student_feature_map /
268+
self.student_temperature)
269+
t_fea = layers.softmax(teacher_feature_map /
270+
self.teacher_temperature)
269271
t_fea.stop_gradient = True
270-
ce_loss = layers.softmax_with_cross_entropy(
271-
s_fea, t_fea, soft_label=True)
272+
ce_loss = layres.reduce_mean(
273+
layers.cross_entropy(
274+
s_fea, t_fea, soft_label=True))
272275
distillation_loss = ce_loss * self.distillation_loss_weight
273276
student_loss = 0
274277
if 'loss' in ret_graph.out_nodes:

0 commit comments

Comments
 (0)