使用导入Keras时无法导入名称

使用导入Keras时无法导入名称

本文介绍了使用导入Keras时无法导入名称'tf_utils'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Oracle Linux 7.7,并使用yum(epel仓库)安装了python3.6.然后我安装了tensorflow 1.5(因为如果它更新了,我会丢弃内核)和keras.如果我导入tensorflow,我什么也没有.但是当我导入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'

这是完整的输出:

$ 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'

我以前通过从源代码构建它来使用python 3.6,而keras可以正常工作,但是由于我无法为pyplot安装tkinter,因此我将其卸载并使用yum中的一个.

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.

推荐答案

似乎是keras 2.3.0的问题,我使用pip安装了keras 2.1.5,它工作正常.

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

这篇关于使用导入Keras时无法导入名称'tf_utils'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:16