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_dataandoov_df_valueare 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
kerasPython module is exported -
Major changes to the underlying handling of custom R6 layer classes.
- A new
r_to_py()method is provided forR6ClassGeneratorobjects. - 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(). KerasLayeris deprecated (new classes should inherit directly fromkeras$layers$Layer).KerasWrapperis 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
superin scope that resolves to the Python super class object. - Methods of
supercan 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 = TRUEattribute is now supportedcompute_mask()user defined method is now supported
call()methods now support atrainingargument, 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$Lossinstance) ify_trueandy_predarguments 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$Metricinstance if called withouty_trueandy_pred -
Each metric function is now documented separately, with a common
?Metrictopic 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_shapeanddtype.
See?keras_model_sequentialfor 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_grutime_majorlayer_lstmtime_majorlayer_max_pooling_1ddata_formatlayer_conv_lstm_2dreturn_statelayer_depthwise_conv_2ddilation_ratelayer_conv_3d_transposedilation_ratelayer_conv_1dgroupslayer_conv_2dgroupslayer_conv_3dgroupslayer_locally_connected_1dimplementationlayer_locally_connected_2dimplementationlayer_text_vectorizationvocabulary -
The
compile()method for keras models has been updated:optimizeris now an optional argument. It defaults to"rmsprop"for regular keras models.
Custom models can specify their own default optimizer.lossis now an optional argument.- New optional arguments:
run_eagerly,steps_per_execution. target_tensorsandsample_weight_modemust now be supplied as named arguments.
-
Added activation functions swish and gelu. (#1226)
-
set_vocabulary()gains aidf_weightsargument. -
All optimizer had argument
lrrenamed 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.