AttributeError: module ‘tensorflow’ has no attribute ‘keras’

import tensorflow as tf

model = tf.keras.models.load_model(‘path_to_model.h5’)

I’m getting module ‘tensorflow’ has no attribute ‘keras’ error when i try to load the model.

I found another post with similar issue but the solutions given below didn’t work for me.

Could someone help me?

Hi @Yoganand_Parab, Could you please share the tensorflow and keras version you are using? Thank you.

I have installed following versions of tensorflow and keras on anaconda(win11).
Name: tensorflow
Version: 2.14.0
Name: tensorflow
Version: 2.14.0

Hi @Yoganand_Parab, could you please check the environment in which you have installed tensorflow contains keras package as well if not please try to install keras using pip install keras. Thank you.

hello, i have the same issue and i have installed keras it doesnt solve it.

Hi @tolishunter23, Instead of importing keras from tensorflow could you please try by importing keras directly using import keras . Thank you.

1 Like

This one worked for me!

Thanks a lot

I have same error and tried to uninstall tensor and reinstall it and I tried to upgrade tensorflow and upgrade keras and I tried to import keras there is nothing help