错误:不允许将“ tf.Tensor”用作Python“ bool”(Tensorflow动态创建变量)

时间:2018-11-10 06:47:55

标签: python tensorflow lstm

我想根据 placehoder 的值动态创建一些变量,但是tf.get_variable()似乎不受支持。

这是我的代码:

pos_diags=tf.palceholder(tf.string,shape=[None],name='pos_diags')
with tf.variable_scope('att_pos'):
     att_para={'w':tf.get_variable(pos_diags+'w',[300,100]),
               'b':tf.get_variable(pos_diags+'b',[1,100])
      }

但是我总是收到错误消息:

"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.

0 个答案:

没有答案