{"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/contrastive-test-time-adaptation","title":"Contrastive Test-Time Adaptation","arxiv_id":"2204.10377","date":"2022-04-21","proceeding":"CVPR 2022 1","authors":["Dian Chen","Dequan Wang","Trevor Darrell","Sayna Ebrahimi"],"abstract":"Test-time adaptation is a special setting of unsupervised domain adaptation where a trained model on the source domain has to adapt to the target domain without accessing source data. We propose a novel way to leverage self-supervised contrastive learning to facilitate target feature learning, along with an online pseudo labeling scheme with refinement that significantly denoises pseudo labels. The contrastive learning task is applied jointly with pseudo labeling, contrasting positive and negative pairs constructed similarly as MoCo but with source-initialized encoder, and excluding same-class negative pairs indicated by pseudo labels. Meanwhile, we produce pseudo labels online and refine them via soft voting among their nearest neighbors in the target feature space, enabled by maintaining a memory queue. Our method, AdaContrast, achieves state-of-the-art performance on major benchmarks while having several desirable properties compared to existing works, including memory efficiency, insensitivity to hyper-parameters, and better model calibration. Project page: sites.google.com/view/adacontrast.","url_abs":"https://arxiv.org/abs/2204.10377v1","url_pdf":"https://arxiv.org/pdf/2204.10377v1.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":"contrastive-test-time-adaptation","repo_url":"https://github.com/DianCh/AdaContrast","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"contrastive-learning","task_name":"Contrastive Learning"},{"task_slug":"domain-adaptation","task_name":"Domain Adaptation"},{"task_slug":"test-time-adaptation","task_name":"Test-time Adaptation"},{"task_slug":"unsupervised-domain-adaptation","task_name":"Unsupervised Domain Adaptation"}],"methods":[{"method_slug":"batch-normalization","method_name":"Batch Normalization"},{"method_slug":"contrastive-learning","method_name":"Contrastive Learning"},{"method_slug":"infonce","method_name":"InfoNCE"},{"method_slug":"moco","method_name":"MoCo"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2204.10377","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2204.10377"}},"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":"deterministic:regex_extraction","url":"https://github.com/DianCh/AdaContrast","reach":null}],"summary":{"ran":7,"ran_honours":4,"ran_draft_wrong":8,"ran_fixture":2,"ran_violates":2,"unverified":9},"by_repo_kind":{"official":{"samples":31,"ran":23,"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":32,"samples":[{"code_sha256_prefix":"9b777416ee4b9661","entry":"AdaMoCo","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"9b777416ee4b9661"}},{"code_sha256_prefix":"52b386c85c15f1f1","entry":"AverageMeter","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"52b386c85c15f1f1"}},{"code_sha256_prefix":"aea0d8d156ae8f0e","entry":"GaussianBlur","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"aea0d8d156ae8f0e"}},{"code_sha256_prefix":"ac8ac005970ac1fd","entry":"ImageList","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"ac8ac005970ac1fd"}},{"code_sha256_prefix":"dfe72857fdcd0631","entry":"NCropsTransform","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"dfe72857fdcd0631"}},{"code_sha256_prefix":"b4cae627da9d4b40","entry":"ProgressMeter","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b4cae627da9d4b40"}},{"code_sha256_prefix":"2944a9ae1c818935","entry":"adjust_learning_rate","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"2944a9ae1c818935"}},{"code_sha256_prefix":"e4f0afadad927f4c","entry":"calculate_acc","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e4f0afadad927f4c"}},{"code_sha256_prefix":"4769519334699711","entry":"classification_loss","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"4769519334699711"}},{"code_sha256_prefix":"7f2f33aeb9dd8ed3","entry":"cross_entropy_loss","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"7f2f33aeb9dd8ed3"}},{"code_sha256_prefix":"2bb0642fa17353c2","entry":"div","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"2bb0642fa17353c2"}},{"code_sha256_prefix":"b7348e1772bfba11","entry":"diversification_loss","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b7348e1772bfba11"}},{"code_sha256_prefix":"3277bef847b54b5d","entry":"get_augmentation","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3277bef847b54b5d"}},{"code_sha256_prefix":"aa067e5e8cb4bee4","entry":"get_augmentation_versions","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"aa067e5e8cb4bee4"}},{"code_sha256_prefix":"9a1f0bd5002fe561","entry":"get_distances","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"9a1f0bd5002fe561"}},{"code_sha256_prefix":"b01220197705c453","entry":"get_target_optimizer","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b01220197705c453"}},{"code_sha256_prefix":"1f34a1638da5703f","entry":"instance_loss","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1f34a1638da5703f"}},{"code_sha256_prefix":"5db12a48f3a9c2a9","entry":"is_master","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"5db12a48f3a9c2a9"}},{"code_sha256_prefix":"d41e65573feeba36","entry":"load_image","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"d41e65573feeba36"}},{"code_sha256_prefix":"dd980e064cdbfe0e","entry":"per_class_accuracy","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"dd980e064cdbfe0e"}},{"code_sha256_prefix":"d974e249f37878d2","entry":"refine_predictions","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"d974e249f37878d2"}},{"code_sha256_prefix":"6651e12b55f05e5d","entry":"soft_k_nearest_neighbors","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"6651e12b55f05e5d"}},{"code_sha256_prefix":"412b38636159f8fa","entry":"use_wandb","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"412b38636159f8fa"}},{"code_sha256_prefix":"291ff0547fe08f00","entry":"Classifier","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"291ff0547fe08f00"}},{"code_sha256_prefix":"f6f503974907329f","entry":"CustomDistributedDataParallel","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f6f503974907329f"}},{"code_sha256_prefix":"a2ae53d34bc13317","entry":"concat_all_gather","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"a2ae53d34bc13317"}},{"code_sha256_prefix":"1fb8be6b7baba941","entry":"eval_and_label_dataset","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1fb8be6b7baba941"}},{"code_sha256_prefix":"ee1a4a51e75b6f4e","entry":"remove_wrap_arounds","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"ee1a4a51e75b6f4e"}},{"code_sha256_prefix":"df95bf057b7a70cf","entry":"save_checkpoint","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"df95bf057b7a70cf"}},{"code_sha256_prefix":"ee293b943ff80976","entry":"train_epoch","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"ee293b943ff80976"}},{"code_sha256_prefix":"56ce9a1463e90b9f","entry":"train_target_domain","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"56ce9a1463e90b9f"}},{"code_sha256_prefix":"8eb94c91b5bcfa39","entry":"update_labels","repo":"DianCh/AdaContrast","repo_kind":"official","path":"target.py","file_url":"https://github.com/DianCh/AdaContrast/blob/HEAD/target.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"8eb94c91b5bcfa39"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}