Update TensorFlow backend for Python 3.12 compatibility (Keras 2 via tf-keras) - LTS DLC 2#3091
Merged
MMathisLab merged 18 commits intoLTS-DLC-2from Nov 4, 2025
Merged
Conversation
5f90898 to
504b556
Compare
864dce3 to
de31770
Compare
tf-keras) - LTS DLC 2
2 tasks
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR updates DeepLabCut's dependencies to support newer versions of TensorFlow, PyTorch, and Python, while simplifying COLAB installation instructions. The main changes transition from pinned legacy versions to more flexible version constraints that support modern ML frameworks.
- Removes version pins on core dependencies (tables, pyside6) and updates TensorFlow/PyTorch to latest versions
- Adds tf-keras as explicit dependency to support TensorFlow 2.13+
- Simplifies COLAB notebook installation from multi-step CUDA workarounds to single pip install command
Reviewed Changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| setup.py | Removes version pins on tables/pyside6, adds tf-keras dependency, removes TensorFlow upper version constraint for non-Windows platforms |
| requirements.txt | Updates PyTorch to 2.7.1, TensorFlow to >=2.0, adds tf-keras, adds platform-specific intel-openmp, adjusts matplotlib version |
| examples/testscript_multianimal.py | Removes mobilenet_v2_0.35 from test models list |
| examples/testscript.py | Removes mobilenet_v2_0.35 from test models list |
| examples/COLAB/*.ipynb | Simplifies installation from multi-step CUDA 11.8 workaround to single deeplabcut[tf] install |
| deeplabcut/utils/auxfun_multianimal.py | Fixes NetworkX 3.x compatibility by converting EdgeView to list |
| deeplabcut/pose_estimation_tensorflow/_tf_legacy.py | Adds new module to configure TensorFlow legacy Keras mode and fix tf-keras import paths |
| deeplabcut/pose_estimation_tensorflow/init.py | Imports _tf_legacy module and moves TensorFlow logging suppression from main init.py |
| deeplabcut/init.py | Removes TensorFlow import and logging suppression (moved to pose_estimation_tensorflow) |
| .github/workflows/python-package.yml | Updates CI to test Python 3.10-3.12 on LTS-DLC-2 branch with macos-latest |
| .github/workflows/codespell.yml | Updates branch target to LTS-DLC-2 |
| .circleci/config.yml | Updates CircleCI Python image from 3.8 to 3.12 |
Comments suppressed due to low confidence (1)
setup.py:42
- The torch dependency in setup.py is unpinned while requirements.txt specifies torch==2.7.1 (a non-existent version). These should be consistent. Consider using the same version constraint in both files, such as
torch>=2.0or a valid pinned version.
"torch",
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Description
This PR backports the TensorFlow backend fixes from main branch PR to the DLC 2 LTS branch, in order to ensure compatibility with Python 3.12 (needed due to Google Colab’s migration from Python 3.11 → 3.12).
The motivation and general solution are the same as described in the main branch PR:
tf-kerasand setting theTF_USE_LEGACY_KERAS=1environment variable._tf_legacy.pyshim to declare the environment variables and restore compatibility withtf_keras.legacy_tf_layers.WRAPT_DISABLE_EXTENSIONS=1).tables,PySide6, etc.) for Python 3.12.See the main branch PR for full details.
LTS-specific changes
In addition to the above, the following changes were required specifically for the LTS branch:
import tensorflowout ofdeeplabcut/__init__.pyand intodeeplabcut/pose_estimation_tensorflow/__init__.py(as already done in main branch), to ensure_tf_legacy.pyruns before TensorFlow is imported.random.samle(): Converted Graph edges to list before callingrandom.sample(dict views are no longer supported in 3.12). This fix matches main.intel-openmp,matplotlib,torch).python:3.12(since latest TensorFlow does not provide wheels for 3.8 anymore).Testing
tensorflow-metalshould be manually tested.