Keras: The high-level API for TensorFlow (original) (raw)

Keras: The high-level API for TensorFlow

Stay organized with collections Save and categorize content based on your preferences.

Keras is the high-level API of the TensorFlow platform. It provides an approachable, highly-productive interface for solving machine learning (ML) problems, with a focus on modern deep learning. Keras covers every step of the machine learning workflow, from data processing to hyperparameter tuning to deployment. It was developed with a focus on enabling fast experimentation.

With Keras, you have full access to the scalability and cross-platform capabilities of TensorFlow. You can run Keras on a TPU Pod or large clusters of GPUs, and you can export Keras models to run in the browser or on mobile devices. You can also serve Keras models via a web API.

Keras is designed to reduce cognitive load by achieving the following goals:

Who should use Keras

The short answer is that every TensorFlow user should use the Keras APIs by default. Whether you're an engineer, a researcher, or an ML practitioner, you should start with Keras.

There are a few use cases (for example, building tools on top of TensorFlow or developing your own high-performance platform) that require the low-levelTensorFlow Core APIs. But if your use case doesn't fall into one of theCore API applications, you should prefer Keras.

Keras API components

The core data structures of Keras are layers andmodels. A layer is a simple input/output transformation, and a model is a directed acyclic graph (DAG) of layers.

Layers

The tf.keras.layers.Layer class is the fundamental abstraction in Keras. ALayer encapsulates a state (weights) and some computation (defined in thetf.keras.layers.Layer.call method).

Weights created by layers can be trainable or non-trainable. Layers are recursively composable: If you assign a layer instance as an attribute of another layer, the outer layer will start tracking the weights created by the inner layer.

You can also use layers to handle data preprocessing tasks like normalization and text vectorization. Preprocessing layers can be included directly into a model, either during or after training, which makes the model portable.

Models

A model is an object that groups layers together and that can be trained on data.

The simplest type of model is theSequential model, which is a linear stack of layers. For more complex architectures, you can either use theKeras functional API, which lets you build arbitrary graphs of layers, oruse subclassing to write models from scratch.

The tf.keras.Model class features built-in training and evaluation methods:

These methods give you access to the following built-in training features:

For a detailed overview of how to use fit, see thetraining and evaluation guide. To learn how to customize the built-in training and evaluation loops, seeCustomizing what happens in fit().

Other APIs and tools

Keras provides many other APIs and tools for deep learning, including:

For a full list of available APIs, see theKeras API reference. To learn more about other Keras projects and initiatives, seeThe Keras ecosystem.

Next steps

To get started using Keras with TensorFlow, check out the following topics:

To learn more about Keras, see the following topics atkeras.io: