tensorflow后端错误. AttributeError:模块"tensorflow"没有属性"name_scope" [英] tensorflow backend error. AttributeError: module 'tensorflow' has no attribute 'name_scope'

查看:105
本文介绍了tensorflow后端错误. AttributeError:模块"tensorflow"没有属性"name_scope"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用版本:TensorFlow的2.1.0和keras的2.3.1.导入任何模块的keras时,我都在tensorflow后端错误下面.

I'm using Version: 2.1.0 of TensorFlow and 2.3.1 of keras. While importing any module of keras i'm facing below tensorflow back-end error.

import pandas as pd, numpy as np, os, re, json, math, time 
from keras.models import Sequential 
from keras.layers import Dense 
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.model_selection import cross_val_score 
from sklearn.model_selection import KFold 
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline 
from sklearn.model_selection import train_test_split 

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last) <ipython-input-82-2f712055860b> in <module>
      1 import pandas as pd, numpy as np, os, re, json, math, time
----> 2 from keras.models import Sequential
      3 from keras.layers import Dense
      4 from keras.wrappers.scikit_learn import KerasRegressor
      5 from sklearn.model_selection import cross_val_score

~\Anaconda3\lib\site-packages\keras\__init__.py in <module>
      1 from __future__ import absolute_import
      2 
----> 3 from . import utils
      4 from . import activations
      5 from . import applications

~\Anaconda3\lib\site-packages\keras\utils\__init__.py in <module>
      4 from . import data_utils
      5 from . import io_utils
----> 6 from . import conv_utils
      7 from . import losses_utils
      8 from . import metrics_utils

~\Anaconda3\lib\site-packages\keras\utils\conv_utils.py in <module>
      7 from six.moves import range
      8 import numpy as np
----> 9 from .. import backend as K
     10 
     11 

~\Anaconda3\lib\site-packages\keras\backend\__init__.py in <module>
----> 1 from .load_backend import epsilon
      2 from .load_backend import set_epsilon
      3 from .load_backend import floatx
      4 from .load_backend import set_floatx
      5 from .load_backend import cast_to_floatx

~\Anaconda3\lib\site-packages\keras\backend\load_backend.py in <module>
     88 elif _BACKEND == 'tensorflow':
     89     sys.stderr.write('Using TensorFlow backend.\n')
---> 90     from .tensorflow_backend import *
     91 else:
     92     # Try and load external backend.

~\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py in <module>
     54 get_graph = tf_keras_backend.get_graph
     55 # learning_phase_scope = tf_keras_backend.learning_phase_scope  # TODO
---> 56 name_scope = tf.name_scope
     57 
     58 

> AttributeError: module 'tensorflow' has no attribute 'name_scope'

期待快速解决.

推荐答案

我建议您切换到使用TensorFlow中的keras模块.

I recommend that you switch to using the keras module inside TensorFlow.

维护得更好,不会出现不兼容的问题.

It is better maintained and you will not have incompatibility issues.

根据弗朗索瓦·乔勒(Francois Chollet):

According to Francois Chollet:

Keras 2.3.0版在这里,它是最后一个主要的多后端 释放.今后,建议用户切换其代码 转到TensorFlow 2.0中的tf.keras.此版本带来了API更改 以及一些重大变化.看看引擎盖下,看看它是什么 内容以及计划的进展.

Keras version 2.3.0 is here, and it is the last major multi-backend release. Going forward, users are recommended to switch their code over to tf.keras in TensorFlow 2.0. This release brings API changes and a few breaking changes. Have a look under the hood and see what it includes, as well as what the plans are going forward.

切换所有导入,而不是

from keras.models import Sequential 
from keras.layers import Dense 

from tensorflow.keras.models import Sequential 
from tensorflow.keras.layers import Dense 

将解决您所有的不兼容问题.

will solve all your incompatibility issues.

由于默认情况下TensorFlow中已包含Keras,因此可以将其作为单独的软件包完全卸载.

You can uninstall Keras altogether as a separate package since it is already included by default in TensorFlow.

观察:如果PyCharm无法识别tensorflow.keras,则需要将PyCharm更新为最新版本> = 2019.3.仅从该版本开始,PyCharm中会相应地识别TensorFlow 2.0.请查阅下面的答案以获取更多信息:

OBSERVATION: If PyCharm does not recognise tensorflow.keras, you will need to update PyCharm to the latest version >=2019.3. Only starting with that version is TensorFlow 2.0 recognised accordingly in PyCharm. Please consult the answer below for more information:

无法在PyCharm中导入Keras(从TensorFlow 2.0)

这篇关于tensorflow后端错误. AttributeError:模块"tensorflow"没有属性"name_scope"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆