Here is short explanation about the dimensions of the input tensor to Convolutional 2D layer.
tensor_shape = (BATCH_SIZE, WIDTH, HEIGHT, CHANNELS).
The fourth dimension is channels(color) dimension.
Long answer would be:
Convolutional 2D layer expects the input to have four dimensions. There are two image tensor formats in tensorflow .
1. channels_last(NHWC) - Dimensions are ordered as
(BATCH_SIZE, HEIGHT, WIDTH, CHANNEL).
2. channels_first(NCHW) - Dimensions are ordered as
BATCH_SIZE, CHANNELS, HEIGHT, WIDTH).
Batch Size dimension
In tensorflow(possibly in other machine learning libraries) once you have defined your model, you have two options to feed data to your model. The first options is feeding the data points one at a time. The second options is feed
N number of data points at time to your model. This is possible becuase of the Batch size dimension
This dimension specifies the width of the image.
This dimension specifies Height of the image
The channel dimension in RGB image is the RGB values dimension.
To specify the dataformat of your input images tensor conv2d layer accepts data_format argument.The default is "channels_last". You can find more here.
The following code shows input with channals_last data format
inputs_ = tf.placeholder(tf.float32, [None, 32, 32, 3])
conv1 = tf.layers.conv2d(inputs_,32, (3, 3), data_format="channals_last")
for channels first
conv1 = tf.layers.conv2d(inputs_,32, (3, 3), data_format="channels_first")