{"id":24569684,"url":"https://github.com/bfshi/absvit","last_synced_at":"2025-04-22T19:52:26.110Z","repository":{"id":106565908,"uuid":"605854352","full_name":"bfshi/AbSViT","owner":"bfshi","description":"Official code for \"Top-Down Visual Attention from Analysis by Synthesis\" (CVPR 2023 highlight)","archived":false,"fork":false,"pushed_at":"2023-08-20T21:48:48.000Z","size":9044,"stargazers_count":165,"open_issues_count":5,"forks_count":12,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-21T06:42:48.593Z","etag":null,"topics":["attention","classification","cvpr","pytorch","segmentation","vision-transformer"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bfshi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-02-24T03:15:45.000Z","updated_at":"2025-01-17T09:25:33.000Z","dependencies_parsed_at":"2023-09-25T06:57:19.926Z","dependency_job_id":null,"html_url":"https://github.com/bfshi/AbSViT","commit_stats":{"total_commits":20,"total_committers":1,"mean_commits":20.0,"dds":0.0,"last_synced_commit":"ac35c4289ee69166a8d22997aaeaea5c60878827"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfshi%2FAbSViT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfshi%2FAbSViT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfshi%2FAbSViT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfshi%2FAbSViT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bfshi","download_url":"https://codeload.github.com/bfshi/AbSViT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250314694,"owners_count":21410467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attention","classification","cvpr","pytorch","segmentation","vision-transformer"],"created_at":"2025-01-23T15:55:38.553Z","updated_at":"2025-04-22T19:52:26.055Z","avatar_url":"https://github.com/bfshi.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Top-Down Visual Attention from Analysis by Synthesis\n\n\nThis is the official codebase of AbSViT, from the following paper:\n\nTop-Down Visual Attention from Analysis by Synthesis, CVPR 2023\\\n[Baifeng Shi](https://bfshi.github.io), [Trevor Darrell](https://people.eecs.berkeley.edu/~trevor/), and [Xin Wang](https://xinw.ai/)\\\nUC Berkeley, Microsoft Research\n\n[Website](https://sites.google.com/view/absvit) | [Paper](https://arxiv.org/pdf/2303.13043.pdf)\n\n\u003cimg src=\"demo/intro.png\" alt=\"drawing\" width=\"800\"/\u003e\n\n\n## To-Dos\n\n- [x] Finetuning on Vision-Language datasets\n\n\n\u003c!-- ✅ ⬜️  --\u003e\n\n\n## Environment\n\nInstall PyTorch 1.7.0+ and torchvision 0.8.1+ from the official website.\n\n`requirements.txt` lists all the dependencies:\n```\npip install -r requirements.txt\n```\nIn addition, please also install the magickwand library:\n```\napt-get install libmagickwand-dev\n```\n\n## Demo\n\nImageNet demo: [`demo/demo.ipynb`](demo/demo.ipynb) gives an example of visualizing AbSViT's attention map on single-object and multi-object images in ImageNet. Since the model is only trained on single-object recognition, the top-down attention is quite weak.\n\nVQA demo: [`vision_language/demo/visualize_attention.ipynb`](vision_language/demo/visualize_attention.ipynb) gives an example of how AbSViT's top-down attention is adaptive to different questions on the same image.\n\n## Model Zoo\n\n| Name | ImageNet |   ImageNet-C (↓)   | PASCAL VOC | Cityscapes | ADE20K |                                       Weights                                        |\n|:---:|:---:|:------------------:|:---:|:---:|:---:|:------------------------------------------------------------------------------------:|\n| ViT-Ti | 72.5 |        71.1        | - | - | - | [model](https://berkeley.box.com/shared/static/mw99ywof7ri7kczq79iwjia2att2dpmh.pth) |\n| AbSViT-Ti | 74.1 |        66.7        | - | - | - | [model](https://berkeley.box.com/shared/static/0n2tvn9hmx7bwv097nwb60vw1jf4841n.pth) |\n| ViT-S | 80.1 |        54.6        | - | - | - | [model](https://berkeley.box.com/shared/static/tftkkov22978lmvgv1g1cxuuk62iacn7.pth) |\n| AbSViT-S | 80.7 |        51.6        | - | - | - | [model](https://berkeley.box.com/shared/static/3wpkf5qo31ghb4dzehczup4pfh24xmve.pth) |\n| ViT-B | 80.8 |        49.3        | 80.1 | 75.3 | 45.2 | [model](https://berkeley.box.com/shared/static/6fszey9291pvnkwdpt5ngrhh0rcu1iqu.pth) |\n| AbSViT-B | 81.0 |        48.3        | 81.3 | 76.8 | 47.2 | [model](https://berkeley.box.com/shared/static/aain2svhs9lfvz8o21xao91dsnylgsot.pth) |\n\n\n## Evaluation on Image Classification\n\nFor example, to evaluate AbSViT_small on ImageNet, run\n\n```\npython main.py --model absvit_small_patch16_224 --data-path path/to/imagenet --eval --resume path/to/checkpoint\n```\n\nTo evaluate on robustness benchmarks, please add one of `--inc_path /path/to/imagenet-c`, `--ina_path /path/to/imagenet-a`, `--inr_path /path/to/imagenet-r` or `--insk_path /path/to/imagenet-sketch` to test [ImageNet-C](https://github.com/hendrycks/robustness), [ImageNet-A](https://github.com/hendrycks/natural-adv-examples), [ImageNet-R](https://github.com/hendrycks/imagenet-r) or [ImageNet-Sketch](https://github.com/HaohanWang/ImageNet-Sketch).\n\nIf you want to test the accuracy under adversarial attackers, please add `--fgsm_test` or `--pgd_test`.\n\n\n## Evaluation on Semantic Segmentation\n\nPlease see [`segmentation`](segmentation) for instructions.\n\n## Training\n\nTake AbSViT_small for an example. We use single node with 8 gpus for training:\n\n```\npython -m torch.distributed.launch --nproc_per_node=8 --master_port 12345  main.py --model absvit_small_patch16_224 --data-path path/to/imagenet  --output_dir output/here  --num_workers 8 --batch-size 128 --warmup-epochs 10\n```\n\nTo train different model architectures, please change the arguments `--model`. We provide choices of ViT_{tiny, small, base}' and AbSViT_{tiny, small, base}. \n\n## Finetuning on Vision-Language Dataset\n\nPlease see [`vision_language`](vision_language) for instructions.\n\n## Links\n\nThis codebase is built upon the official code of \"[Visual Attention Emerges from Recurrent Sparse Reconstruction](https://github.com/bfshi/VARS)\" and \"[Towards Robust Vision Transformer](https://github.com/vtddggg/Robust-Vision-Transformer)\".\n\n\n## Citation\n\nIf you found this code helpful, please consider citing our work: \n\n\n```bibtext\n\n@inproceedings{shi2023top,\n  title={Top-Down Visual Attention from Analysis by Synthesis},\n  author={Shi, Baifeng and Darrell, Trevor and Wang, Xin},\n  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},\n  pages={2102--2112},\n  year={2023}\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbfshi%2Fabsvit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbfshi%2Fabsvit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbfshi%2Fabsvit/lists"}