Search code examples
keraschanneldataformatimage-formats

Which data format convention in Keras (channels_last or channels_first) should be used when?


I'm a newbie in deep learning and confused which data format convention should be used when. According to the https://keras.io/backend/, there are two data format conventions.

channels_last for 2D data: (rows, cols, channels)
channels_first: for 2D data: (channels, rows, cols)

Why there is a channels_first option in Keras? When should I use it? Is there any historical reason like BGR usage in OpenCV?

" BGR was a choice made for historical reasons and now we have to live with it. In other words, BGR is the horse’s ass in OpenCV."
https://www.learnopencv.com/why-does-opencv-use-bgr-color-format/


Solution

  • I believe the reason that there are two data formats, is that Keras supports Theano as another backend too. In Theano, the first axis represents the channels.