Function Reference

Keras Models

keras_model

Keras Model

keras_model_sequential

Keras Model composed of a linear stack of layers

multi_gpu_model

Replicates a model on different GPUs.

summary

Print a summary of a Keras model

compile

Configure a Keras model for training

fit

Train a Keras model

fit_generator

Fits the model on data yielded batch-by-batch by a generator.

evaluate_generator

Evaluates the model on a data generator.

predict

Generate predictions from a Keras model

predict_proba predict_classes

Generates probability or class probability predictions for the input samples.

predict_on_batch

Returns predictions for a single batch of samples.

predict_generator

Generates predictions for the input samples from a data generator.

train_on_batch test_on_batch

Single gradient update or model evaluation over one batch of samples.

get_layer

Retrieves a layer based on either its name (unique) or index.

pop_layer

Remove the last layer in a model

save_model_hdf5 load_model_hdf5

Save/Load models using HDF5 files

serialize_model unserialize_model

Serialize a model to an R object

clone_model

Clone a model instance.

freeze_weights unfreeze_weights

Freeze and unfreeze weights

Core Layers

layer_input

Input layer

layer_dense

Add a densely-connected NN layer to an output

layer_activation

Apply an activation function to an output.

layer_dropout

Applies Dropout to the input.

layer_reshape

Reshapes an output to a certain shape.

layer_permute

Permute the dimensions of an input according to a given pattern

layer_repeat_vector

Repeats the input n times.

layer_lambda

Wraps arbitrary expression as a layer

layer_activity_regularization

Layer that applies an update to the cost function based input activity.

layer_masking

Masks a sequence by using a mask value to skip timesteps.

layer_flatten

Flattens an input

Convolutional Layers

layer_conv_1d

1D convolution layer (e.g. temporal convolution).

layer_conv_2d_transpose

Transposed 2D convolution layer (sometimes called Deconvolution).

layer_conv_2d

2D convolution layer (e.g. spatial convolution over images).

layer_conv_3d_transpose

Transposed 3D convolution layer (sometimes called Deconvolution).

layer_conv_3d

3D convolution layer (e.g. spatial convolution over volumes).

layer_conv_lstm_2d

Convolutional LSTM.

layer_separable_conv_2d

Depthwise separable 2D convolution.

layer_upsampling_1d

Upsampling layer for 1D inputs.

layer_upsampling_2d

Upsampling layer for 2D inputs.

layer_upsampling_3d

Upsampling layer for 3D inputs.

layer_zero_padding_1d

Zero-padding layer for 1D input (e.g. temporal sequence).

layer_zero_padding_2d

Zero-padding layer for 2D input (e.g. picture).

layer_zero_padding_3d

Zero-padding layer for 3D data (spatial or spatio-temporal).

layer_cropping_1d

Cropping layer for 1D input (e.g. temporal sequence).

layer_cropping_2d

Cropping layer for 2D input (e.g. picture).

layer_cropping_3d

Cropping layer for 3D data (e.g. spatial or spatio-temporal).

Pooling Layers

layer_max_pooling_1d

Max pooling operation for temporal data.

layer_max_pooling_2d

Max pooling operation for spatial data.

layer_max_pooling_3d

Max pooling operation for 3D data (spatial or spatio-temporal).

layer_average_pooling_1d

Average pooling for temporal data.

layer_average_pooling_2d

Average pooling operation for spatial data.

layer_average_pooling_3d

Average pooling operation for 3D data (spatial or spatio-temporal).

layer_global_max_pooling_1d

Global max pooling operation for temporal data.

layer_global_average_pooling_1d

Global average pooling operation for temporal data.

layer_global_max_pooling_2d

Global max pooling operation for spatial data.

layer_global_average_pooling_2d

Global average pooling operation for spatial data.

layer_global_max_pooling_3d

Global Max pooling operation for 3D data.

layer_global_average_pooling_3d

Global Average pooling operation for 3D data.

Activation Layers

layer_activation

Apply an activation function to an output.

layer_activation_leaky_relu

Leaky version of a Rectified Linear Unit.

layer_activation_parametric_relu

Parametric Rectified Linear Unit.

layer_activation_thresholded_relu

Thresholded Rectified Linear Unit.

layer_activation_elu

Exponential Linear Unit.

Dropout Layers

layer_dropout

Applies Dropout to the input.

layer_spatial_dropout_1d

Spatial 1D version of Dropout.

layer_spatial_dropout_2d

Spatial 2D version of Dropout.

layer_spatial_dropout_3d

Spatial 3D version of Dropout.

Locally-connected Layers

layer_locally_connected_1d

Locally-connected layer for 1D inputs.

layer_locally_connected_2d

Locally-connected layer for 2D inputs.

Recurrent Layers

layer_simple_rnn

Fully-connected RNN where the output is to be fed back to input.

layer_gru

Gated Recurrent Unit - Cho et al.

layer_cudnn_gru

Fast GRU implementation backed by CuDNN.

layer_lstm

Long-Short Term Memory unit - Hochreiter 1997.

Embedding Layers

layer_embedding

Turns positive integers (indexes) into dense vectors of fixed size.

Normalization Layers

layer_batch_normalization

Batch normalization layer (Ioffe and Szegedy, 2014).

Noise Layers

layer_gaussian_noise

Apply additive zero-centered Gaussian noise.

layer_gaussian_dropout

Apply multiplicative 1-centered Gaussian noise.

layer_alpha_dropout

Applies Alpha Dropout to the input.

Merge Layers

layer_add

Layer that adds a list of inputs.

layer_subtract

Layer that subtracts two inputs.

layer_multiply

Layer that multiplies (element-wise) a list of inputs.

layer_average

Layer that averages a list of inputs.

layer_maximum

Layer that computes the maximum (element-wise) a list of inputs.

layer_minimum

Layer that computes the minimum (element-wise) a list of inputs.

layer_concatenate

Layer that concatenates a list of inputs.

layer_dot

Layer that computes a dot product between samples in two tensors.

Layer Wrappers

time_distributed

Apply a layer to every temporal slice of an input.

bidirectional

Bidirectional wrapper for RNNs.

Layer Methods

get_config from_config

Layer/Model configuration

get_weights set_weights

Layer/Model weights as R arrays

get_input_at get_output_at get_input_shape_at get_output_shape_at get_input_mask_at get_output_mask_at

Retrieve tensors for layers with multiple nodes

count_params

Count the total number of scalars composing the weights.

reset_states

Reset the states for a layer

Custom Layers

KerasLayer

Base R6 class for Keras layers

create_layer

Create a Keras Layer

Model Persistence

save_model_hdf5 load_model_hdf5

Save/Load models using HDF5 files

save_model_weights_hdf5 load_model_weights_hdf5

Save/Load model weights using HDF5 files

serialize_model unserialize_model

Serialize a model to an R object

get_weights set_weights

Layer/Model weights as R arrays

get_config from_config

Layer/Model configuration

model_to_json model_from_json

Model configuration as JSON

model_to_yaml model_from_yaml

Model configuration as YAML

Datasets

dataset_cifar10

CIFAR10 small image classification

dataset_cifar100

CIFAR100 small image classification

dataset_imdb dataset_imdb_word_index

IMDB Movie reviews sentiment classification

dataset_reuters dataset_reuters_word_index

Reuters newswire topics classification

dataset_mnist

MNIST database of handwritten digits

dataset_boston_housing

Boston housing price regression dataset

Applications

application_xception xception_preprocess_input

Xception V1 model for Keras.

application_inception_v3 inception_v3_preprocess_input

Inception V3 model, with weights pre-trained on ImageNet.

application_vgg16 application_vgg19

VGG16 and VGG19 models for Keras.

application_resnet50

ResNet50 model for Keras.

application_mobilenet mobilenet_preprocess_input mobilenet_decode_predictions mobilenet_load_model_hdf5

MobileNet model architecture.

imagenet_preprocess_input

Preprocesses a tensor encoding a batch of images.

imagenet_decode_predictions

Decodes the prediction of an ImageNet model.

Sequence Preprocessing

pad_sequences

Pads each sequence to the same length (length of the longest sequence).

skipgrams

Generates skipgram word pairs.

make_sampling_table

Generates a word rank-based probabilistic sampling table.

Text Preprocessing

text_tokenizer

Text tokenization utility

fit_text_tokenizer

Update tokenizer internal vocabulary based on a list of texts or list of sequences.

save_text_tokenizer load_text_tokenizer

Save a text tokenizer to an external file

texts_to_sequences

Transform each text in texts in a sequence of integers.

texts_to_sequences_generator

Transforms each text in texts in a sequence of integers.

texts_to_matrix

Convert a list of texts to a matrix.

sequences_to_matrix

Convert a list of sequences into a matrix.

text_one_hot

One-hot encode a text into a list of word indexes in a vocabulary of size n.

text_hashing_trick

Converts a text to a sequence of indexes in a fixed-size hashing space.

text_to_word_sequence

Convert text to a sequence of words (or tokens).

Image Preprocessing

image_load

Loads an image into PIL format.

image_to_array

Converts a PIL Image instance to a 3d-array.

image_data_generator

Generate minibatches of image data with real-time data augmentation.

fit_image_data_generator

Fit image data generator internal statistics to some sample data.

flow_images_from_data

Generates batches of augmented/normalized data from image data and labels

flow_images_from_directory

Generates batches of data from images in a directory (with optional augmented/normalized data)

generator_next

Retreive the next item from a generator

Optimizers

optimizer_sgd

Stochastic gradient descent optimizer

optimizer_rmsprop

RMSProp optimizer

optimizer_adagrad

Adagrad optimizer.

optimizer_adadelta

Adadelta optimizer.

optimizer_adam

Adam optimizer

optimizer_adamax

Adamax optimizer

optimizer_nadam

Nesterov Adam optimizer

Callbacks

callback_progbar_logger

Callback that prints metrics to stdout.

callback_model_checkpoint

Save the model after every epoch.

callback_early_stopping

Stop training when a monitored quantity has stopped improving.

callback_remote_monitor

Callback used to stream events to a server.

callback_learning_rate_scheduler

Learning rate scheduler.

callback_tensorboard

TensorBoard basic visualizations

callback_reduce_lr_on_plateau

Reduce learning rate when a metric has stopped improving.

callback_terminate_on_naan

Callback that terminates training when a NaN loss is encountered.

callback_csv_logger

Callback that streams epoch results to a csv file

callback_lambda

Create a custom callback

KerasCallback

Base R6 class for Keras callbacks

Initializers

initializer_zeros

Initializer that generates tensors initialized to 0.

initializer_ones

Initializer that generates tensors initialized to 1.

initializer_constant

Initializer that generates tensors initialized to a constant value.

initializer_random_normal

Initializer that generates tensors with a normal distribution.

initializer_random_uniform

Initializer that generates tensors with a uniform distribution.

initializer_truncated_normal

Initializer that generates a truncated normal distribution.

initializer_variance_scaling

Initializer capable of adapting its scale to the shape of weights.

initializer_orthogonal

Initializer that generates a random orthogonal matrix.

initializer_identity

Initializer that generates the identity matrix.

initializer_glorot_normal

Glorot normal initializer, also called Xavier normal initializer.

initializer_glorot_uniform

Glorot uniform initializer, also called Xavier uniform initializer.

initializer_he_normal

He normal initializer.

initializer_he_uniform

He uniform variance scaling initializer.

initializer_lecun_uniform

LeCun uniform initializer.

initializer_lecun_normal

LeCun normal initializer.

Constraints

constraint_maxnorm

MaxNorm weight constraint

constraint_nonneg

NonNeg weight constraint

constraint_unitnorm

UnitNorm weight constraint

constraint_minmaxnorm

MinMaxNorm weight constraint

Utils

plot

Plot training history

to_categorical

Converts a class vector (integers) to binary class matrix.

normalize

Normalize a matrix or nd-array

keras_array

Keras array object

hdf5_matrix

Representation of HDF5 dataset to be used instead of an R array

get_file

Downloads a file from a URL if it not already in the cache.

backend

Keras backend tensor engine

implementation

Keras implementation

reexports

Objects exported from other packages

install_keras

Install Keras and the TensorFlow backend

is_keras_available

Check if Keras is Available

Losses

loss_mean_squared_error loss_mean_absolute_error loss_mean_absolute_percentage_error loss_mean_squared_logarithmic_error loss_squared_hinge loss_hinge loss_categorical_hinge loss_logcosh loss_categorical_crossentropy loss_sparse_categorical_crossentropy loss_binary_crossentropy loss_kullback_leibler_divergence loss_poisson loss_cosine_proximity

Model loss functions

Metrics

metric_binary_accuracy metric_binary_crossentropy metric_categorical_accuracy metric_categorical_crossentropy metric_cosine_proximity metric_hinge metric_kullback_leibler_divergence metric_mean_absolute_error metric_mean_absolute_percentage_error metric_mean_squared_error metric_mean_squared_logarithmic_error metric_poisson metric_sparse_categorical_crossentropy metric_squared_hinge metric_top_k_categorical_accuracy metric_sparse_top_k_categorical_accuracy

Model performance metrics

Regularizers

regularizer_l1 regularizer_l2 regularizer_l1_l2

L1 and L2 regularization

Activations

activation_relu activation_elu activation_selu activation_hard_sigmoid activation_linear activation_sigmoid activation_softmax activation_softplus activation_softsign activation_tanh

Activation functions