没有名为layers的模块

时间:2017-02-24 15:50:42

标签: python tensorflow

我正在使用tensorflow 1.0.0,我想访问tensorflow.layers模块。该模块似乎存在:

In [12]: dir(tensorflow.layers)
Out[12]: 
['__builtins__',
 '__doc__',
 '__file__',
 '__name__',
 '__package__',
 '_allowed_symbols',
 'average_pooling1d',
 'average_pooling2d',
 'average_pooling3d',
 'batch_normalization',
 'conv1d',
 'conv2d',
 'conv2d_transpose',
 'conv3d',
 'dense',
 'dropout',
 'max_pooling1d',
 'max_pooling2d',
 'max_pooling3d',
 'separable_conv2d']

但是当我尝试导入时,例如密集的功能:

In [13]: from tensorflow.layers import dense
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-13-e5b2c910300d> in <module>()
----> 1 from tensorflow.layers import dense

ImportError: No module named layers

为什么python不能访问该模块?

1 个答案:

答案 0 :(得分:1)

您的安装或工作区出现问题:

  • 确保Python路径中没有名为“tensorflow”的目录。
  • 再次安装官方tensorflow发行版pip install —upgrade —ignore-installed tensorflow)
  • 确保使用正确的tensorflow版本print(tensorflow.__version__)