You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 8.6KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. # LAP
  2. An Attention-Based Module for Faithful Interpretation and Knowledge Injection in Convolutional Neural Networks
  3. In this supplementary material, we have provided a pdf containing more details for some of the sections mentioned in the paper, and the code of our work.
  4. # Data Preparation
  5. ## Metadata
  6. First, download the metadata from [here](https://mega.nz/file/MqhXiLgC#NK1vd9ZLGU-3a182x-BXfvGCSuqHgq9hflI6tddh4Wc)
  7. ## RSNA
  8. ## CelebA
  9. 1. Download the dataset from [here](https://www.kaggle.com/jessicali9530/celeba-dataset)
  10. 2. Extract the data
  11. ```bash
  12. unzip -q -j celeba-dataset.zip '**/*.jpg' -d data/celeba
  13. ```
  14. 3. Extract `celeba.tsv` from [this](#metadata) metadata file to `dataset_metadata/celeba.tsv`
  15. ## Imagenet
  16. 1. Download the ImageNet ILSVRC2012 dataset from [here](https://www.image-net.org/challenges/LSVRC/index.php).
  17. 1. Extract `ILSVRC2012_img_train_t3.tar` to `data/imagenet/tars`.
  18. 1. Run the following command to extract the train images per class:
  19. ```bash
  20. python data_preparation/imagenet/extract_train.py -s data/imagenet/tars/ -n <num-threads>
  21. ```
  22. 1. Run the following command to extract the validation images per class (replace directory with the directory containing `ILSVRC2012_img_val.tar`, and extract `imagenet_val_maps.pklz` from [this](#metadata) metadata file):
  23. ```bash
  24. python data_preparation/imagenet/extract_val.py -s <directory> -m <imagenet_val_maps.pklz>
  25. ```
  26. 1. download the localizations bounding-boxes from [here](https://www.kaggle.com/c/imagenet-object-localization-challenge/data). Put `LOC_train_solution.csv` and `LOC_val_solution.csv` in `data/imagenet/extracted`.
  27. # Model checkpoints
  28. Download all the checkpoints from [here](https://mega.nz/file/16pWWA5L#b1SwLEv-YO5lL9wLVTcgykn2LmUBHm1exPFNB0JBoZo).
  29. # Run
  30. ## Evaluate the checkpoints
  31. ### RSNA
  32. #### Vanilla ResNet 18
  33. ##### Evaluate the model performance on the test set
  34. ```bash
  35. python evaluate.py rsna.org_resnet --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.org_resnet.pth
  36. ```
  37. #### Vanilla Inception V3
  38. ##### Evaluate the model performance on the test set
  39. ```bash
  40. python evaluate.py rsna.org_inception --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.org_inception.pth
  41. ```
  42. #### WS ResNet 18
  43. ##### Evaluate the model performance on the test set
  44. ```bash
  45. python evaluate.py rsna.ws_lap_resnet --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.ws_resnet.pth
  46. ```
  47. ##### Generate the LAP interpretations for positive samples
  48. ```bash
  49. python interpret.py rsna.ws_lap_resnet --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.ws_resnet.pth --skip-raw --interpretation-method Attention --global-threshold --cut-threshold 0 --mapped-labels-to-use 1 --save-by-file-name --report-dir rsna/ws_resnet_interpretations
  50. ```
  51. ##### Generate the LAP interpretations for negative samples
  52. ```bash
  53. python interpret.py rsna.ws_lap_resnet --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.ws_resnet.pth --skip-raw --interpretation-method Attention --global-threshold --cut-threshold 0 --mapped-labels-to-use 0 --save-by-file-name --report-dir rsna/ws_resnet_interpretations
  54. ```
  55. #### WS Inception V3
  56. ##### Evaluate the model performance on the test set
  57. ```bash
  58. python evaluate.py rsna.ws_lap_inception --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.ws_inception.pth
  59. ```
  60. ##### Generate the LAP interpretations for positive samples
  61. ```bash
  62. python interpret.py rsna.ws_lap_inception --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.ws_inception.pth --skip-raw --interpretation-method Attention --global-threshold --cut-threshold 0 --mapped-labels-to-use 1 --save-by-file-name --report-dir rsna/ws_inception_interpretations
  63. ```
  64. ##### Generate the LAP interpretations for negative samples
  65. ```bash
  66. python interpret.py rsna.ws_lap_inception --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.ws_inception.pth --skip-raw --interpretation-method Attention --global-threshold --cut-threshold 0 --mapped-labels-to-use 0 --save-by-file-name --report-dir rsna/ws_inception_interpretations
  67. ```
  68. #### BB ResNet 18
  69. ##### Evaluate the model performance on the test set
  70. ```bash
  71. python evaluate.py rsna.bb_lap_resnet --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.bb_resnet.pth
  72. ```
  73. ##### Generate the LAP interpretations for positive samples
  74. ```bash
  75. python interpret.py rsna.bb_lap_resnet --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.bb_resnet.pth --skip-raw --interpretation-method Attention --global-threshold --cut-threshold 0 --mapped-labels-to-use 1 --save-by-file-name --report-dir rsna/bb_resnet_interpretations
  76. ```
  77. ##### Generate the LAP interpretations for negative samples
  78. ```bash
  79. python interpret.py rsna.bb_lap_resnet --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.bb_resnet.pth --skip-raw --interpretation-method Attention --global-threshold --cut-threshold 0 --mapped-labels-to-use 0 --save-by-file-name --report-dir rsna/bb_resnet_interpretations
  80. ```
  81. #### BB Inception V3
  82. ##### Evaluate the model performance on the test set
  83. ```bash
  84. python evaluate.py rsna.bb_lap_inception --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.bb_inception.pth
  85. ```
  86. ##### Generate the LAP interpretations for positive samples
  87. ```bash
  88. python interpret.py rsna.bb_lap_inception --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.bb_inception.pth --skip-raw --interpretation-method Attention --global-threshold --cut-threshold 0 --mapped-labels-to-use 1 --save-by-file-name --report-dir rsna/bb_inception_interpretations
  89. ```
  90. ##### Generate the LAP interpretations for negative samples
  91. ```bash
  92. python interpret.py rsna.ws_lap_inception --device cuda:0 --samples-dir test --final-model-dir checkpoints/rsna.ws_inception.pth --skip-raw --interpretation-method Attention --global-threshold --cut-threshold 0 --mapped-labels-to-use 0 --save-by-file-name --report-dir rsna/ws_inception_interpretations
  93. ```
  94. ### CelebA
  95. #### Vanilla ResNet 18
  96. ##### Evaluate the model performance on the test set
  97. ```bash
  98. python evaluate.py celeba.org_resnet --device cuda:0 --samples-dir test --final-model-dir checkpoints/celeba.org_resnet.pth
  99. ```
  100. #### Vanilla Inception V3
  101. ##### Evaluate the model performance on the test set
  102. ```bash
  103. python evaluate.py celeba.org_inception --device cuda:0 --samples-dir test --final-model-dir checkpoints/celeba.org_inception.pth
  104. ```
  105. #### WS ResNet 18
  106. ##### Evaluate the model performance on the test set
  107. ```bash
  108. python evaluate.py celeba.ws_lap_resnet --device cuda:0 --samples-dir test --final-model-dir checkpoints/celeba.ws_resnet.pth
  109. ```
  110. ##### Generate the LAP interpretations for positive samples
  111. ```bash
  112. python interpret.py celeba.ws_lap_resnet --device cuda:0 --samples-dir test --final-model-dir checkpoints/celeba.ws_resnet.pth --skip-raw --interpretation-method Attention --global-threshold --cut-threshold 0 --mapped-labels-to-use 1 --save-by-file-name --report-dir celeba/ws_resnet_interpretations
  113. ```
  114. ##### Generate the LAP interpretations for negative samples
  115. ```bash
  116. python interpret.py celeba.ws_lap_resnet --device cuda:0 --samples-dir test --final-model-dir checkpoints/celeba.ws_resnet.pth --skip-raw --interpretation-method Attention --global-threshold --cut-threshold 0 --mapped-labels-to-use 0 --save-by-file-name --report-dir celeba/ws_resnet_interpretations
  117. ```
  118. #### WS Inception V3
  119. ##### Evaluate the model performance on the test set
  120. ```bash
  121. python evaluate.py celeba.ws_lap_inception --device cuda:0 --samples-dir test --final-model-dir checkpoints/celeba.ws_inception.pth
  122. ```
  123. ##### Generate the LAP interpretations for positive samples
  124. ```bash
  125. python interpret.py celeba.ws_lap_inception --device cuda:0 --samples-dir test --final-model-dir checkpoints/celeba.ws_inception.pth --skip-raw --interpretation-method Attention --global-threshold --cut-threshold 0 --mapped-labels-to-use 1 --save-by-file-name --report-dir celeba/ws_inception_interpretations
  126. ```
  127. ##### Generate the LAP interpretations for negative samples
  128. ```bash
  129. python interpret.py celeba.ws_lap_inception --device cuda:0 --samples-dir test --final-model-dir checkpoints/celeba.ws_inception.pth --skip-raw --interpretation-method Attention --global-threshold --cut-threshold 0 --mapped-labels-to-use 0 --save-by-file-name --report-dir celeba/ws_inception_interpretations
  130. ```
  131. ### ImageNet
  132. #### WS ResNet 50 (Fine-tuned)
  133. ##### Evaluate the model performance on the validation set
  134. ```bash
  135. python evaluate.py imagenet.lap_resnet50_ft --device cuda:0 --samples-dir val --final-model-dir checkpoints/imagenet.ws_resnet_ft.pth
  136. ```