{"id":20291602,"url":"https://github.com/hila-chefer/transformer-mm-explainability","last_synced_at":"2025-04-12T22:18:51.391Z","repository":{"id":38250435,"uuid":"350871478","full_name":"hila-chefer/Transformer-MM-Explainability","owner":"hila-chefer","description":"[ICCV 2021- Oral] Official PyTorch implementation for Generic Attention-model Explainability for Interpreting Bi-Modal and Encoder-Decoder Transformers, a novel method to visualize any Transformer-based network. Including examples for DETR, VQA.","archived":false,"fork":false,"pushed_at":"2023-08-24T17:45:14.000Z","size":26560,"stargazers_count":847,"open_issues_count":12,"forks_count":110,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-12T22:17:57.667Z","etag":null,"topics":["clip","detr","explainability","explainable-ai","interpretability","lxmert","transformer","transformers","visualbert","visualization","vqa"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hila-chefer.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-23T22:11:18.000Z","updated_at":"2025-04-12T07:17:05.000Z","dependencies_parsed_at":"2024-08-01T13:17:39.894Z","dependency_job_id":"893c1542-de76-4bfd-a927-964559895e2b","html_url":"https://github.com/hila-chefer/Transformer-MM-Explainability","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hila-chefer%2FTransformer-MM-Explainability","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hila-chefer%2FTransformer-MM-Explainability/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hila-chefer%2FTransformer-MM-Explainability/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hila-chefer%2FTransformer-MM-Explainability/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hila-chefer","download_url":"https://codeload.github.com/hila-chefer/Transformer-MM-Explainability/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248637786,"owners_count":21137538,"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":["clip","detr","explainability","explainable-ai","interpretability","lxmert","transformer","transformers","visualbert","visualization","vqa"],"created_at":"2024-11-14T15:13:07.091Z","updated_at":"2025-04-12T22:18:51.366Z","avatar_url":"https://github.com/hila-chefer.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"[ICCV 2021- Oral] PyTorch Implementation of `Generic Attention-model Explainability for Interpreting Bi-Modal and Encoder-Decoder Transformers \u003chttps://arxiv.org/abs/2103.15679\u003e`_\n=================================================================================================================================================================\n\n|youtube|\n\n.. |youtube| image:: https://img.shields.io/static/v1?label=ICCV2021\u0026message=12MinuteVideo\u0026color=red\n                   :target: https://www.youtube.com/watch?v=bQTL34Dln-M\n\nNotebooks for LXMERT + DETR:\n----------------------------\n\n|DETR_LXMERT|\n\n.. |DETR_LXMERT| image:: https://colab.research.google.com/assets/colab-badge.svg\n                   :target: https://colab.research.google.com/github/hila-chefer/Transformer-MM-Explainability/blob/main/Transformer_MM_Explainability.ipynb\n\nNotebook for CLIP:\n----------------------------\n\n|CLIP|\n\n.. |CLIP| image:: https://colab.research.google.com/assets/colab-badge.svg\n                   :target: https://colab.research.google.com/github/hila-chefer/Transformer-MM-Explainability/blob/main/CLIP_explainability.ipynb\n\n**Demo**: You can check out a demo on `Huggingface spaces \u003chttps://huggingface.co/spaces/PaulHilders/CLIPGroundingExplainability\u003e`_ or scan the following QR code.\n\n.. image:: https://user-images.githubusercontent.com/19412343/176676771-d26f2146-9901-49e7-99be-b030f3d790de.png\n   :width: 100\n\n\nNotebook for ViT:\n----------------------------\n\n|ViT|\n\n.. |ViT| image:: https://colab.research.google.com/assets/colab-badge.svg\n                   :target: https://colab.research.google.com/github/hila-chefer/Transformer-MM-Explainability/blob/main/Transformer_MM_explainability_ViT.ipynb\n\n.. sectnum::\n\n\nUsing Colab\n----------------\n\n* Please notice that the notebook assumes that you are using a GPU. To switch runtime go to Runtime -\u003e change runtime type and select GPU.\n* Installing all the requirements may take some time. After installation, please restart the runtime.\n\nRunning Examples\n----------------\n\nNotice that we have two `jupyter` notebooks to run the examples presented in the paper.\n\n* `The notebook for LXMERT \u003c./LXMERT.ipynb\u003e`_ contains both the examples from the paper and examples with images from the internet and free form questions.\n  To use your own input, simply change the `URL` variable to your image and the `question` variable to your free form question.\n\n  .. image:: LXMERT.PNG\n\n  .. image:: LXMERT-web.PNG\n\n* `The notebook for DETR \u003c./DETR.ipynb\u003e`_ contains the examples from the paper.\n  To use your own input, simply change the `URL` variable to your image.\n\n  .. image:: DETR.PNG\n\nReproduction of results\n-----------------------\n\n^^^^^^^^^^\nVisualBERT\n^^^^^^^^^^\n\nRun the `run.py` script as follows:\n\n.. code-block:: bash\n\n   CUDA_VISIBLE_DEVICES=0 PYTHONPATH=`pwd` python VisualBERT/run.py --method=\u003cmethod_name\u003e --is-text-pert=\u003ctrue/false\u003e --is-positive-pert=\u003ctrue/false\u003e --num-samples=10000 config=projects/visual_bert/configs/vqa2/defaults.yaml model=visual_bert dataset=vqa2 run_type=val checkpoint.resume_zoo=visual_bert.finetuned.vqa2.from_coco_train env.data_dir=/path/to/data_dir training.num_workers=0 training.batch_size=1 training.trainer=mmf_pert training.seed=1234\n\n.. note::\n\n  If the datasets aren't already in `env.data_dir`, then the script will download the data automatically to the path in `env.data_dir`.\n\n\n^^^^^^\nLXMERT\n^^^^^^\n\n#. Download `valid.json \u003chttps://nlp.cs.unc.edu/data/lxmert_data/vqa/valid.json\u003e`_:\n\n    .. code-block:: bash\n\n      pushd data/vqa\n      wget https://nlp.cs.unc.edu/data/lxmert_data/vqa/valid.json\n      popd\n\n#. Download the `COCO_val2014` set to your local machine.\n\n   .. note::\n\n      If you already downloaded `COCO_val2014` for the `VisualBERT`_ tests, you can simply use the same path you used for `VisualBERT`_.\n\n#. Run the `perturbation.py` script as follows:\n\n    .. code-block:: bash\n\n      CUDA_VISIBLE_DEVICES=0 PYTHONPATH=`pwd` python lxmert/lxmert/perturbation.py  --COCO_path /path/to/COCO_val2014 --method \u003cmethod_name\u003e --is-text-pert \u003ctrue/false\u003e --is-positive-pert \u003ctrue/false\u003e\n\n\n\n^^^^\nDETR\n^^^^\n\n#. Download the COCO dataset as described in the `DETR repository \u003chttps://github.com/facebookresearch/detr#data-preparation\u003e`_.\n   Notice you only need the validation set.\n   \n#. Lower the IoU minimum threshold from 0.5 to 0.2 using the following steps:\n         \n   * Locate the `cocoeval.py` script in your python library path:\n      \n     find library path:\n    \n      .. code-block:: python\n\n         import sys\n         print(sys.path)\n         \n     find `cocoeval.py`: \n  \n      .. code-block:: bash\n      \n         cd /path/to/lib\n         find -name cocoeval.py\n         \n   * Change the `self.iouThrs` value in the `setDetParams` function (which sets the parameters for the COCO detection evaluation) in the `Params` class as follows:\n      \n     insead of:\n    \n      .. code-block:: python\n\n       self.iouThrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True)\n     use: \n  \n      .. code-block:: python\n\n       self.iouThrs = np.linspace(.2, 0.95, int(np.round((0.95 - .2) / .05)) + 1, endpoint=True)\n\n#. Run the segmentation experiment, use the following command:\n\n    .. code-block:: bash\n\n       CUDA_VISIBLE_DEVICES=0 PYTHONPATH=`pwd`  python DETR/main.py --coco_path /path/to/coco/dataset  --eval --masks --resume https://dl.fbaipublicfiles.com/detr/detr-r50-e632da11.pth --batch_size 1 --method \u003cmethod_name\u003e\n\nCiting\n-------\n\nIf you make use of our work, please cite our paper:\n\n    .. code-block:: latex\n\n       @InProceedings{Chefer_2021_ICCV,\n          author    = {Chefer, Hila and Gur, Shir and Wolf, Lior},\n          title     = {Generic Attention-Model Explainability for Interpreting Bi-Modal and Encoder-Decoder Transformers},\n          booktitle = {Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},\n          month     = {October},\n          year      = {2021},\n          pages     = {397-406}\n       }\n\n\nCredits\n-------\n\n* VisualBERT implementation is based on the `MMF \u003chttps://github.com/facebookresearch/mmf\u003e`_ framework.\n* LXMERT implementation is based on the `offical LXMERT \u003chttps://github.com/airsplay/lxmert\u003e`_ implementation and on `Hugging Face Transformers \u003chttps://github.com/huggingface/transformers\u003e`_.\n* DETR implementation is based on the `offical DETR \u003chttps://github.com/facebookresearch/detr\u003e`_ implementation.\n* CLIP implementation is based on the `offical CLIP \u003chttps://github.com/openai/CLIP\u003e`_ implementation.\n* The CLIP huggingface spaces demo was made by Paul Hilders, Danilo de Goede, and Piyush Bagad from the University of Amsterdam as part of their `final project \u003chttps://github.com/bpiyush/CLIP-grounding\u003e`_.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhila-chefer%2Ftransformer-mm-explainability","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhila-chefer%2Ftransformer-mm-explainability","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhila-chefer%2Ftransformer-mm-explainability/lists"}