keras 2.6.0
Breaking changes (Tensorflow 2.6):
-
Note: The following breaking changes are specific to Tensorflow version 2.6.0.
However, the keras R package maintains compatibility with multiple versions of Tensorflow/Keras.
You can upgrade the R package and still preserve the previous behavior by
installing a specific version of Tensorflow:keras::install_keras(tensorflow="2.4.0")
-
predict_proba()
andpredict_classes()
were removed. -
model_to_yaml()
andmodel_from_yaml()
were removed. -
default changed:
layer_text_vectorization(pad_to_max_tokens=FALSE)
-
set_vocabulary()
argumentsdf_data
andoov_df_value
are removed. They are replaced by the new argumentidf_weights
.
New Features:
-
Default Tensorflow/Keras version is now 2.6
-
Introduced
%py_class%
, an R-language constructor for Python classes. -
New vignettes:
- Subclassing Python classes: How to use
%py_class%
. - Making new layers and models via subclassing.
- Customizing what happens in fit (example of how to define a model, like a GAN, with a custom train step).
- Writing your own callbacks.
- Subclassing Python classes: How to use
-
The
keras
Python module is exported -
Major changes to the underlying handling of custom R6 layer classes.
- A new
r_to_py()
method is provided forR6ClassGenerator
objects. - R6 custom layers can now inherit directly from Python layer classes
or other R6 custom layer classes. - Custom R6 layers can now be instantiated directly after conversion of the class generator with
r_to_py()
, without going throughcreate_layer()
. KerasLayer
is deprecated (new classes should inherit directly fromkeras$layers$Layer
).KerasWrapper
is deprecated (new classes should inherit directly fromkeras$layers$Wrapper
).create_wrapper()
is deprecated (no longer needed, usecreate_layer()
directly).- All layer class methods provided as R functions now have a
super
in scope that resolves to the Python super class object. - Methods of
super
can be accessed in the 3 common ways:- (Python 3 style):
super()$"__init__"()
- (Python 2 style):
super(ClassName, self)$"__init__"()
- (R6 style):
super$initialize()
- (Python 3 style):
- User defined custom classes that inherit from a Python type are responsible for calling
super()$`__init__`(...)
if appropriate. - Custom layers can now properly handle masks (#1225)
supports_masking = TRUE
attribute is now supportedcompute_mask()
user defined method is now supported
call()
methods now support atraining
argument, as well as any additional arbitrary user-defined arguments
- A new
-
Layer()
custom layer constructor is now lazy about initializing the Python session and safe to use on the top level of an R package (#1229). -
New function
create_layer_wrapper()
that can create a composing R function wrapper around a custom layer class. -
Refactored
install_keras()
(along withtensorflow::install_tensorflow()
).
Installation should be more reliable for more users now.
If you encounter installation issues, please file an issue: https://github.com/rstudio/keras/issues/new-
Potentially breaking change: numeric versions supplied without a patchlevel now automatically pull the latest patch release.
(e.g.install_keras(tensorflow="2.4")
will install tensorflow version "2.4.2". Previously it would install "2.4.0") -
pandas is now a default extra packages installed by
install_keras()
-
pyyaml is no longer installed by
install_keras()
if TF >= 2.6.
-
-
Loss functions:
-
All the loss functions gain the ability to return a callable
(akeras$losses$Loss
instance) ify_true
andy_pred
arguments are missing. -
New builtin loss functions:
loss_huber()
loss_kl_divergence()
-
-
Metric functions:
-
All the metric functions gain the ability to return a
keras$metrics$Metric
instance if called withouty_true
andy_pred
-
Each metric function is now documented separately, with a common
?Metric
topic demonstrating example usage. -
New built-in metrics:
metric_true_negatives()
metric_true_positives()
metric_false_negatives()
metric_false_positives()
metric_specificity_at_sensitivity()
metric_sensitivity_at_specificity()
metric_precision()
metric_precision_at_recall()
metric_sum()
metric_recall()
metric_recall_at_precision()
metric_root_mean_squared_error()
metric_sparse_categorical_accuracy()
metric_mean_tensor()
metric_mean_wrapper()
metric_mean_iou()
metric_mean_relative_error()
metric_logcosh_error()
metric_mean()
metric_cosine_similarity()
metric_categorical_hinge()
metric_accuracy()
metric_auc()
-
-
keras_model_sequential()
gains the ability to accept arguments that
define the input layer likeinput_shape
anddtype
.
See?keras_model_sequential
for details and examples. -
Many layers gained new arguments, coming to parity with the interface
available in the latest Python version:layer name new argument layer_gru
time_major
layer_lstm
time_major
layer_max_pooling_1d
data_format
layer_conv_lstm_2d
return_state
layer_depthwise_conv_2d
dilation_rate
layer_conv_3d_transpose
dilation_rate
layer_conv_1d
groups
layer_conv_2d
groups
layer_conv_3d
groups
layer_locally_connected_1d
implementation
layer_locally_connected_2d
implementation
layer_text_vectorization
vocabulary
-
The
compile()
method for keras models has been updated:optimizer
is now an optional argument. It defaults to"rmsprop"
for regular keras models.
Custom models can specify their own default optimizer.loss
is now an optional argument.- New optional arguments:
run_eagerly
,steps_per_execution
. target_tensors
andsample_weight_mode
must now be supplied as named arguments.
-
Added activation functions swish and gelu. (#1226)
-
set_vocabulary()
gains aidf_weights
argument. -
All optimizer had argument
lr
renamed tolearning_rate
.
(backwards compatibility is preserved, an R warning is now issued). -
The glue package was added to Imports
-
Refactored automated tests to closer match the default installation procedure
and compute environment of most user. -
Expanded CI test coverage to include R devel, oldrel and 3.6.