liveBook · Manning

Channels-first convention

As explained in Deep Learning with R, Third Edition

A channels-first image format stores the color-channel axis before the spatial height and width axes.

The channels-first convention places an image’s color-channel axis immediately after the batch axis: (samples, channels, height, width). It contrasts with channels-last, which places channels at the end. section 2.2.8

For image batches, the convention changes the shape without changing the image content:

  • A batch of 128 grayscale 256 × 256 images uses (128, 1, 256, 256). section 2.2.8
  • A batch of 128 color 256 × 256 images uses (128, 3, 256, 256). section 2.2.8
  • Individual images are represented as (channels, height, width), rather than (height, width, channels). section 8.1

Configuring Keras

Keras supports both formats. Set config_set_image_data_format("channels_first") to change its default, or pass data_format to an individual convolution or pooling layer. Unless a specific need requires channels-first, the default can remain unchanged. section 8.1

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines dimension ordering with grayscale and color shapes, then stops short of explaining layout internals or performance consequences.
Examples
Uses grayscale and color image batches, plus convolutional and pooling layer format settings, to demonstrate the ordering.
What it assumes
Recognizes image tensors as height, width, and color-depth dimensions while treating batch shape notation as established.
What you can do after
Operate/configure Keras image pipelines with channels-first defaults or per-layer data-format settings.
How it connects
Connects image tensors, channels-last convention, convolutional layers, pooling layers, Keras, TensorFlow, JAX, and PyTorch.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.