Skip to main content
QUICK REVIEW

[Paper Review] Dynamic Grained Encoder for Vision Transformers

Lin Song, Songyang Zhang|arXiv (Cornell University)|Jan 10, 2023
Multimodal Machine Learning ApplicationsComputer Science11 citations
TL;DR

A dynamic grained encoder (DGE) assigns region-dependent numbers of queries in vision transformers, reducing computation by 40-60% while preserving accuracy, and improving performance on certain tasks.

ABSTRACT

Transformers, the de-facto standard for language modeling, have been recently applied for vision tasks. This paper introduces sparse queries for vision transformers to exploit the intrinsic spatial redundancy of natural images and save computational costs. Specifically, we propose a Dynamic Grained Encoder for vision transformers, which can adaptively assign a suitable number of queries to each spatial region. Thus it achieves a fine-grained representation in discriminative regions while keeping high efficiency. Besides, the dynamic grained encoder is compatible with most vision transformer frameworks. Without bells and whistles, our encoder allows the state-of-the-art vision transformers to reduce computational complexity by 40%-60% while maintaining comparable performance on image classification. Extensive experiments on object detection and segmentation further demonstrate the generalizability of our approach. Code is available at https://github.com/StevenGrove/vtpack.

Motivation & Objective

  • Motivate reducing spatial redundancy in vision transformers by exploiting image regions with varying informativeness.
  • Propose a dynamic, region-based router to assign mixed-granularity patches as sparse queries.
  • Ensure compatibility with standard vision transformer blocks and end-to-end trainability.
  • Demonstrate efficiency-accuracy trade-offs across image classification, object detection, and semantic segmentation.

Proposed method

  • Introduce Dynamic Grained Encoder (DGE) that replaces standard encoders with a dynamic grained router plus a vanilla encoder block.
  • Partition a 2D feature into fixed SxS regions and select a region-specific granularity from a candidate set Phi via a gating network.
  • Compute region tokens by average-pooling patches of the chosen granularity to form sparse queries for the transformer.
  • Restore output to the original resolution with un-pooling and fuse with a residual connection.
  • Train with a Gumbel-Softmax-based stochastic gating and a budget constraint that targets a desired computation ratio gamma.
  • Optionally allow region-wise or layer-wise routing, with region-wise gating showing performance gains.
Figure 1: The overall diagram of the proposed dynamic grained encoder. $\mathbf{x}$ is the input sequence, and $\mathbf{y}$ is the output sequence. The dynamic grained router automatically split a 2D feature into mixed-grained patches with a different number of tokens in a patch. Each patch is then
Figure 1: The overall diagram of the proposed dynamic grained encoder. $\mathbf{x}$ is the input sequence, and $\mathbf{y}$ is the output sequence. The dynamic grained router automatically split a 2D feature into mixed-grained patches with a different number of tokens in a patch. Each patch is then

Experimental results

Research questions

  • RQ1Can vision transformers achieve substantial computation savings by using region-adaptive, mixed-granularity queries?
  • RQ2How does a data-dependent routing strategy affect accuracy and efficiency across classification, detection, and segmentation tasks?
  • RQ3Is region-wise dynamic granularity more effective than layer-wise dynamic control in vision transformers?
  • RQ4What is the impact of a computational budget constraint on model performance and speed?
  • RQ5How well does DGE generalize across different backbone architectures (DeiT, PVT, DPVT) and downstream tasks?

Key findings

  • Dynamic Grained Encoder reduces FLOPs by about 40-60% in image classification while maintaining comparable accuracy.
  • Budget-constrained DGE can achieve similar or better accuracy at about half the compute, depending on configuration.
  • Region-wise routing provides about 1.1% absolute gain over layer-wise routing at similar complexity.
  • Foreground regions receive more queries, enabling fine-grained representation where it matters most.
  • DGE improves downstream task performance (object detection and semantic segmentation) with notable FLOPs reductions across backbones.
  • On ADE-20K, DPVT/ PVT with DGE achieve competitive mIoU with substantial FLOPs reductions (up to ~30%).
(b) Accuracy v.s. Complexity
(b) Accuracy v.s. Complexity

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.