|
| 1 | +# Keras: The high-level API for TensorFlow |
| 2 | + |
| 3 | +Keras is the high-level API of the TensorFlow platform. It provides an |
| 4 | +approachable, highly-productive interface for solving machine learning (ML) |
| 5 | +problems, with a focus on modern deep learning. Keras covers every step of the |
| 6 | +machine learning workflow, from data processing to hyperparameter tuning to |
| 7 | +deployment. It was developed with a focus on enabling fast experimentation. |
| 8 | + |
| 9 | +With Keras, you have full access to the scalability and cross-platform |
| 10 | +capabilities of TensorFlow. You can run Keras on a TPU Pod or large clusters of |
| 11 | +GPUs, and you can export Keras models to run in the browser or on mobile |
| 12 | +devices. You can also serve Keras models via a web API. |
| 13 | + |
| 14 | +Keras is designed to reduce cognitive load by achieving the following goals: |
| 15 | + |
| 16 | +* Offer simple, consistent interfaces. |
| 17 | +* Minimize the number of actions required for common use cases. |
| 18 | +* Provide clear, actionable error messages. |
| 19 | +* Follow the principle of progressive disclosure of complexity: It's easy to get |
| 20 | + started, and you can complete advanced workflows by learning as you go. |
| 21 | +* Help you write concise, readable code. |
| 22 | + |
| 23 | +## Who should use Keras |
| 24 | + |
| 25 | +The short answer is that every TensorFlow user should use the Keras APIs by |
| 26 | +default. Whether you're an engineer, a researcher, or an ML practitioner, you |
| 27 | +should start with Keras. |
| 28 | + |
| 29 | +There are a few use cases (for example, building tools on top of TensorFlow or |
| 30 | +developing your own high-performance platform) that require the low-level |
| 31 | +[TensorFlow Core APIs](https://www.tensorflow.org/guide/core). But if your use |
| 32 | +case doesn't fall into one |
| 33 | +of the |
| 34 | +[Core API applications](https://www.tensorflow.org/guide/core#core_api_applications), |
| 35 | +you should prefer Keras. |
| 36 | + |
| 37 | +## Keras API components |
| 38 | + |
| 39 | +The core data structures of Keras are [layers](https://keras.io/api/layers/) and |
| 40 | +[models](https://keras.io/api/models/). A layer is a simple input/output |
| 41 | +transformation, and a model is a directed acyclic graph (DAG) of layers. |
| 42 | + |
| 43 | +### Layers |
| 44 | + |
| 45 | +The `tf.keras.layers.Layer` class is the fundamental abstraction in Keras. A |
| 46 | +`Layer` encapsulates a state (weights) and some computation (defined in the |
| 47 | +`tf.keras.layers.Layer.call` method). |
| 48 | + |
| 49 | +Weights created by layers can be trainable or non-trainable. Layers are |
| 50 | +recursively composable: If you assign a layer instance as an attribute of |
| 51 | +another layer, the outer layer will start tracking the weights created by the |
| 52 | +inner layer. |
| 53 | + |
| 54 | +You can also use layers to handle data preprocessing tasks like normalization |
| 55 | +and text vectorization. Preprocessing layers can be included directly into a |
| 56 | +model, either during or after training, which makes the model portable. |
| 57 | + |
| 58 | +### Models |
| 59 | + |
| 60 | +A model is an object that groups layers together and that can be trained on |
| 61 | +data. |
| 62 | + |
| 63 | +The simplest type of model is the |
| 64 | +[`Sequential` model](https://www.tensorflow.org/guide/keras/sequential_model), |
| 65 | +which is a linear stack of layers. For more complex architectures, you can |
| 66 | +either use the |
| 67 | +[Keras functional API](https://www.tensorflow.org/guide/keras/functional_api), |
| 68 | +which lets you build arbitrary graphs of layers, or |
| 69 | +[use subclassing to write models from scratch](https://www.tensorflow.org/guide/keras/making_new_layers_and_models_via_subclassing). |
| 70 | + |
| 71 | +The `tf.keras.Model` class features built-in training and evaluation methods: |
| 72 | + |
| 73 | +* `tf.keras.Model.fit`: Trains the model for a fixed number of epochs. |
| 74 | +* `tf.keras.Model.predict`: Generates output predictions for the input samples. |
| 75 | +* `tf.keras.Model.evaluate`: Returns the loss and metrics values for the model; |
| 76 | + configured via the `tf.keras.Model.compile` method. |
| 77 | + |
| 78 | +These methods give you access to the following built-in training features: |
| 79 | + |
| 80 | +* [Callbacks](https://www.tensorflow.org/api_docs/python/tf/keras/callbacks). |
| 81 | + You can leverage built-in callbacks for early stopping, model checkpointing, |
| 82 | + and [TensorBoard](https://www.tensorflow.org/tensorboard) monitoring. You can |
| 83 | + also |
| 84 | + [implement custom callbacks](https://www.tensorflow.org/guide/keras/writing_your_own_callbacks). |
| 85 | +* [Distributed training](https://www.tensorflow.org/guide/keras/distributed_training). |
| 86 | + You can easily scale up your training to multiple GPUs, TPUs, or devices. |
| 87 | +* Step fusing. With the `steps_per_execution` argument in |
| 88 | + `tf.keras.Model.compile`, you can process multiple batches in a single |
| 89 | + `tf.function` call, which greatly improves device utilization on TPUs. |
| 90 | + |
| 91 | +For a detailed overview of how to use `fit`, see the |
| 92 | +[training and evaluation guide](https://www.tensorflow.org/guide/keras/training_with_built_in_methods). |
| 93 | +To learn how to customize the built-in training and evaluation loops, see |
| 94 | +[Customizing what happens in `fit()`](https://www.tensorflow.org/guide/keras/customizing_what_happens_in_fit). |
| 95 | + |
| 96 | +### Other APIs and tools |
| 97 | + |
| 98 | +Keras provides many other APIs and tools for deep learning, including: |
| 99 | + |
| 100 | +* [Optimizers](https://keras.io/api/optimizers/) |
| 101 | +* [Metrics](https://keras.io/api/metrics/) |
| 102 | +* [Losses](https://keras.io/api/losses/) |
| 103 | +* [Data loading utilities](https://keras.io/api/data_loading/) |
| 104 | + |
| 105 | +For a full list of available APIs, see the |
| 106 | +[Keras API reference](https://keras.io/api/). To learn more about other Keras |
| 107 | +projects and initiatives, see |
| 108 | +[The Keras ecosystem](https://keras.io/getting_started/ecosystem/). |
| 109 | + |
| 110 | +## Next steps |
| 111 | + |
| 112 | +To get started using Keras with TensorFlow, check out the following topics: |
| 113 | + |
| 114 | +* [The Sequential model](https://www.tensorflow.org/guide/keras/sequential_model) |
| 115 | +* [The Functional API](https://www.tensorflow.org/guide/keras/functional) |
| 116 | +* [Training & evaluation with the built-in methods](https://www.tensorflow.org/guide/keras/training_with_built_in_methods) |
| 117 | +* [Making new layers and models via subclassing](https://www.tensorflow.org/guide/keras/custom_layers_and_models) |
| 118 | +* [Serialization and saving](https://www.tensorflow.org/guide/keras/save_and_serialize) |
| 119 | +* [Working with preprocessing layers](https://www.tensorflow.org/guide/keras/preprocessing_layers) |
| 120 | +* [Customizing what happens in fit()](https://www.tensorflow.org/guide/keras/customizing_what_happens_in_fit) |
| 121 | +* [Writing a training loop from scratch](https://www.tensorflow.org/guide/keras/writing_a_training_loop_from_scratch) |
| 122 | +* [Working with RNNs](https://www.tensorflow.org/guide/keras/rnn) |
| 123 | +* [Understanding masking & padding](https://www.tensorflow.org/guide/keras/masking_and_padding) |
| 124 | +* [Writing your own callbacks](https://www.tensorflow.org/guide/keras/custom_callback) |
| 125 | +* [Transfer learning & fine-tuning](https://www.tensorflow.org/guide/keras/transfer_learning) |
| 126 | +* [Multi-GPU and distributed training](https://www.tensorflow.org/guide/keras/distributed_training) |
| 127 | + |
| 128 | +To learn more about Keras, see the following topics at |
| 129 | +[keras.io](http://keras.io): |
| 130 | + |
| 131 | +* [About Keras](https://keras.io/about/) |
| 132 | +* [Introduction to Keras for Engineers](https://keras.io/getting_started/intro_to_keras_for_engineers/) |
| 133 | +* [Introduction to Keras for Researchers](https://keras.io/getting_started/intro_to_keras_for_researchers/) |
| 134 | +* [Keras API reference](https://keras.io/api/) |
| 135 | +* [The Keras ecosystem](https://keras.io/getting_started/ecosystem/) |
0 commit comments