Fused-Layer CNNs for Memory-Efficient Inference on Microcontrollers

Mark Deutel, Frank Hannig, Christopher Mutschler, Jürgen TeichCompression @ NeurIPS 2024

TL;DR

This paper introduces a novel layer fusion technique for convolutional neural networks (CNNs) specifically designed for memory-constrained microcontrollers (MCUs). By fusing multiple convolutional layers within inverted residual blocks, they achieve significant memory reductions (up to 54%) without sacrificing accuracy, enabling higher-resolution image processing on MCUs.

What Problem Does This Paper Address?

Deploying sophisticated computer vision models, particularly Convolutional Neural Networks (CNNs), on resource-limited microcontrollers (MCUs) is a significant challenge. MCUs, commonly found in embedded systems and IoT devices, have severe constraints on both memory (RAM) and processing power. While CNNs excel at image analysis, their intermediate feature maps can be very large, quickly exceeding the available RAM on MCUs, especially when processing high-resolution images. This limitation restricts the complexity and resolution of vision tasks that can be performed directly on the edge device. The paper aims to bridge this gap by optimizing CNN inference for MCUs, specifically targeting the memory bottleneck.

Methods

The core contribution of this paper is a layer fusion method for inverted residual blocks in quantized CNNs. Inverted residual blocks, a key component of architectures like MobileNetV2, consist of three convolutional layers: a 1x1 expansion convolution, a 3x3 depthwise convolution, and a 1x1 projection convolution. The authors propose to fuse these three layers into a single computational unit.

This fusion is achieved by adapting a tiling approach commonly used in hardware accelerators. Instead of computing entire feature maps layer by layer, the output feature map is divided into smaller tiles. These tiles can then be computed sequentially, allowing for the reuse of memory. This significantly reduces the amount of intermediate data that needs to be stored at any given time.

Crucially, the authors note that while this tiling can introduce some latency due to recomputing intermediate results for overlapping tile boundaries, they strategically apply this fusion only to the early, memory-intensive inverted residual blocks. This approach aims to maximize memory savings while minimizing the impact on overall inference latency. They also incorporate standard techniques like folding Batchnorm and ReLU layers into preceding convolutions as part of the quantization process.

Datasets

The paper evaluates their approach on three standard vision datasets:

  • CIFAR10: Used with 128x128 pixel images.
  • GTSRB (German Traffic Sign Recognition Benchmark): Used with 256x256 pixel images.
  • Flowers: Used with 320x320 pixel images.

These datasets were used to train and evaluate two CNN architectures: a generic MobileNetV2-like CNN and MCUNet, a CNN specifically designed for MCU deployment.

Key Insights and Ideas

  • Targeting the Bottleneck: The paper highlights that the primary memory bottleneck in CNNs on MCUs lies in the early layers due to large intermediate feature maps. By focusing fusion efforts on these specific layers, significant memory savings can be achieved without drastically increasing latency.
  • Fusion for Memory, Not Just Speed: While layer fusion is often used for speedups, this work demonstrates its critical role in enabling deployment on memory-constrained devices, even if it slightly increases latency.
  • Strategic Fusion: Applying fusion only to a subset of inverted residual blocks (the initial ones) is a key strategy to balance memory reduction and latency increase.
  • Flexibility of Inverted Residual Blocks: The "narrow-wide-narrow" structure of inverted residual blocks makes them particularly amenable to fusion, as it allows for the reduction of the "wide" intermediate feature maps.

Key Results

  • Memory Reduction: The proposed layer fusion method achieved memory savings of up to 54% for inference.
  • Accuracy: The fusion technique resulted in no change in accuracy.
  • Latency Increase: The cost of this optimization was a relatively small increase in latency of about 14%.
  • Higher Resolution Support: This memory optimization enabled the deployment of image processing pipelines on a Cortex-M7 MCU supporting image resolutions up to 320x320 pixels, a significant improvement over the commonly used 128x128 pixels in related work.
  • Compression Factor: For MCUNet on CIFAR10, they achieved a 2.1x reduction in memory requirements, which is higher than previous approaches (1.6x).

Limitations and Future Work

  • Runtime Dependency: The authors acknowledge that layer fusion requires explicit implementation within the runtime system used for CNN execution on the MCU. This can limit the flexibility of designing CNN architectures, as each fused layer combination needs to be supported by the runtime.
  • Co-design Requirement: The technique necessitates a degree of co-design between the CNN architecture and the runtime, which can restrict the design space.
  • Future Work: The paper suggests that their approach is effective for well-defined blocks like inverted residual blocks, which are common starting points for MCU-focused CNNs. Future work could explore extending this to other layer types or more complex fusion strategies. The paper also mentions an algorithm for automatically finding the optimal number of blocks to fuse, which could be further refined.

Summary updated

BibTeX
@inproceedings{deutel2024fused,
  author = {Mark Deutel and Frank Hannig and Christopher Mutschler and Jürgen Teich},
  title = {{Fused-Layer CNNs for Memory-Efficient Inference on Microcontrollers}},
  booktitle = {Compression @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=2O8qbyxH6X},
}
Figure