Path: blob/master/site/en-snapshot/tutorials/quickstart/advanced.ipynb
25118 views
Copyright 2019 The TensorFlow Authors.
TensorFlow 2 quickstart for experts
This is a Google Colaboratory notebook file. Python programs are run directly in the browser—a great way to learn and use TensorFlow. To follow this tutorial, run the notebook in Google Colab by clicking the button at the top of this page.
In Colab, connect to a Python runtime: At the top-right of the menu bar, select CONNECT.
Run all the notebook code cells: Select Runtime > Run all.
Download and install TensorFlow 2. Import TensorFlow into your program:
Note: Upgrade pip
to install the TensorFlow 2 package. See the install guide for details.
Import TensorFlow into your program:
Load and prepare the MNIST dataset.
Use tf.data
to batch and shuffle the dataset:
Build the tf.keras
model using the Keras model subclassing API:
Choose an optimizer and loss function for training:
Select metrics to measure the loss and the accuracy of the model. These metrics accumulate the values over epochs and then print the overall result.
Use tf.GradientTape
to train the model:
Test the model:
The image classifier is now trained to ~98% accuracy on this dataset. To learn more, read the TensorFlow tutorials.