{"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/sparse-spatial-transformers-for-few-shot","title":"Sparse Spatial Transformers for Few-Shot Learning","arxiv_id":"2109.12932","date":"2021-09-27","proceeding":null,"authors":["Haoxing Chen","Huaxiong Li","Yaohui Li","Chunlin Chen"],"abstract":"Learning from limited data is challenging because data scarcity leads to a poor generalization of the trained model. A classical global pooled representation will probably lose useful local information. Many few-shot learning methods have recently addressed this challenge using deep descriptors and learning a pixel-level metric. However, using deep descriptors as feature representations may lose image contextual information. Moreover, most of these methods independently address each class in the support set, which cannot sufficiently use discriminative information and task-specific embeddings. In this paper, we propose a novel transformer-based neural network architecture called sparse spatial transformers (SSFormers), which finds task-relevant features and suppresses task-irrelevant features. Particularly, we first divide each input image into several image patches of different sizes to obtain dense local features. These features retain contextual information while expressing local information. Then, a sparse spatial transformer layer is proposed to find spatial correspondence between the query image and the full support set to select task-relevant image patches and suppress task-irrelevant image patches. Finally, we propose using an image patch-matching module to calculate the distance between dense local representations, thus determining which category the query image belongs to in the support set. Extensive experiments on popular few-shot learning benchmarks demonstrate the superiority of our method over state-of-the-art methods. Our source code is available at \\url{https://github.com/chenhaoxing/ssformers}.","url_abs":"https://arxiv.org/abs/2109.12932v3","url_pdf":"https://arxiv.org/pdf/2109.12932v3.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":"sparse-spatial-transformers-for-few-shot","repo_url":"https://github.com/chenhaoxing/ssformers","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"few-shot-image-classification","task_name":"Few-Shot Image Classification"},{"task_slug":"few-shot-learning","task_name":"Few-Shot Learning"},{"task_slug":"patch-matching","task_name":"Patch Matching"}],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"spatial-transformer","method_name":"Spatial Transformer"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/few-shot-image-classification-on-cifar-fs-5","task":"Few-Shot Image Classification","dataset":"CIFAR-FS 5-way (1-shot)","model":"SSFormers","rank_in_archive_order":29,"of":38,"metrics":{"Accuracy":"74.5"},"uses_additional_data":false},{"leaderboard":"/sota/few-shot-image-classification-on-cifar-fs-5-1","task":"Few-Shot Image Classification","dataset":"CIFAR-FS 5-way (5-shot)","model":"SSFormers","rank_in_archive_order":27,"of":39,"metrics":{"Accuracy":"86.61"},"uses_additional_data":false},{"leaderboard":"/sota/few-shot-image-classification-on-fc100-5-way","task":"Few-Shot Image Classification","dataset":"FC100 5-way (1-shot)","model":"SSFormers","rank_in_archive_order":17,"of":22,"metrics":{"Accuracy":"43.72"},"uses_additional_data":false},{"leaderboard":"/sota/few-shot-image-classification-on-fc100-5-way-1","task":"Few-Shot Image Classification","dataset":"FC100 5-way (5-shot)","model":"SSFormers","rank_in_archive_order":17,"of":22,"metrics":{"Accuracy":"58.92"},"uses_additional_data":false},{"leaderboard":"/sota/few-shot-image-classification-on-mini-2","task":"Few-Shot Image Classification","dataset":"Mini-Imagenet 5-way (1-shot)","model":"SSFormers","rank_in_archive_order":47,"of":105,"metrics":{"Accuracy":"67.25"},"uses_additional_data":false},{"leaderboard":"/sota/few-shot-image-classification-on-mini-3","task":"Few-Shot Image Classification","dataset":"Mini-Imagenet 5-way (5-shot)","model":"SSFormers","rank_in_archive_order":38,"of":95,"metrics":{"Accuracy":"82.75"},"uses_additional_data":false},{"leaderboard":"/sota/few-shot-image-classification-on-tiered","task":"Few-Shot Image Classification","dataset":"Tiered ImageNet 5-way (1-shot)","model":"SSFormers","rank_in_archive_order":25,"of":49,"metrics":{"Accuracy":"72.52"},"uses_additional_data":false},{"leaderboard":"/sota/few-shot-image-classification-on-tiered-1","task":"Few-Shot Image Classification","dataset":"Tiered ImageNet 5-way (5-shot)","model":"SSFormers","rank_in_archive_order":25,"of":51,"metrics":{"Accuracy":"86.61"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2109.12932","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2109.12932"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+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/chenhaoxing/ssformers","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"unverified":6},"by_repo_kind":{"official":{"samples":6,"ran":0,"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":"c0aedf9b31c98a1e","entry":"batched_index_select","repo":"chenhaoxing/ssformers","repo_kind":"official","path":"modules/utils.py","file_url":"https://github.com/chenhaoxing/ssformers/blob/HEAD/modules/utils.py","link_basis":"first_harvest_node","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":"c0aedf9b31c98a1e"}},{"code_sha256_prefix":"6006bd806e56c499","entry":"l2distance","repo":"chenhaoxing/ssformers","repo_kind":"official","path":"modules/utils.py","file_url":"https://github.com/chenhaoxing/ssformers/blob/HEAD/modules/utils.py","link_basis":"first_harvest_node","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":"6006bd806e56c499"}},{"code_sha256_prefix":"71f8406f0baba76c","entry":"make_fsl","repo":"chenhaoxing/ssformers","repo_kind":"official","path":"modules/fsl_query.py","file_url":"https://github.com/chenhaoxing/ssformers/blob/HEAD/modules/fsl_query.py","link_basis":"first_harvest_node","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":"71f8406f0baba76c"}},{"code_sha256_prefix":"5f1075c9097df6f9","entry":"make_pretrain_model","repo":"chenhaoxing/ssformers","repo_kind":"official","path":"modules/pretrain_model.py","file_url":"https://github.com/chenhaoxing/ssformers/blob/HEAD/modules/pretrain_model.py","link_basis":"first_harvest_node","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":"5f1075c9097df6f9"}},{"code_sha256_prefix":"61a7d5e666a9cc01","entry":"make_semi_fsl","repo":"chenhaoxing/ssformers","repo_kind":"official","path":"modules/fsl_semi_query.py","file_url":"https://github.com/chenhaoxing/ssformers/blob/HEAD/modules/fsl_semi_query.py","link_basis":"first_harvest_node","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":"61a7d5e666a9cc01"}},{"code_sha256_prefix":"a0c812453b8c2180","entry":"multihot_embedding","repo":"chenhaoxing/ssformers","repo_kind":"official","path":"modules/utils.py","file_url":"https://github.com/chenhaoxing/ssformers/blob/HEAD/modules/utils.py","link_basis":"first_harvest_node","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":"a0c812453b8c2180"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}