Using tensorflow.keras throws import error: ImportError: cannot import name 'type_spec_registry' from 'tensorflow.python.framework'

Hello there, first post here, so please let me know if there is a specific format I should post in or if there is more information you need to be able to comment.

I’m currently trying to train a CNN with help from my GPU. For that I followed the installation guide from the tensorflow documentation: Install TensorFlow with pip , except installing MiniConda because I’m using Anaconda.
This worked fine, my GPU is detected by tensorflow, but whenever I try to import something from keras, I get the error mentioned in the title of the post. So for example when I’m importing EarlyStopping like this from tensorflow.keras.callbacks import EarlyStopping it throws the error: ImportError: cannot import name ‘type_spec_registry’ from ‘tensorflow.python.framework’ (C:\Users\USER\anaconda3\envs\tf\lib\site-packages\tensorflow\python\

I’m not sure why this happens. I’m using tensorflow version 2.10.1, installed CUDA 11.2, cuDNN 8.1 and python 3.9.16.

If anyone knows something about this, please share any info!


Welcome to the Tensorflow Forum!

It seems the issue with version compatibility between Tensorflow and Keras.

Note: To use Keras, you will need to have the TensorFlow package installed. See detailed instructions.

Once TensorFlow is installed, just import Keras via:

from tensorflow import keras

If the problem persists, could you please try upgrading to the most recent Tensorflow version and let us know?

Thank you!

I couldn’t make it work with a lower version and then tried upgrading to tensorflow 2.11 and the error didn’t occur anymore. But I wanted to use a lower tensorflow version in the first place, because of the GPU support. Isn’t there any way to make a lower tensorflow version work with keras?