expand_dims will not add or reduce elements in the tensor, it just changes shape, adding 1 to the dimensions. For example, a vector with 10 elements can be considered as a 10x1 matrix.
The situation I met to use expand_dims was when I tried to create ConvNet to classify grayscale images. Images in grayscale will be uploaded as a size matrix [320, 320] . However, tf.nn.conv2d requires input [batch, in_height, in_width, in_channels] , where in my data there is no in_channels size, which in this case should be 1 . So I used expand_dims to add another dimension.
In your case, I don't think you need expand_dims .
Da tong
source share