Here’s an interesting article on creating and using custom loss functions in Keras. Why would you need to do this?
Here’s one example from the article:
Let’s say you are designing a Variational Autoencoder. You want your model to be able to reconstruct its inputs from the encoded latent space. However, you also want your encoding in the latent space to be (approximately) normally distributed.