Search code examples
deep-learningkerasautoencoder

Keras - epoch dependant loss function


I'm working with the Keras framework and I would like to implement an epoch dependent loss function (i.e the loss function isn't the same at each epoch)

How would you do that ? Can you add an example, for instance based on the keras VAE tutorial ?

Thank you for your help


Solution

  • This can be accomplished by recompiling the network. The weights are saved not changed by the recompilation. So in essence something like this:

    for epoch in range(nb_epoch):
         loss_function = loss_for_epoch(epoch)
         model.compile(optimizer, loss_function, metrics)
         model.fit(X, y, nb_epoch=1)