keras包导入问题AttributeError: module 'tensorflow' has no attribute 'name_scope'
模型可视化
from tensorflow import keras
from keras.utils import plot_model
plot_model(model, to_file='model.png')
Using TensorFlow backend.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-a068fd2fd5a7> in <module>
----> 1 from keras.utils import plot_model
3 plot_model(model, to_file='model.png')
D:\anaconda\envs\py3\lib\site-packages\keras\__init__.py in <module>
1 from __future__ import absolute_import
----> 3 from . import utils
4 from . import activations
5 from . import applications
D:\anaconda\envs\py3\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
D:\anaconda\envs\py3\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
D:\anaconda\envs\py3\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
D:\anaconda\envs\py3\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.
D:\anaconda\envs\py3\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
AttributeError: module 'tensorflow' has no attribute 'name_scope'
把from keras.utils import plot_model改成 from tensorflow.keras.utils import plot_model问题就解决了,问题不晓得出在哪了。
from tensorflow.keras.utils import plot_model
plot_model(model, to_file='model.png')