Welcome to the getting started guide for Keras, the high-level neural networks API, written in Python and capable of running on top of TensorFlow.

Keras is designed to enable fast experimentation with deep neural networks. It focuses on being user-friendly, modular, and extensible.

Quick Start

Here's a quick overview of how to start using Keras:

  • Install TensorFlow: Make sure you have TensorFlow installed. You can install it using pip:

    pip install tensorflow
    
  • Import Keras: Import Keras in your Python script:

    from keras import layers, models
    
  • Build a Model: Define your model using Keras layers:

    model = models.Sequential()
    model.add(layers.Dense(64, activation='relu', input_shape=(784,)))
    model.add(layers.Dense(10, activation='softmax'))
    
  • Compile the Model: Compile your model with an optimizer, a loss function, and metrics:

    model.compile(optimizer='adam',
                  loss='categorical_crossentropy',
                  metrics=['accuracy'])
    
  • Train the Model: Train your model on your data:

    model.fit(x_train, y_train, epochs=5)
    
  • Evaluate the Model: Evaluate your model on new data:

    model.evaluate(x_test, y_test)
    
  • Save the Model: Save your trained model for later use:

    model.save('my_model.h5')
    

For more detailed information and examples, please visit the Keras documentation.

Keras Layers

Keras provides a variety of layers for building neural networks, including:

  • Dense: Fully connected layer.
  • Conv2D: Convolutional layer for 2D data (images).
  • MaxPooling2D: Max pooling layer for 2D data.
  • Flatten: Flatten layer to convert a 2D tensor into a 1D tensor.
  • Dropout: Dropout layer to prevent overfitting.

For a complete list of layers, please refer to the Keras layers documentation.

Keras Models

Keras provides two types of models: Sequential and Functional.

  • Sequential: A linear stack of layers. It is the simplest and most common type of model.
  • Functional: A more flexible model that allows for complex architectures and custom layers.

For more information on models, please visit the Keras models documentation.

Keras Backend

Keras can run on top of different backends, including TensorFlow, Theano, and CNTK. The default backend is TensorFlow.

For more information on backends, please visit the [Keras backend documentation](/community/tensorflow/keras/docs/en/stable/behind_the scenes/).

Neural Network