Python 连接两个张量
我有两种类型的张量:Python 连接两个张量,python,tensorflow,tensor,Python,Tensorflow,Tensor,我有两种类型的张量: <class 'tensorflow.python.framework.ops.EagerTensor'> 获取错误: InvalidArgumentError: cannot compute ConcatV2 as input #1(zero-based) was expected to be a uint8 tensor but is a float tensor [Op:ConcatV2] name: concat 但不起作用,请帮助。连接时,需要确
<class 'tensorflow.python.framework.ops.EagerTensor'>
获取错误:
InvalidArgumentError: cannot compute ConcatV2 as input #1(zero-based) was expected to be a uint8 tensor but is a float tensor [Op:ConcatV2] name: concat
但不起作用,请帮助。连接时,需要确保两个张量的类型相同。将uint8 1转换为浮动(更可能是您想要的),反之亦然(尽管将浮动转换为uint8可能不会得到您期望的结果)
将tensorflow导入为tf
将numpy作为np导入
tf.compat.v1.enable_eager_execution()
张量1=tf.ones([64,10],dtype=tf.uint8)
tensor2=tf.ones([64100],dtype=tf.float32)
#打印(x型)
tf.concat(axis=1,values=[tf.cast(tensor1,tf.float32),tensor2])#得到了它,谢谢@GPhilo
InvalidArgumentError: cannot compute ConcatV2 as input #1(zero-based) was expected to be a uint8 tensor but is a float tensor [Op:ConcatV2] name: concat
import tensorflow as tf
import numpy as np
tf.compat.v1.enable_eager_execution()
tensor1 = tf.ones([64, 10], dtype=tf.uint8)
tensor2 = tf.ones([64, 100], dtype=tf.float32)
# print(type(x)) # <type 'EagerTensor'>
tf.concat(axis=1, values = [tf.cast(tensor1, tf.float32), tensor2]) # <<<< note the cast