liveBook · Manning

Channel

As explained in Math and Architectures of Deep Learning

A channel dimension in a tensor that separates different input feature maps or image channels.

A channel is a tensor dimension that separates input feature maps or image channels. In a 2D convolution, PyTorch arranges input data as N × C × H × W: batch size, channels, height, and width. RGB input has C = 3 for red, green, and blue; grayscale input has C = 1. Deeper layers may use any channel count, whose values usually represent learned features rather than visible colors. section 10.3.3

Channels determine how convolutional kernels read and combine feature maps:

  • A 3D-convolution input uses N × C × D × H × W, adding sequence depth D while retaining the input-channel dimension C. section 10.4.2
  • A kernel has one separate spatial-temporal brick for each input channel and combines them through a weighted sum. section 10.4.2
  • For 3D convolution, weights use C_out × C_in × kT × kH × kW; C_in must match the input channel count, while C_out determines output channels. section 10.4.2
Listing 10.4 PyTorch code for 2D local averaging convolution
import torch

x = load_img()                                             #1

w = torch.tensor(                                          #2
    [
        [0.11, 0.11, 0.11],
        [0.11, 0.11, 0.11],
        [0.11, 0.11, 0.11]
    ]
)

x = x.unsqueeze(0).unsqueeze(0)                            #3
w = w.unsqueeze(0).unsqueeze(0)

conv2d = torch.nn.Conv2d(1, 1, kernel_size=2,
                    stride=1, bias=False)                  #4

conv2d.weight = torch.nn.Parameter(w, requires_grad=False) #5


with torch.no_grad():                                      #6


    y = conv2d(x)                                          #7

Shows how singleton batch and channel dimensions are added before applying a fixed PyTorch Conv2d kernel. section 10.3.3

Grayscale motion input

A sequence of five 320 × 320 grayscale frames has N = 1, C = 1, D = 5, H = 320, and W = 320. A single 3D filter therefore consumes one input channel and produces one output channel. section 10.4.2

How Math and Architectures of Deep Learning covers it

How deep it goes
Defines channels within 2D and 3D tensor layouts and kernel shapes, stopping short of training learned channel representations.
Examples
Uses RGB and grayscale images, a fixed 2D averaging kernel, and a five-frame grayscale motion detector.
What you can do after
Apply via PyTorch by shaping inputs as N × C × H × W or N × C × D × H × W and matching kernel channel dimensions.
How it connects
Connects channels to tensors, convolution, kernels, batch size, RGB images, grayscale images, and feature maps.

Also explained in

Compare how 7 books explain channel →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math and Architectures of Deep Learning. The section links point to the parts of the book it draws on.