Adding an additional channel to a 3 channel tensor

Viewed 522

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

I 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?

1 Answers

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)
Related