Learning without Forgetting (LwF) trains a new task with the usual cross-entropy while forcing the network's old outputs on the new inputs to stay close to what they were before training started. The old outputs are recorded once, with a forward pass of the frozen original network, so no old data is stored. Implement the loss on logits.
softmax(z, T=1.0)
z is (N, C); return the row-wise softmax of z / T, computed stably.distillation_loss(old_logits_recorded, old_logits_current, T=2.0)
(N, C_old). Targets are the recorded logits softened at temperature T; predictions are the current old-head logits at the same temperature. Return the mean over samples of the cross-entropy , multiplied by (the standard scaling so the gradient magnitude does not shrink with T), as a Python float.lwf_loss(new_logits, labels, old_logits_recorded, old_logits_current, T=2.0, alpha=1.0, decimals=6)
new_logits is (N, C_new), labels an (N,) integer array; the cross-entropy on the new head is the mean of ."ce", "distill", "total" (ce + alpha * distill), rounded to decimals.log(softmax).