I would like to combine a tensor of shape [3,1024,1024] and a tensor of shape [1,1024,1024] in order to form a single tensor of shape [4,1024,1024]
This is to combine the channels of an RGB image to a depth image in the format of [r,g,b,d] for each pixel
Im am currently trying to do this like this:
tensor = tf.concat([imageTensor, depthTensor], axis=2)
But I receive the error
InvalidArgumentError: ConcatOp : Dimensions of inputs should match: shape[0] = [3,1024,1024] vs. shape[1] = [1,1024,1024] [Op:ConcatV2]
I was just wondering how this would be done?
CodePudding user response:
You want to concatenate on axis=0:
import tensorflow as tf
t1 = tf.random.uniform((3, 1024, 1024))
t2 = tf.random.uniform((1, 1024, 1024))
final_tensor = tf.concat((t1, t2), axis=0)
print(final_tensor.shape)
(4, 1024, 1024)
CodePudding user response:
Depending on what your tensors look like, try:
import tensorflow as tf
imageTensor = tf.random.normal((3,1024,1024))
depthTensor = tf.random.normal((1,1024,1024))
tensor = tf.concat([imageTensor, depthTensor], axis=0)
print(tensor.shape)
# (4, 1024, 1024)
Or:
imageTensor = tf.random.normal((1024,1024,3))
depthTensor = tf.random.normal((1024,1024, 1))
tensor = tf.concat([imageTensor, depthTensor], axis=-1)
print(tensor.shape)
# (1024, 1024, 4)