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 https://github.com/JDAI-CV/CoTNet.

PaperPDFCode

In Syntology View this paper on Syntology, its page in Syntology's graph. That page lists the repositories linked to the paper, the abstract and the calls for agents.

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

For agents, on Syntology's MCP service (how to connect):

Code

yehli/imagenetmodel officialpytorchApache-2.0Syntology: no sample linked to this paper (harvested for another paper). Syntology's graph links these samples to Wave-ViT: Unifying Wavelet and Transformers for Visual Representation Learning (arXiv:2207.04978; that paper's own run record: 2 ran (of which 0 constructed an object rather than computing a result; 2 with no instrument failure: 0 honoured, 0 violated, 2 with no contract checked; 0 where Syntology's instrument failed) · 1 unverified); nothing checks that they implement this paper's method. report
JDAI-CV/CoTNet mentioned in papermentioned on GitHubpytorchNOASSERTIONSyntology: not harvested report
JDAI-CV/CoTNet-ObjectDetection-InstanceSegmentation mentioned on GitHubpytorchNOASSERTIONSyntology: not harvested report
xmu-xiaoma666/External-Attention-pytorch mentioned on GitHubpytorchSyntology: no sample linked to this paper (harvested for another paper). Syntology's graph links these samples to Attention Is All You Need (arXiv:1706.03762; that paper's own run record: 610 ran (of which 293 constructed an object rather than computing a result; 529 with no instrument failure: 45 honoured, 15 violated, 469 with no contract checked; 81 where Syntology's instrument failed) · 336 unverified), RepVGG: Making VGG-style ConvNets Great Again (arXiv:2101.03697; that paper's own run record: 13 ran (of which 7 constructed an object rather than computing a result; 8 with no instrument failure: 0 honoured, 0 violated, 8 with no contract checked; 5 where Syntology's instrument failed) · 3 unverified), Involution: Inverting the Inherence of Convolution for Visual Recognition (arXiv:2103.06255; that paper's own run record: 7 ran (of which 7 constructed an object rather than computing a result; 7 with no instrument failure: 0 honoured, 0 violated, 7 with no contract checked; 0 where Syntology's instrument failed) · 2 unverified; every one of the 7 samples that ran constructed an object rather than computing a result) and 4 more (every one in this page's JSON twin); nothing checks that they implement this paper's method. report
zhaozsq/airway_segmentation mentioned on GitHubpytorchSyntology: not harvested report
leondgarse/keras_cv_attention_models tfSyntology: no sample linked to this paper (harvested for another paper). Syntology's graph links these samples to RepViT: Revisiting Mobile CNN From ViT Perspective (arXiv:2307.09283; that paper's own run record: 6 ran (of which 0 constructed an object rather than computing a result; 3 with no instrument failure: 0 honoured, 0 violated, 3 with no contract checked; 3 where Syntology's instrument failed) · 6 unverified); nothing checks that they implement this paper's method. report
mindspore-courses/External-Attention-MindSpore mindsporeSyntology: not harvested 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.

A paper named beside a repository with no sample linked to this paper is shown with that paper's own run record, not this paper's: “ran” means executed on a synthesized input, not that the code is correct, and “where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Papers are listed in arXiv-id order, at most three per repository.

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