Code

Multi-Channel Cross-Correlation Code Implementation

A multi-channel cross-correlation operation can be implemented programmatically by iterating through the channel dimension of both the input tensor and the kernel tensor. For each individual channel, a standard two-dimensional cross-correlation is executed between the corresponding two-dimensional slices of the input and the kernel. Finally, the resulting two-dimensional output tensors from all channels are summed together to produce the final output. The following Python snippet illustrates this logic:

def corr2d_multi_in(X, K): # Iterate through the 0th dimension (channel) of K first, then add them up return sum(d2l.corr2d(x, k) for x, k in zip(X, K))

0

1

Updated 2026-05-12

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L