Tensorflow: When use tf.expand_dims?

后端 未结 2 1774
甜味超标
甜味超标 2020-12-24 13:10

Tensorflow tutorials include the use of tf.expand_dims to add a \"batch dimension\" to a tensor. I have read the docs for this function but it still is rather m

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-24 13:47

    expand_dims will not add or reduce elements in a tensor, it just changes the shape by adding 1 to dimensions. For example, a vector with 10 elements could be treated as a 10x1 matrix.

    The situation I have met to use expand_dims is when I tried to build a ConvNet to classify grayscale images. The grayscale images will be loaded as matrix of size [320, 320]. However, tf.nn.conv2d require input to be [batch, in_height, in_width, in_channels], where the in_channels dimension is missing in my data which in this case should be 1. So I used expand_dims to add one more dimension.

    In your case, I do not think you need expand_dims.

提交回复
热议问题