{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/localvit-bringing-locality-to-vision","title":"LocalViT: Bringing Locality to Vision Transformers","arxiv_id":"2104.05707","date":"2021-04-12","proceeding":null,"authors":["Yawei Li","Kai Zhang","JieZhang Cao","Radu Timofte","Luc van Gool"],"abstract":"We study how to introduce locality mechanisms into vision transformers. The transformer network originates from machine translation and is particularly good at modelling long-range dependencies within a long sequence. Although the global interaction between the token embeddings could be well modelled by the self-attention mechanism of transformers, what is lacking a locality mechanism for information exchange within a local region. Yet, locality is essential for images since it pertains to structures like lines, edges, shapes, and even objects. We add locality to vision transformers by introducing depth-wise convolution into the feed-forward network. This seemingly simple solution is inspired by the comparison between feed-forward networks and inverted residual blocks. The importance of locality mechanisms is validated in two ways: 1) A wide range of design choices (activation function, layer placement, expansion ratio) are available for incorporating locality mechanisms and all proper choices can lead to a performance gain over the baseline, and 2) The same locality mechanism is successfully applied to 4 vision transformers, which shows the generalization of the locality concept. In particular, for ImageNet2012 classification, the locality-enhanced transformers outperform the baselines DeiT-T and PVT-T by 2.6\\% and 3.1\\% with a negligible increase in the number of parameters and computational effort. Code is available at \\url{https://github.com/ofsoundof/LocalViT}.","url_abs":"https://arxiv.org/abs/2104.05707v1","url_pdf":"https://arxiv.org/pdf/2104.05707v1.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"localvit-bringing-locality-to-vision","repo_url":"https://github.com/ofsoundof/LocalViT","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"localvit-bringing-locality-to-vision","repo_url":"https://github.com/rishikksh20/LocalViT-pytorch","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"image-classification","task_name":"Image Classification"}],"methods":[{"method_slug":"convolution","method_name":"Convolution"},{"method_slug":"localvit","method_name":"LocalViT"}],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/image-classification-on-imagenet","task":"Image Classification","dataset":"ImageNet","model":"LocalViT-S","rank_in_archive_order":681,"of":1060,"metrics":{"GFLOPs":"4.6","Number of params":"22.4M","Top 1 Accuracy":"80.8%"},"uses_additional_data":false},{"leaderboard":"/sota/image-classification-on-imagenet","task":"Image Classification","dataset":"ImageNet","model":"LocalViT-PVT","rank_in_archive_order":847,"of":1060,"metrics":{"GFLOPs":"4.8","Number of params":"13.5M","Top 1 Accuracy":"78.2%"},"uses_additional_data":false},{"leaderboard":"/sota/image-classification-on-imagenet","task":"Image Classification","dataset":"ImageNet","model":"LocalViT-TNT","rank_in_archive_order":931,"of":1060,"metrics":{"GFLOPs":"1.4","Number of params":"6.3M","Top 1 Accuracy":"75.9%"},"uses_additional_data":false},{"leaderboard":"/sota/image-classification-on-imagenet","task":"Image Classification","dataset":"ImageNet","model":"LocalViT-T","rank_in_archive_order":969,"of":1060,"metrics":{"GFLOPs":"1.3","Number of params":"5.9M","Top 1 Accuracy":"74.8%"},"uses_additional_data":false},{"leaderboard":"/sota/image-classification-on-imagenet","task":"Image Classification","dataset":"ImageNet","model":"LocalViT-T2T","rank_in_archive_order":997,"of":1060,"metrics":{"GFLOPs":"1.2","Number of params":"4.3M","Top 1 Accuracy":"72.5%"},"uses_additional_data":false}],"syntology":{"syntology_url":"https://syntology.ai/paper/2104.05707","atlas_url":"https://app.syntology.ai/?focus=2104.05707","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2104.05707"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/rishikksh20/LocalViT-pytorch","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ofsoundof/LocalViT","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran_draft_wrong":2,"ran_fixture":1,"unverified":3},"by_repo_kind":{"official":{"samples":6,"ran":3,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"ad708b63b59159a6","entry":"flops_to_string","repo":"ofsoundof/LocalViT","repo_kind":"official","path":"flops_counter.py","file_url":"https://github.com/ofsoundof/LocalViT/blob/HEAD/flops_counter.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ad708b63b59159a6"}},{"code_sha256_prefix":"f9fd6241d935f07b","entry":"window_partition","repo":"ofsoundof/LocalViT","repo_kind":"official","path":"models/swin_transformer.py","file_url":"https://github.com/ofsoundof/LocalViT/blob/HEAD/models/swin_transformer.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f9fd6241d935f07b"}},{"code_sha256_prefix":"fb32094c6dbece71","entry":"window_reverse","repo":"ofsoundof/LocalViT","repo_kind":"official","path":"models/swin_transformer.py","file_url":"https://github.com/ofsoundof/LocalViT/blob/HEAD/models/swin_transformer.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"fb32094c6dbece71"}},{"code_sha256_prefix":"9153241c4331eb1a","entry":"build_dataset","repo":"ofsoundof/LocalViT","repo_kind":"official","path":"datasets.py","file_url":"https://github.com/ofsoundof/LocalViT/blob/HEAD/datasets.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9153241c4331eb1a"}},{"code_sha256_prefix":"3bc74137ab36aa79","entry":"build_transform","repo":"ofsoundof/LocalViT","repo_kind":"official","path":"datasets.py","file_url":"https://github.com/ofsoundof/LocalViT/blob/HEAD/datasets.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3bc74137ab36aa79"}},{"code_sha256_prefix":"ddea91f7dddc66e6","entry":"params_to_string","repo":"ofsoundof/LocalViT","repo_kind":"official","path":"flops_counter.py","file_url":"https://github.com/ofsoundof/LocalViT/blob/HEAD/flops_counter.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ddea91f7dddc66e6"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}