Cannot import name 'tf_utils' when using importing keras
Asked Answered
E

3

22

I'm using Oracle Linux 7.7, and I installed python3.6 using yum (epel repos). Then I install tensorflow 1.5(since if it goes newer ver I got core dumped) and keras. If I'm importing tensorflow, I got nothing. But when I import keras, I got

ImportError: cannot import name 'tf_utils'

Here's the full output:

$ python
Python 3.6.8 (default, Aug  7 2019, 08:02:28) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39.0.1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> import keras
Using TensorFlow backend.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/reyhan/project/.virtualenvs/keras_tf/lib/python3.6/site-packages/keras/__init__.py", line 3, in <module>
from . import utils
  File "/home/reyhan/project/.virtualenvs/keras_tf/lib/python3.6/site-packages/keras/utils/__init__.py", line 6, in <module>
from . import conv_utils
  File "/home/reyhan/project/.virtualenvs/keras_tf/lib/python3.6/site-packages/keras/utils/conv_utils.py", line 9, in <module>
from .. import backend as K
  File "/home/reyhan/project/.virtualenvs/keras_tf/lib/python3.6/site-packages/keras/backend/__init__.py", line 1, in <module>
from .load_backend import epsilon
  File "/home/reyhan/project/.virtualenvs/keras_tf/lib/python3.6/site-packages/keras/backend/load_backend.py", line 90, in <module>
from .tensorflow_backend import *
  File "/home/reyhan/project/.virtualenvs/keras_tf/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 13, in <module>
from tensorflow.python.keras.utils import tf_utils
ImportError: cannot import name 'tf_utils'

I was using python 3.6 by building it from source before and keras worked fine but since I can't install tkinter for pyplot I uninstall it and using the one from yum instead.

Extensive answered 18/9, 2019 at 5:5 Comment(0)
E
68

Seems like it was a problem with keras 2.3.0, I installed keras 2.1.5 using pip and it works fine.

Extensive answered 18/9, 2019 at 5:54 Comment(8)
I had the same problem, by pip uninstall keras and reinstalling keras 2.2.0 (pip install keras==2.2.0) my problem solved. I was using python 2.7.15 on ubuntu 18.04Playtime
@weber85's solution helped me on python 3.6.8 on ubuntu 18.04Luane
Worked for me too, Thank you! Ubuntu 19.10, Python 3.6.9, Tensorflow 1.5 (also after core dumped) and Keras 2.2.0.Caylacaylor
@Caylacaylor did you upgrade tensorflow to 2.0 and still get core dumped even if you use ubuntu 19.10?Extensive
@Christophorus, no I didn’t upgrade back to 2.0, but did get a core dumped when trying to run tensorboard. Eventually ran my stuff on google collab jupyter notebook.Caylacaylor
@ChristophorusReyhan now is i'm getting the following. from tensorflow.python.keras.utils import tf_utils ImportError: cannot import name 'tf_utils'Dorian
@safak whats your version of tf and keras?Extensive
@SafakCiplak Yes you're getting import error for tf_utils because your current keras version is probably not compatible with either your system or other libraries; try downgrading your keras version; maybe your processor is pentium.Army
J
4

I had the same problem, but upgraded Tensorflow via pip rather than downgrading Keras and this solved the problem :)

Using Python 3.6.4, Keras 2.3.1, Tensorflow 2.0

Junko answered 23/10, 2019 at 10:45 Comment(1)
that's because keras 2.3.1 is compatible with tensorflow 2.0, but I can't afford to upgrade tf to 2.0 because i got core dumped. But yes, if you can upgrade the tensorflow, do itExtensive
G
0

This useful link could help you, the script is:

pip install tensorflow==2.12 tensorflow-addons[tensorflow]
Graf answered 10/10, 2023 at 12:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.