François Chollet @fchollet Deep learning @google. Creator of Keras, neural networks library. Author of 'Deep Learning with Python'. Opinions are my own. May. 24, 2019 1 min read

When you're using tf.keras in TensorFlow 2.0, training your models with `fit` is one option, but you can also write a custom training loop. It takes about 10 lines.

If your model creates additional losses during its forward pass (i.e. if you called `self.add_loss` in a custom layer), collect them in one line like this.

The advantage of using `fit` is that it packs a lot of functionality in a convenient interface: a progress bar, easy reporting of metrics such as precision & recall, easy management of class weights for imbalanced classification, callbacks for model checkpointing and more...

You can follow @fchollet.


Tip: mention @threader_app on a Twitter thread with the keyword “compile” to get a link to it.

Enjoy Threader? Sign up.

Threader is an independent project created by only two developers. The site gets 500,000+ visits a month and our iOS Twitter client was featured as an App of the Day by Apple. Running this space is expensive and time consuming. If you find Threader useful, please consider supporting us to make it a sustainable project.