Open
Description
Keras 3 is a major new release. It features a number of cleanups and modernizations of Keras which leads to number of breaking changes compared to Keras 2.
The list below is exhaustive to the best of our knowledge.
A small number of items are likely to affect you (jit_compile
default value change, TF SavedModel support changes, usage of tf.Variable
as layer attributes). The majority are very niche. All APIs that were removed were dropped due to extremely low usage.
Behavior differences between old tf.keras
and Keras 3 (with TF backend)
- APIs that were previously long-deprecated or experimental are gone.
compat.v1
APIs are gone (deprecated in 2019). In the case ofexperimental
APIs, usually those are APIs that have already moved to a permanent namespace long ago (e.g. the contents oftf.keras.layers.experimental.preprocessing
is now atkeras.layers
, since 2021), so just update the import path to the up-to-date location. - Keras 3 has
jit_compile=True
by default -- this might not work with all TF ops, so with some custom models/layers you might have setjit_compile=False
if you see an XLA related error. - Saving to TF SavedModel format via
model.save()
is no longer supported (note: you can usetf.save_model.save(model)
instead) - Loading a TF SavedModel file via
keras.models.load_model()
is no longer supported (note: you can usekeras.layers.TFSMLayer(filepath, call_endpoint="serving_default")
to reload any TF SavedModel as a Keras layer) Model()
can no longer be passed deeply nested inputs/outputs (nested more than 1 level deep, e.g. lists of lists of tensors)- In old
tf.keras
, TF autograph is enabled by default on thecall()
method of custom layers. In Keras 3, it is not. This means you may have to usecond
ops if you're using control flow, or alternatively you can decorate yourcall()
method with@tf.function
. - Using a TF op on a Keras tensor during functional model construction is disallowed: "A KerasTensor cannot be used as input to a TensorFlow function". Fix: use an equivalent op from
keras.ops
. - Multioutput model's
evaluate()
method does not return individual output losses anymore -> use themetrics
argument in compile to track them - Layer names and variable names can no longer contain the
/
character. - No
RaggedTensor
support. We may add it back later. - When having multiple named outputs (for example named
output_a
andoutput_b
, oldtf.keras
adds<output_a>_loss
,<output_b>_loss
and so on to metrics. Keras 3 doesn't add them to metrics and needs to be done them to the output metrics by explicitly providing them inmetrics
list of individual outputs. tf.Variable
objects assigned to aLayer
are not tracked as part ofweights
. Fix: useself.add_weight()
method or use akeras.Variable
instead.None
entries are not allowed as part of nested (e.g. list/tuples) tensor arguments inLayer.call()
, nor as part ofcall()
return values.- Functional models with list outputs do not accept dict losses/metrics anymore
- Symbolic
add_loss()
is removed (you can still useadd_loss()
inside thecall()
method of a layer/model). - Locally-connected layers are removed (they had ~0 usage). Fix: copy the layer implementation into your own codebase.
- Kernelized layers are removed (they had ~0 usage). Fix: copy the layer implementation into your own codebase.
Layer
attributesmetrics
,dynamic
are removedconstants
arg in RNN layers is removed (remnant of Theano, ~0 usage)time_major
arg in RNN layers is removed (~0 usage)- Removed
reset_metrics
argument frommodel.*_on_batch
methods (~0 usage) RadialConstraint
constraint object is removed (~0 usage)
Present in Keras 3 standalone but will work when accessing Keras 3 via the new tf.keras
- Various (undocumented) backend functions missing, e.g.
backend.random_normal
AlphaDropout
layer is removedThresholdedReLU
layer is removed (subsumed byReLU
)RandomHeight
/RandomWidth
layers are removed (better useRandomZoom
)
Metadata
Metadata
Assignees
Labels
No labels