TypeError("Using a `tf.Tensor` as a Python `bool` is not allowed. "
<p>My main task here is to sum the values of tensor generated by conv1_2
Following is my code</p>

<pre><code>class vgg16:
    def __init__(self, imgs, weights=None, sess=None): 
        self.imgs = imgs
        self.convlayers()
        self.fc_layers()
    self.sum_pool()
        self.probs = tf.nn.softmax(self.fc3l) #this is your inference
        if weights is not None and sess is not None:
            self.load_weights(weights, sess)
    def sum_pool(self):
    if self.conv1_2 is not None:
        return tf.add_n(self.conv1_2)

    def convlayers(self):
       .....
        ....

        # conv1_1
        with tf.name_scope('conv1_1') as scope:
           ......

            self.conv1_1 = tf.nn.relu(out, name=scope)
            self.parameters += [kernel, biases]

        # conv1_2
       .....
            self.conv1_2 = tf.nn.relu(out, name=scope)
            self.parameters += [kernel, biases]

        # pool1

    tf.Print(self.conv1_2,self.parameters)

        self.pool1=self.sum_pool()
</code></pre>

<p>When I run this code it gives me the following error</p>

<pre><code>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 TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.
</code></pre>

<p>And this error is coming from the line where I am calling the function add_n()
I can't figure this out. Please tell me what I am doing wrong. </p>

<p>Traceback:</p>

<pre><code>Traceback (most recent call last):
  File "/usr/lib/python2.7/pdb.py", line 1314, in main
    pdb._runscript(mainpyfile)
  File "/usr/lib/python2.7/pdb.py", line 1233, in _runscript
    self.run(statement)
  File "/usr/lib/python2.7/bdb.py", line 400, in run
    exec cmd in globals, locals
  File "&lt;string&gt;", line 1, in &lt;module&gt;
  File "vgg16.py", line 268, in &lt;module&gt;
    vgg = vgg16(imgs, 'vgg16_weights.npz', sess)
  File "vgg16.py", line 22, in __init__
    self.convlayers()
  File "vgg16.py", line 71, in convlayers
    self.pool1=self.sum_pool()
  File "vgg16.py", line 31, in sum_pool
    return tf.add_n(self.conv1_2)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/math_ops.py", line 1826, in add_n
    if not inputs or not isinstance(inputs, (list, tuple)):
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 547, 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 TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
&gt; /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py(547)__nonzero__()
-&gt; raise TypeError("Using a `tf.Tensor` as a Python `bool` is not allowed. "
</code></pre>