Channels first vs Channels last in CNNs

Hi, I am trying to understand the difference between channels first and channels last, with regards to CNNs

Lets say I have the following data
rainfall temp
10 20
11 25
12 30
13 35

in the shape (4,2)
and I want convolutions to happen along rainfall data [10,11,12,13] and temp data [20,25,30,35] and not [10,20] for the first record [rainfall,temp]

what would bet the setting for the data_format in keras

tf.keras.layers.Conv1D( 32, 3, activation='relu',data_format="channels_last".....)
tf.keras.layers.Conv1D( 32, 3, activation='relu',data_format="channels_first".....)


data_format=channels_first means that in a specific tensor (e.g. image), you would have (channels, height, width), while data_format=channels_last means that the channels are in the last position of a tensor (height, width, channels).

For time series the data_format is irrelevant. So the Conv1D layer can be as shown below

tf.keras.layers.Conv1D( 32, 3, activation='relu')

Thank you!

1 Like