【发布时间】:2017-08-20 23:25:04
【问题描述】:
我想在 Tensorflow 中连接一个变量和一个张量,但 Tensorflow 不会让这两种类型连接。
这是我连接两个张量的方法:
self.embedded_chars = tf.nn.embedding_lookup(self.W, self.input_x) //returns Tensor object
v1 = tf.Variable(tf.zeros([88,77]),dtype=tf.float32)
self.embedded_chars = tf.concat(1,[self.embedded_chars,v1])
但我收到以下错误:
文件“test.py”,第 93 行,在 l2_reg_lambda=FLAGS.l2_reg_lambda) 文件“test.py”,第 31 行,在 init 中 self.embedded_chars = tf.concat(1,[self.embedded_chars,v1]) 文件“lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py”,行 1047,连续 dtype=dtypes.int32).get_shape(文件“lib/python2.7/site-packages/tensorflow/python/framework/ops.py”,行 第651章 as_ref=False)文件“lib/python2.7/site-packages/tensorflow/python/framework/ops.py”,行 716,在 internal_convert_to_tensor 中 ret = conversion_func(值,dtype=dtype,name=name,as_ref=as_ref)文件 “lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py”, 第 176 行,在 _constant_tensor_conversion_function 返回常量(v,dtype=dtype,name=name)文件“lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py”, 第 165 行,保持不变 tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape)) 文件 “lib/python2.7/site-packages/tensorflow/python/framework/tensor_util.py”, 第 367 行,在 make_tensor_proto 中 _AssertCompatible(values, dtype) 文件“lib/python2.7/site-packages/tensorflow/python/framework/tensor_util.py”, 第 302 行,在 _AssertCompatible 中 (dtype.name, repr(mismatch), type(mismatch).name)) TypeError: Expected int32, got list contains Tensors of type '_Message' 而是。
如何正确连接变量和张量?
【问题讨论】:
标签: python python-2.7 tensorflow concatenation