Update TensorFlow backend for Python 3.12 compatibility (Keras 2 via tf-keras)#3087
Merged
Update TensorFlow backend for Python 3.12 compatibility (Keras 2 via tf-keras)#3087
tf-keras)#3087Conversation
1c1fd02 to
08b5d3c
Compare
08b5d3c to
79e54a9
Compare
2657cdf to
40d159a
Compare
aa0fca8 to
0e8c3d2
Compare
0e8c3d2 to
b4aca6e
Compare
4efcbda to
48201fa
Compare
48201fa to
01c3008
Compare
7c151af to
d08878e
Compare
7e88a68 to
1023a14
Compare
5a4df95 to
e778557
Compare
6833c8a to
8b8ec8c
Compare
tf-keras)
2 tasks
AlexEMG
approved these changes
Oct 1, 2025
deruyter92
added a commit
to deruyter92/DeepLabCut
that referenced
this pull request
Dec 5, 2025
Useful for investigating compatibility with different tensorflow versions (See PR DeepLabCut#3087 and DeepLabCut#3091)
deruyter92
added a commit
to deruyter92/DeepLabCut
that referenced
this pull request
Dec 5, 2025
Useful for investigating compatibility with different tensorflow versions (See PR DeepLabCut#3087 and DeepLabCut#3091)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Google Colab recently switched from Python 3.11 to Python 3.12, which introduced several dependency issues, particularly affecting our TensorFlow backend.
The main issue was that we had pinned TensorFlow to version 2.12.0 (
tensorflow>=2.0,<=2.12for non-Windows,<=2.10for Windows). These old versions are no longer available for Python 3.12, where the earliest installable TensorFlow release is 2.16.0.However, since TensorFlow 2.16.0, Keras 3 is used by default, which is incompatible with our current TensorFlow code (e.g.,
BatchNormalization is not available with Keras 3errors due totf.compat.v1). This incompatibility was the reason for pinning TensorFlow in the first place.Changes Introduced
To resolve these issues, this PR introduces the following changes:
1. TensorFlow & Keras compatibility (link to TF documentation)
tf-kerasand setting the environment variableTF_USE_LEGACY_KERAS=1._tf_legacy.pyto ensure these environment variables are declared when using the TensorFlow backend.2. Additional environment variables
WRAPT_DISABLE_EXTENSIONS=1to resolve the error:TypeError: this __dict__ descriptor does not support '_DictWrapper' objects(related to wrapt, a TensorFlow dependency, the solution has been suggested here).
3. Compatibility shim for tf-keras namespace changes
tf-kerasreorganized legacy layers under asrc/namespace._tf_legacy.pyto handle both layouts:4. Relaxed other package requirements
tablesandPySide6, since the exact pinned versions were unavailable on Python 3.12.5. CI/CD improvements
num_workers > 0. Setnum_workers=0explicitly in these cases.6. Colab notebooks update
Testing
tensorflow-metal: only tested via CI/CD (notensorflow-metal), not on a real machine. This should be validated before merging.Notes / Future Work
tensorflow-metalusers validate installation and training pipelines.