Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano. This article is about summary and tips on Keras.

Simple Example

The core data structure of Keras is a model, a way to organize layers. The simplest type of model is the Sequential model, a linear stack of layers. For more complex architectures, you should use the Keras functional API, which allows to build arbitrary graphs of layers.

from keras.models import Sequential, Dense

# Construct `Sequential` model
model = Sequential()

# Stacking layers by `.add()`
model.add(Dense(units=64, activation='relu', input_dim=100))
model.add(Dense(units=10, activation='softmax'))

# Configure its learning process with `.compile()`
# Iterate on the training data in batches, y_train, epochs=5, batch_size=32)

# Alternatively, you can feed batches to your model manually:
model.train_on_batch(x_batch, y_batch)

# Evaluate performance:
loss_and_metrics = model.evaluate(x_test, y_test, batch_size=128)

# Generate predictions on new data:
classes = model.predict(x_test, batch_size=128)


  • Web: Keras Documentation [Link]