# What would be the advantage of making channel dimension first in TensorFlow Keras implementation?

I was reproducing the findings of a research article in which I discovered that they had switched the Channel dimension from last to first. To clarify this concept, I went through A Gentle Introduction to Channels-First and Channels-Last Image Formats . The author of this link stated:

When represented as three-dimensional arrays, the channel dimension for the image data is last by default, but may be moved to be the first dimension, often for performance-tuning reasons.

There are two ways to represent the image data as a three dimensional array. The first involves having the channels as the last or third dimension in the array. This is called “channels last“. The second involves having the channels as the first dimension in the array, called “channels first“.

Channels Last. Image data is represented in a three-dimensional array where the last channel represents the color channels, e.g. [rows][cols][channels].

Channels First. Image data is represented in a three-dimensional array where the first channel represents the color channels, e.g. [channels][rows][cols].

.

We are aware of when the channel was last used and the manner in which kernels were applied, theoretically. However, I'm curious as to when the dimensions of the channel come first. How kernels will process. More precisely:

Assume we have [rows, columns, channels] -> [2,4,3] image dimensions. We may say we have three data channels, each with two rows and four columns, correct?

Alternatively, if we assume that channel dimensions are first means [channels, rows, columns] -> [3,2,4]. In other words, we now have four data channels, each with three rows and two columns, am I correct? If I am taking correctly than this is quite confusing because we are completely modifying our image.

### Question:

What is the benefit of shifting the channel dimension first, and how will the kernels move on it?

For more detail check the code:

input_layer = tf.keras.Input(shape=input_shape, name="Time_Series_Activity")
con_l1 = tf.keras.layers.Conv2D(64, (5, 1), activation="relu", data_format='channels_first')(input_layer)


Summary of Code

Layer (type)                 Output Shape              Param #
=================================================================
Time_Series_Activity (InputL [(None, 1, 30, 52)]       0
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 64, 26, 52)        384
_________________________________________________________________
{"ft_lang_label":"__label__en","ft_lang_prob":0.9068028,"math_prob":0.88103724,"size":2430,"snap":"2021-43-2021-49","text_gpt3_token_len":511,"char_repetition_ratio":0.22382523,"word_repetition_ratio":0.058651026,"special_character_ratio":0.2946502,"punctuation_ratio":0.15935335,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9657289,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-23T02:38:57Z\",\"WARC-Record-ID\":\"<urn:uuid:751238e4-f582-4dc8-a159-d8de1ce92066>\",\"Content-Length\":\"157882\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:752eb369-67dc-47ba-9edf-b36f24c2b7b7>\",\"WARC-Concurrent-To\":\"<urn:uuid:e3c25e68-9dfa-4e69-b0f2-fdd91c9c3cce>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://ai.stackexchange.com/questions/30145/what-would-be-the-advantage-of-making-channel-dimension-first-in-tensorflow-kera\",\"WARC-Payload-Digest\":\"sha1:YMKC5ZG3GB6K2ZCLH34LYILMG26VRH2H\",\"WARC-Block-Digest\":\"sha1:7N7DPGJEE5KP5HPSCCYSZOHDIE5WE525\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585537.28_warc_CC-MAIN-20211023002852-20211023032852-00507.warc.gz\"}"}