TensorFlow:“;TypeError:应为int32,获取包含类型为'的张量的列表_消息';取而代之的是;

TensorFlow:“;TypeError:应为int32,获取包含类型为'的张量的列表_消息';取而代之的是;,tensorflow,Tensorflow,当我运行以下代码时: import tensorflow as tf pivot = tf.constant([1, 2]) my_ones = tf.ones([2, 3]) padded = tf.pad(my_ones, [[pivot[0], 0], [1,1]]) sess = tf.Session() init_op = tf.initialize_all_variables() sess.run(init_op) my_ones_var = sess.run(padded) p

当我运行以下代码时:

import tensorflow as tf

pivot = tf.constant([1, 2])
my_ones = tf.ones([2, 3])
padded = tf.pad(my_ones, [[pivot[0], 0], [1,1]])
sess = tf.Session()

init_op = tf.initialize_all_variables()
sess.run(init_op)
my_ones_var = sess.run(padded)
print("my_ones, ", my_ones_var)
…我在包含
tf.pad()
的行中得到一个错误:


我怎样才能做到这一点;DR:当前无法将张量参数定义为包含张量的列表,因此必须手动构建填充

此错误发生在以下行:

padded = tf.pad(my_ones, [[pivot[0], 0], [1,1]])
它失败的原因是
pivot[0]
是一个,它的第二个参数需要一个
tf.Tensor
,而TensorFlow当前没有将包含
tf.Tensor
对象的列表转换为新的张量。解决方法是用于手动构建填充张量:

paddings = tf.pack([tf.pack([pivot[0], 0]), [1, 1]])
padded = tf.pad(my_ones, paddings)
我们正在研究这种自动发生的方式,这样你的原创作品就可以发挥作用


编辑:现在支持自动打包(因为TensorFlow 0.9),所以下面的代码现在可以工作了:

padded = tf.pad(my_ones, [[pivot[0], 0], [1, 1]])

嗨,所有问题都是由于Keras版本引起的。最重要的是,我尝试了,但没有成功。卸载Keras并通过pip安装。这对我有用

我在keras1.0.2中遇到了这个错误,并用keras1.2.0解决了这个问题


希望这会有所帮助。谢谢

您只需使用tf.concat更新所有行即可

比如说

平均值=tf.concat(0,[tf.reduce_-mean(tf.gather(vectors,tf.restrape(tf.equal(assignments,c)),[1,-1])),范围(k)]内c的还原指数=[1]))

应改为


平均数=tf.concat([tf.reduce_-mean(tf.gather(vectors,tf.reformate(tf.where(tf.equal(assignments,c)),[1,-1])),范围(k)]内的c的还原指数=[1]),0)

谢谢!!!!!我终于可以继续工作了。我试过tf.pack,但在不同的地方都没有成功。是的,这应该是自动的。干杯
padded = tf.pad(my_ones, [[pivot[0], 0], [1, 1]])