Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import name 'tf_utils' when using importing keras

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.

like image 805
Christophorus Reyhan Avatar asked Sep 18 '19 05:09

Christophorus Reyhan


2 Answers

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

like image 117
Christophorus Reyhan Avatar answered Oct 10 '22 02:10

Christophorus Reyhan


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

like image 4
FantasticManWhale Avatar answered Oct 10 '22 01:10

FantasticManWhale