ClassFormer: Exploring Class-Aware Dependency with Transformer for Medical Image Segmentation

Huimin Huang, Shiao Xie, Lanfen Lin, Ruofeng Tong, Yen-Wei Chen, Hong Wang, Yuexiang Li, Yawen Huang, Yefeng Zheng

Introduction

Vision Transformers (ViTs) have significantly advanced medical image segmentation by capturing long-range dependencies that traditional Convolutional Neural Networks (CNNs) often miss. However, standard ViTs typically process images as class-agnostic patches, leading to two major limitations in multi-organ segmentation: the intra-class problem and the inter-class problem.

The intra-class problem refers to the failure to extract specific correspondences between pixels of the same category, resulting in fragmented boundaries or "incompact" object representations. The inter-class problem arises when models fail to account for the explicit spatial and semantic relationships between different organs, leading to category confusion (e.g., misclassifying parts of the stomach as the spleen due to proximity or texture similarity).

Conceptual overview of intra-class and inter-class dependency modeling in ClassFormer.

Methodology

ClassFormer addresses these challenges by introducing a two-stage sequential architecture designed to be integrated into the decoder of standard segmentation networks. The framework shifts the focus from global, class-agnostic attention to targeted, class-aware dependency modeling.

1. Intra-Class Dynamic Transformer

This module decouples feature maps into category-specific representations to refine the internal structure of each organ. It employs a Saliency-aware Selection network to identify the most informative pixels for each class. To accommodate organs of varying sizes, a Pyramid Mechanism samples these salient keys across multiple scales using different window sizes. This approach allows the model to capture fine-grained details for small structures and global context for larger ones. By attending only to these selected salient keys, ClassFormer avoids the quadratic computational complexity ($O(N^2)$) of standard Transformers.

2. Inter-Class Interactive Transformer

Following the intra-class refinement, this module models the relationships between different categories. It calculates "Class Tokens" (centers) for each organ by averaging features weighted by their predicted probabilities. These tokens interact with patch tokens via cross-attention, enabling the model to learn spatial logic (e.g., the liver's typical adjacency to the stomach). To further reduce inter-class confusion, an auxiliary Euclidean Distance Loss ($L_{EU}$) is introduced to maximize the separation between different class centers in the feature space.

The overall architecture of ClassFormer, featuring the Intra-Class Dynamic Transformer and the Inter-Class Interactive Transformer.

Evaluation and Results

ClassFormer was evaluated on three major benchmarks: Synapse (multi-organ CT), ACDC (cardiac MRI), and MoNuSeg (nucleus segmentation).

On the Synapse dataset, ClassFormer established a new state-of-the-art (SOTA) performance:

  • Dice Similarity Coefficient (DSC): Reached 84.40%, surpassing previous leaders like ScaleFormer (82.86%) and SwinUNet (79.12%).
  • Hausdorff Distance (HD): Significantly reduced boundary error to 12.22mm, compared to 16.81mm for ScaleFormer.
  • Efficiency: The model is relatively lightweight with 35.43M parameters, a substantial reduction from ScaleFormer's 111.58M parameters.

Qualitative results demonstrate that ClassFormer produces much sharper boundaries and eliminates the "islands" of misclassified pixels common in earlier Transformer-based models like TransUNet.

Discussion and Conclusion

The success of ClassFormer highlights that decoupling feature maps into independent classes before applying attention leads to more stable and accurate learning. The sequential "Intra-then-Inter" arrangement ensures that the model first understands the internal structure of an organ before reasoning about its relationship to its neighbors.

While currently focused on 2D slices, the plug-and-play nature of ClassFormer makes it a versatile candidate for integration with various backbones and potential extension to 3D medical imaging tasks. By making Transformers "aware" of class-level dependencies, ClassFormer sets a new standard for precision and efficiency in medical image segmentation.

Summary updated

BibTeX
@inproceedings{huang2023classformer,
  author = {Huimin Huang and Shiao Xie and Lanfen Lin and Ruofeng Tong and Yen-Wei Chen and Hong Wang and Yuexiang Li and Yawen Huang and Yefeng Zheng},
  title = {{ClassFormer: Exploring Class-Aware Dependency with Transformer for Medical Image Segmentation}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2023},
  doi = {10.1609/aaai.v37i1.25171},
}
Figure