AttributeError: 模块“tensorflow”没有属性“float32”

ahb*_*bon 3 python windows tensorflow

在为 tensorflow 模型设置环境时,当我python model_builder_test.py在最后一步运行时,原因AttributeError: module 'tensorflow' has no attribute 'float32',有人知道如何修复它吗?谢谢。

https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md

PS C:\Users\User\models\research\object_detection\builders> python model_builder_test.py
Traceback (most recent call last):
  File "model_builder_test.py", line 21, in <module>
    from object_detection.builders import model_builder
  File "C:\Users\User\models\research\object_detection\builders\model_builder.py", line 17, in <module>
    from object_detection.builders import anchor_generator_builder
  File "C:\Users\User\models\research\object_detection\builders\anchor_generator_builder.py", line 18, in <module>
    from object_detection.anchor_generators import grid_anchor_generator
  File "C:\Users\User\models\research\object_detection\anchor_generators\grid_anchor_generator.py", line 27, in <module>
    from object_detection.utils import ops
  File "C:\Users\User\models\research\object_detection\utils\ops.py", line 282, in <module>
    dtype=tf.float32):
AttributeError: module 'tensorflow' has no attribute 'float32'
Run Code Online (Sandbox Code Playgroud)

InA*_*ash 5

tensorflow 有 float32。

In [1]: import tensorflow as tf

In [2]: tf.float32
Out[2]: tf.float32
Run Code Online (Sandbox Code Playgroud)

以上是我的输出确认。这是在 Windows 中安装时的一个已知问题。您可以查看这里

要修复它,您只需要tensorflow使用以下命令重新安装

pip install --upgrade --force-reinstall tensorflow
Run Code Online (Sandbox Code Playgroud)

注意:一个更常见的错误是将模块命名为tensorflow. 这可能会导入您创建的这个空模块