Abstract
Modern convolutional neural networks apply the same operations on every pixel in an image. However, not all image regions are equally important. To address this inefficiency, we propose a method to dynamically apply convolutions conditioned on the input image. We introduce a residual block where a small gating branch learns which spatial positions should be evaluated. These discrete gating decisions are trained end-to-end using the Gumbel-Softmax trick, in combination with a sparsity criterion. Our experiments on CIFAR, ImageNet and MPII show that our method has better focus on the region of interest and better accuracy than existing methods, at a lower computational complexity. Moreover, we provide an efficient CUDA implementation of our dynamic convolutions using a gather-scatter approach, achieving a significant improvement in inference speed with MobileNetV2 residual blocks. On human pose estimation, a task that is inherently spatially sparse, the processing speed is increased by 60% with no loss in accuracy.
Introduction
In the field of computer vision, standard Convolutional Neural Networks (CNNs) traditionally treat every pixel as equally important. Whether a pixel is part of a complex human face or a uniform background, a standard CNN spends the same amount of computational cycles on it. This uniform processing is inherently inefficient, especially for tasks where the region of interest is small relative to the total image area.
In this work, we argue that this "one-size-fits-all" approach to spatial computation is unnecessary. We propose Dynamic Convolutions (DynConv), a method that allows neural networks to "glance" at an image, decide which parts are interesting, and only perform heavy computations on those specific regions. By skipping the "boring" pixels, we can significantly reduce inference time without sacrificing model performance.
Methodology: The Dynamic Residual Block
The core of our approach is the Dynamic Convolutional Residual Block. This block consists of two main components: a standard residual branch and a lightweight Mask Unit.
Spatial Masking and Gumbel-Softmax
The Mask Unit is a tiny branch added to each residual block that predicts a binary mask (0 or 1) for every pixel location. To enable end-to-end training with these discrete decisions, we utilize the Gumbel-Softmax trick. This allows the network to learn gating decisions during training as if they were continuous values, while still producing hard binary masks during inference.
Efficient GPU Implementation
Theoretical reductions in operations (FLOPs) often fail to translate into actual speedups on GPUs due to the overhead of irregular memory access. To bridge this gap, we developed a custom CUDA implementation using a gather-scatter approach. This kernel "gathers" the active pixels into a dense matrix for efficient processing and then "scatters" the results back to their original positions. This ensures that the theoretical efficiency of spatial sparsity results in tangible wall-clock speedups.
Experiments and Results
We evaluated DynConv across several standard benchmarks, including CIFAR-10, ImageNet, and MPII Human Pose estimation.
Image Classification Performance
On CIFAR-10 and ImageNet, DynConv consistently outperformed previous spatial-adaptive methods such as SACT and ConvNet-AIG. As shown in the performance plots, our method provides a superior trade-off between Top-1 accuracy and computational cost (MACs), effectively pushing the Pareto frontier of efficient image classification.
Human Pose Estimation
Human pose estimation is a task that is inherently spatially sparse, as the subjects usually occupy only a small fraction of the frame. By applying DynConv to the MPII dataset, we achieved a 60% increase in processing speed (85 images/sec vs 30 images/sec for the baseline) with zero loss in accuracy. The network naturally learns to focus exclusively on the human figure, ignoring the static background.
Conclusion
Dynamic Convolutions offer a robust framework for exploiting spatial sparsity in deep learning. By combining learnable masking with an optimized CUDA implementation, we demonstrate that it is possible to achieve significant inference speedups on real hardware. This method is particularly well-suited for high-resolution images and video processing, where the ratio of informative pixels to background is often very high. Future work will explore the application of this technique to object detection and real-time video segmentation.
Summary updated