A Dense Block with 2D Convolutions
Core Vision Operations DS practice problem on Onlearn.
Difficulty: hard.
Topics: Understanding Implement a Dense Block with 2D Convolutions, Dense Connectivity, Channel Concatenation, Zero-Padding, Growth Rate, NHWC Memory Layout, Computer Vision, Deep Learning, Numerical Computing, Software Engineering, Tensor Algebra, CNN Architectures, Feature Map Manipulation, Convolutional Operations, Activation Functions, Data Structure Validation.
Create a function dense net block that performs the forward pass of a DenseNet dense block on a batch of images stored in an NHWC NumPy tensor input data (shape (N, H, W, C0)). The block must run num layers iterations; at each iteration it should (i) apply ReLU to the running feature tensor, (ii) convolve it with the corresponding kernel from kernels (using stride 1, no bias, and symmetric zero padding so that H and W are preserved), and (iii) concatenate the convolution output (whose channel count equals growth rate) to the running tensor along the channel axis. Every kernel kernels[l] therefore has shape (kh, kw, C0 + l x growth rate, growth rate), where (kh, kw) equals kernel size (default (3, 3)). After the final layer the function must return a tensor of shape (N, H, W, C0 + num layers x growth rate). If any kernel's input channel dimension does not match the current feature map channels, the function should raise a ValueError.