Conviformers: Convolutionally guided Vision Transformer

Mohit Vaishnav, Thomas Fel, Ivan Felipe Rodríguez, Thomas Serre

Abstract

Vision transformers are nowadays the de-facto choice for image classification tasks. There are two broad categories of classification tasks, fine-grained and coarse-grained. In fine-grained classification, the necessity is to discover subtle differences due to the high level of similarity between sub-classes. Such distinctions are often lost as we downscale the image to save the memory and computational cost associated with vision transformers (ViT). In this work, we present an in-depth analysis and describe the critical components for developing a system for the fine-grained categorization of plants from herbarium sheets. Our extensive experimental analysis indicated the need for a better augmentation technique and the ability of modern-day neural networks to handle higher dimensional images. We also introduce a convolutional transformer architecture called Conviformer which, unlike the popular Vision Transformer (ConViT), can handle higher resolution images without exploding memory and computational cost. We also introduce a novel, improved pre-processing technique called PreSizer to resize images better while preserving their original aspect ratios, which proved essential for classifying natural plants. With our simple yet effective approach, we achieved SoTA on Herbarium 202x and iNaturalist 2019 dataset.

Introduction

Fine-grained image classification—the task of distinguishing between highly similar sub-classes, such as specific species of plants—is often described as a "game of pixels." Subtle morphological differences are the key to correct identification, but these details are frequently lost when images are downscaled to standard resolutions like $224 \times 224$ to accommodate the computational limits of deep learning models.

While Vision Transformers (ViTs) have revolutionized computer vision by capturing global dependencies, they face a significant hurdle in high-resolution tasks: computational complexity. The memory and compute requirements of a standard ViT grow quadratically with the number of input patches. To process the high-resolution data necessary for botanical specimens, a standard ViT would require prohibitive amounts of VRAM. This research introduces the Conviformer architecture and the PreSizer pre-processing technique to bridge the gap between high-resolution requirements and computational efficiency.

The Conviformer Architecture

The Conviformer is a hybrid "plug-and-play" model designed to handle high-resolution inputs without the typical "memory explosion" associated with transformers. It employs a convolutional block as a front-end that acts as a trainable downsampler, followed by a back-end based on the Convolutional Vision Transformer (ConViT).

Overview of the Conviformer architecture, featuring a convolutional front-end followed by a transformer back-end.

By using convolutions to reduce spatial dimensions before tokenization, the model can ingest high-resolution images (e.g., $512 \times 512$ or $600 \times 600$) while only processing a manageable number of patches. For instance, at a $512 \times 512$ resolution, a standard ConViT processes 1,024 patches, whereas the Conviformer processes only 256. This reduction allows the transformer to benefit from high-resolution features while maintaining a low memory footprint.

PreSizer: Intelligent Resizing

Standard resizing techniques often degrade the quality of botanical images by squashing features or introducing uninformative black padding. To address this, the authors developed PreSizer, a pre-processing method tailored for herbarium sheets.

Comparison of resizing techniques: (a) Reference, (b) Equal padding, and (c) the proposed PreSizer using reflective padding.

PreSizer first removes uninformative 20-pixel borders often found in scans. It then utilizes reflective padding to transform the image into a square format while strictly preserving the original aspect ratio. This ensures that the model learns from actual plant structures rather than artificial padding artifacts, leading to a measurable increase in classification accuracy.

Experimental Results and Insights

The researchers evaluated Conviformers on three large-scale, long-tailed datasets: iNaturalist 2019, Herbarium 2021, and Herbarium 2022. Several key insights emerged from the experiments:

  • Resolution is Critical: Increasing input resolution was the primary driver of performance. Moving from $224 \times 224$ to $512 \times 512$ resulted in a 14.72% accuracy boost on iNaturalist 2019.
  • Soft Inductive Bias: By incorporating convolutions at the start of the network, the model gains a "soft inductive bias" regarding spatial locality. This helps the transformer converge faster and perform more robustly, especially in lower-data regimes.
  • Taxonomic Regularization: Using hierarchical labels (Family, Genus, Species) during training acted as a powerful regularizer. Teaching the model taxonomic relationships prevented it from overfitting on noisy species-level features.

On the iNaturalist 2019 dataset, the Conviformer achieved 82.85% accuracy, significantly outperforming models like MAE (80.50%). In the Herbarium 2022 challenge, the combination of hierarchical labels and PreSizer reached an F1 score of 0.829, with an ensembled version reaching 0.868 on the private leaderboard, placing the team in the top 5.

Conclusion

Conviformers demonstrate that high-resolution fine-grained classification does not necessitate an exponential increase in computational cost. By intelligently combining the local feature extraction of CNNs with the global context of ViTs, and supporting them with specialized pre-processing like PreSizer, it is possible to achieve state-of-the-art results on complex botanical datasets. Future work may involve scaling this convolutional front-end to handle even larger gigapixel-scale images common in specialized fields like digital pathology.

Summary updated

BibTeX
@misc{vaishnav2022conviformers,
  author = {Mohit Vaishnav and Thomas Fel and Ivan Felipe Rodríguez and Thomas Serre},
  title = {{Conviformers: Convolutionally guided Vision Transformer}},
  year = {2022},
  eprint = {2208.08900},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2208.08900},
}
Figure