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






