title: Custom loss function in Keras
body: <p>I'm working on a image class-incremental classifier approach using a CNN as a feature extractor and a fully-connected block for classifying.</p>
  
  <p>First, I did a fine-tuning of a VGG per-trained network to do a new task. Once the net is trained for the new task, i store some examples for every class in order to avoid forgetting when new classes are available.</p>
  
  <p>When some classes are available, i have to compute every output of the exemplars included the exemplars for the new classes. Now adding zeros to the outputs for old classes and adding the label corresponding to each new class on the new classes outputs i have my new labels, i.e:
  if 3 new classes enter....</p>
  
  <p>Old class type output: <code>[0.1, 0.05, 0.79, ..., 0 0 0]</code></p>
  
  <p>New class type output: <code>[0.1, 0.09, 0.3, 0.4, ..., 1 0 0]</code> **the last outputs correspond to the class.</p>
  
  <p>My question is, how i can change the loss function for a custom one to train for the new classes?
  The loss function that i want to implement is defined as:</p>
  
  <p><a href="https://i.stack.imgur.com/0kImf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0kImf.png" alt="loss function"></a></p>
  
  <p>where distillation loss corresponds to the outputs for old classes to avoid forgetting, and classification loss corresponds to the new classes.</p>
  
  <p>If you can provide me a sample of code to change the loss function in keras would be nice.</p>
  
  <p>Thanks!!!!!</p>