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

Created on 3 Jul 2016  ·  3Comments  ·  Source: tensorflow/tensorflow

Environment info

Operating System: Linux Mint 17.3 Rosa
$uname -a

Linux Pabeda 3.19.0-32-generic #37~14.04.1-Ubuntu SMP Thu Oct 22 09:41:40 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

$python -c "import tensorflow; print(tensorflow.version)"
0.9.0

Steps to reproduce

$ git clone https://github.com/ilblackdragon/tf_examples.git
$ python titanic.py

What have you tried?

  1. I'm trying to run the tutorial on : https://medium.com/@ilblackdragon/tensorflow-tutorial-part-1-c559c63c0cb1#.1a7hit535

    Errors

/usr/local/lib/python2.7/dist-packages/skflow/io/data_feeder.py:217: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
out.itemset((i, self.y[sample]), 1.0)
Traceback (most recent call last):
File "titanic.py", line 30, in
tflr.fit(X_train, y_train)
File "/usr/local/lib/python2.7/dist-packages/skflow/estimators/base.py", line 227, in fit
feed_params_fn=self._data_feeder.get_feed_params)
File "/usr/local/lib/python2.7/dist-packages/skflow/trainer.py", line 146, in train
if summaries:
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 528, in __nonzero__
raise TypeError("Using a tf.Tensor as a Python bool is not allowed. "
TypeError: Using a tf.Tensor as a Python bool is not allowed. Use if t is not None: instead of if t: to test if a tensor is defined, and use the logical TensorFlow ops to test the value of a tensor.

Most helpful comment

@ilblackdragon, what do you think about @thinxer's reponse?

All 3 comments

This is not a TensorFlow issue. You should report to https://github.com/ilblackdragon/tf_examples not here.

Anyway, to fix it, just follow the instructions: replace if t with if t is not None.

@ilblackdragon, what do you think about @thinxer's reponse?

Closing for now as now as this is intended behavior. Using implicit bool conversions is error prone which is why it is disallowed. Thanks!

Was this page helpful?
0 / 5 - 0 ratings