TensorFlow: Difference between revisions

Line 21: Line 21:
This is using the Keras API in tensorflow.keras.
This is using the Keras API in tensorflow.keras.
===Basics===
===Basics===
===Training Loop===
The general pipeline using Keras is:
* Define a model, typically using [https://www.tensorflow.org/api_docs/python/tf/keras/Sequential tf.keras.Sequential]
* Call [https://www.tensorflow.org/api_docs/python/tf/keras/Model#compile <code>model.compile</code>]
** Here you pass in your optimizer, loss function, metrics, and training callbacks.
* Train your model by calling <code>model.fit</code>
** Here you pass in your training data and some hyperparameters: number of epochs
 
After training, you can use your model by calling <code>model.evaluate</code>
 
 
 
===Custom Models===
An alternative way to define a model is by extending the Model class:
 
* Write a python class which extends <code>tf.keras.Model</code>
* Implement a forward pass in the <code>call</code> method
 
 
===Custom Training Loop===
[https://www.tensorflow.org/guide/keras/train_and_evaluate#part_ii_writing_your_own_training_evaluation_loops_from_scratch Reference]<br>
[https://www.tensorflow.org/guide/keras/train_and_evaluate#part_ii_writing_your_own_training_evaluation_loops_from_scratch Reference]<br>
While you can train using <code>model.compile</code> and <code>model.fit</code>, using your own custom training loop is much more flexable and easier to understand.
While you can train using <code>model.compile</code> and <code>model.fit</code>, using your own custom training loop is much more flexable and easier to understand.