【问题标题】:TypeError: Using a `tf.Tensor` as a Python `bool` is not allowedTypeError: 不允许使用 `tf.Tensor` 作为 Python `bool`
【发布时间】:2016-12-01 17:39:08
【问题描述】:

我想在我的 Python 3.5 代码中使用 Tensorflow 和 TFLearn 库。我已经使用pip 安装了两者。我有以下版本:

tensorflow 0.12.0rc0
tflearn 0.2.1
python 3.5.2
conda 4.2.13

但是,在运行某些代码时,我收到以下错误:

TypeError: Using a `tf.Tensor` as a Python `bool` is not allowed.

从this issue on GitHub 得知,这个问题应该已经解决了。

我该如何解决这个问题?

编辑:这是完整的堆栈跟踪:

Traceback (most recent call last):
  File "test.py", line 35, in <module>
    agent = DQNAgent(create_mlp, n_actions, env.observation_space.shape, min_replay_size=10000, batch_size=64)
  File "agents.py", line 86, in __init__
    self.q_net = network_fn(self.s, self._n_actions)
  File "test.py", line 23, in create_mlp
    net = nn.input_data(placeholder=inputs)
  File "//anaconda/lib/python3.5/site-packages/tflearn/layers/core.py", line 55, in input_data
    if not shape and not placeholder:
  File "//anaconda/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 533, in __bool__
raise TypeError("Using a `tf.Tensor` as a Python `bool` is not allowed. "

【问题讨论】:

  • 你能分享错误的完整堆栈跟踪吗?这将使我们能够查明哪些代码不正确。

标签: python-3.x tensorflow


【解决方案1】:

这个错误是由tflearn v0.2.1 库引起的。解决此错误的方法是通过git 安装最新版本:

pip install git+https://github.com/tflearn/tflearn.git

这将安装tflearn v0.2.2,其中不再出现此错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-17
    • 2020-03-18
    • 1970-01-01
    • 2018-07-12
    • 2021-04-18
    • 2020-05-04
    • 2018-03-20
    • 2019-11-21
    相关资源
    最近更新 更多