Papers › Contextual Transformer Networks for Visual Recognition

Contextual Transformer Networks for Visual Recognition

26 Jul 2021arXiv:2107.12292archive 2025-07-28

Yehao Li, Ting Yao, Yingwei Pan, Tao Mei

Transformer with self-attention has led to the revolutionizing of natural language processing field, and recently inspires the emergence of Transformer-style architecture design with competitive results in numerous computer vision tasks. Nevertheless, most of existing designs directly employ self-attention over a 2D feature map to obtain the attention matrix based on pairs of isolated queries and keys at each spatial location, but leave the rich contexts among neighbor keys under-exploited. In this work, we design a novel Transformer-style module, i.e., Contextual Transformer (CoT) block, for visual recognition. Such design fully capitalizes on the contextual information among input keys to guide the learning of dynamic attention matrix and thus strengthens the capacity of visual representation. Technically, CoT block first contextually encodes input keys via a 3×3 convolution, leading to a static contextual representation of inputs. We further concatenate the encoded keys with input queries to learn the dynamic multi-head attention matrix through two consecutive 1×1 convolutions. The learnt attention matrix is multiplied by input values to achieve the dynamic contextual representation of inputs. The fusion of the static and dynamic contextual representations are finally taken as outputs. Our CoT block is appealing in the view that it can readily replace each 3×3 convolution in ResNet architectures, yielding a Transformer-style backbone named as Contextual Transformer Networks (CoTNet). Through extensive experiments over a wide range of applications (e.g., image recognition, object detection and instance segmentation), we validate the superiority of CoTNet as a stronger backbone. Source code is available at \url{https://github.com/JDAI-CV/CoTNet}.

PaperPDFCode

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

Code

yehli/imagenetmodel officialpytorchApache-2.0 report
JDAI-CV/CoTNet mentioned in papermentioned on GitHubpytorchNOASSERTION report
JDAI-CV/CoTNet-ObjectDetection-InstanceSegmentation mentioned on GitHubpytorchNOASSERTION report
zhaozsq/airway_segmentation mentioned on GitHubpytorch report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

Not run by Syntology. Nothing on this page verifies that the listed code works.

Tasks

Image ClassificationInstance SegmentationObject DetectionSemantic Segmentationobject-detection

Results from the paper archive 2025-07-28

TaskDatasetModelMetricValueRank at snapshotLeaderboardReport
Image Classification ImageNet SE-CoTNetD-152 GFLOPs 26.5 #304 of 1060 Archive leaderboard report
Image Classification ImageNet SE-CoTNetD-152 Number of params 55.8M #304 of 1060 Archive leaderboard report
Image Classification ImageNet SE-CoTNetD-152 Top 1 Accuracy 84.6% #304 of 1060 Archive leaderboard report
Image Classification ImageNet SE-CoTNetD-101 GFLOPs 8.5 #455 of 1060 Archive leaderboard report
Image Classification ImageNet SE-CoTNetD-101 Number of params 40.9M #455 of 1060 Archive leaderboard report
Image Classification ImageNet SE-CoTNetD-101 Top 1 Accuracy 83.2% #455 of 1060 Archive leaderboard report
Image Classification ImageNet SE-CoTNetD-50 GFLOPs 4.1 #626 of 1060 Archive leaderboard report
Image Classification ImageNet SE-CoTNetD-50 Number of params 23.1M #626 of 1060 Archive leaderboard report
Image Classification ImageNet SE-CoTNetD-50 Top 1 Accuracy 81.6% #626 of 1060 Archive leaderboard report

Ranks are positions in the archive's leaderboards as they stood at the 2025-07-28 snapshot. Results published since then are not among these rows, so a rank here is not a current standing.

Methods

1x1 ConvolutionAbsolute Position EncodingsAdamAttentionAverage PoolingBPEBatch NormalizationBottleneck Residual BlockConvolutionDense ConnectionsDropoutGlobal Average PoolingKaiming InitializationLabel SmoothingLayer NormalizationLinear LayerMax PoolingMulti-Head AttentionPosition-Wise Feed-Forward LayerReLUResidual BlockResidual ConnectionSoftmaxTransformer

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections