How to reshape a tensor where one dimension is reduced to 1?
I'm trying to reshape a tensor using addition and squeeze/normalization from [30,50,32,64] to [30,50,32,1]. And when I use Tensorflow reshape, I'm getting the following error.
o = tf.reshape(o, shape=[30, 50, 32, 1])

ValueError: Cannot reshape a tensor with 3072000 elements to shape [30,50,32,1] (48000 elements) for 'discriminator/embedding/Reshape_4' (op: 'Reshape') with input shapes: [30,50,32,64], [4] and with input tensors computed as partial shapes: input[1] = [30,50,32,1].
Can someone suggest a way around it?

I think you are confusing reshape operation with reduction. First of all, reshape has nothing to do with normalisation. By definition, any reshape operation should preserve number and value of tensor's elements.
i.e. it's impossible to reshape 30x50x32x64 (3072000 elements) tensor to 30x50x32x1 tensor (48000 elements).
Check out the docs: https://www.tensorflow.org/api_docs/python/tf/reshape
So if you want to apply reduction operation on last tensor's dimension you can do it like this:
In [1]: import tensorflow as tf
In [2]: data = tf.random.normal(shape=[30, 50, 32, 64])
In [3]: tf.math.reduce_mean(data, axis=-1, keepdims=True).shape
Out[3]: TensorShape([30, 50, 32, 1])

Squeezing/unsqueezing can be viewed as a special case of reshape operation. Where you are removing or adding single tone dimensions.
# squeeze example
In [4]: tf.squeeze(tf.math.reduce_mean(data, axis=-1, keepdims=True)).shape
Out[4]: TensorShape([30, 50, 32])

# unsqueeze example
In [5]: tf.expand_dims(tf.math.reduce_mean(data, axis=-1, keepdims=True), axis=0).shape
Out[5]: TensorShape([1, 30, 50, 32, 1])

