This document details changes, in particular API changes, occurring from Keras 1 to Keras 2.
nb_epoch
argument has been renamed epochs
everywhere.fit_generator
, evaluate_generator
and predict_generator
now work by drawing a number of batches from a generator (number of training steps), rather than a number of samples.
samples_per_epoch
was changed to steps_per_epoch
in fit_generator
. It now refers to the number of batches an epoch is considered as done.nb_val_samples
was renamed validation_steps
in fit_generator
.val_samples
was renamed steps
in evaluate_generator
and predict_generator
.model.add_loss(loss_tensor)
. The loss is added to the other losses of the model and minimized during training.None
as the loss
argument for an output (e.g. in compile, loss={'output_1': None, 'output_2': 'mse'}
, the model will expect no Numpy arrays to be fed for this output when using fit
, train_on_batch
, or fit_generator
. The output values are still returned as usual when using predict
.fit
if some of their inputs (or even all) are TensorFlow queues or variables, rather than placeholders. See this test for specific examples.objectives
module has been renamed losses
.matthews_correlation
, precision
, recall
, fbeta_score
, fmeasure
.Model
have been renamed:
input
-> inputs
output
-> outputs
Sequential
model not longer supports the set_input
method.Deprecated layers MaxoutDense
, Highway
and TimedistributedDense
have been removed.
training
argument in call
(Python boolean or symbolic tensor), allowing to specify the learning phase on a layer-by-layer basis. E.g. by calling a Dropout
instance as dropout(inputs, training=True)
you obtain a layer that will always apply dropout, regardless of the current global learning phase. The training
argument defaults to the global Keras learning phase everywhere.call
method of layers can now take arbitrary keyword arguments, e.g. you can define a custom layer with a call signature like call(inputs, alpha=0.5)
, and then pass a alpha
keyword argument when calling the layer (only with the functional API, naturally).__call__
now makes use of TensorFlow name_scope
, so that your TensorFlow graphs will look pretty and well-structured in TensorBoard.dim_ordering
argumentdim_ordering
has been renamed data_format
. It now takes two values: "channels_first"
(formerly "th"
) and "channels_last"
(formerly "tf"
).
Changed interface:
output_dim
-> units
init
-> kernel_initializer
bias_initializer
argumentW_regularizer
-> kernel_regularizer
b_regularizer
-> bias_regularizer
b_constraint
-> bias_constraint
bias
-> use_bias
Changed interface:
p
-> rate
AtrousConvolution1D
and AtrousConvolution2D
layer have been deprecated. Their functionality is instead supported via the dilation_rate
argument in Convolution1D
and Convolution2D
layers.Convolution*
layers are renamed Conv*
.Deconvolution2D
layer is renamed Conv2DTranspose
.Conv2DTranspose
layer no longer requires an output_shape
argument, making its use much easier.Interface changes common to all convolutional layers:
nb_filter
-> filters
kernel
size. E.g. a legacy call Conv2D(10, 3, 3)
becomes Conv2D(10, (3, 3))
kernel_size
can be set to an integer instead of a tuple, e.g. Conv2D(10, 3)
is equivalent to Conv2D(10, (3, 3))
.subsample
-> strides
. Can also be set to an integer.border_mode
-> padding
init
-> kernel_initializer
bias_initializer
argumentW_regularizer
-> kernel_regularizer
b_regularizer
-> bias_regularizer
b_constraint
-> bias_constraint
bias
-> use_bias
dim_ordering
-> data_format
SeparableConv2D
layers, init
is split into depthwise_initializer
and pointwise_initializer
.dilation_rate
argument in Conv2D
and Conv1D
.spatial_dims + (input_depth, depth))
, even with data_format="channels_first"
.pool_length
-> pool_size
stride
-> strides
border_mode
-> padding
border_mode
-> padding
dim_ordering
-> data_format
The padding
argument of the ZeroPadding2D
and ZeroPadding3D
layers must be a tuple of length 2 and 3 respectively. Each entry i
contains by how much to pad the spatial dimension i
. If it's an integer, symmetric padding is applied. If it's a tuple of integers, asymmetric padding is applied.
length
-> size
The mode
argument of BatchNormalization
has been removed; BatchNorm now only supports mode 0 (use batch metrics for feature-wise normalization during training, and use moving metrics for feature-wise normalization during testing).
beta_init
-> beta_initializer
gamma_init
-> gamma_initializer
center
, scale
(booleans, whether to use a beta
and gamma
respectively)moving_mean_initializer
, moving_variance_initializer
beta_regularizer
, gamma_regularizer
beta_constraint
, gamma_constraint
running_mean
is renamed moving_mean
running_std
is renamed moving_variance
(it is in fact a variance with the current implementation).Same changes as for convolutional layers and recurrent layers apply.
init
-> alpha_initializer
sigma
-> stddev
output_dim
-> units
init
-> kernel_initializer
inner_init
-> recurrent_initializer
bias_initializer
W_regularizer
-> kernel_regularizer
b_regularizer
-> bias_regularizer
kernel_constraint
, recurrent_constraint
, bias_constraint
dropout_W
-> dropout
dropout_U
-> recurrent_dropout
consume_less
-> implementation
. String values have been replaced with integers: implementation 0 (default), 1 or 2.forget_bias_init
has been removed. Instead there is a boolean argument unit_forget_bias
, defaulting to True
.The Lambda
layer now supports a mask
argument.
Utilities should now be imported from keras.utils
rather than from specific submodules (e.g. no more keras.utils.np_utils...
).
std
-> stddev
set_image_ordering
and image_ordering
are now set_data_format
and data_format
.nb_epoch
) prefixed with nb_
has been renamed to be prefixed with num_
instead. This affects two datasets and one preprocessing utility.