README.md

March 12, 2025 ยท View on GitHub

APHQ-ViT: Post-Training Quantization with Average Perturbation Hessian Based Reconstruction for Vision Transformers

This repository is adopted from Swin-Transformer-Object-Detection repo.

Getting Started

  • Install pytorch and MMCV.
pip install torch==1.10.0 torchvision --index-url https://download.pytorch.org/whl/cu113
pip install -U openmim
mim install mmcv-full==1.3.17
  • If your pytorch version is higher than 1.10, you may need to install the bug-fixed version of mmcv-full==1.3.17 through local compilation instead of openmim:
git clone https://github.com/GoatWu/mmcv-v1.3.17.git
cd mmcv-v1.3.17
MMCV_WITH_OPS=1 pip install -e . -v
  • Install mmpycocotools using the local installation package, as the version provided by the official source has some bugs.
cd Object-Detection
pip install mmpycocotools-12.0.3.tar.gz
pip install -v -e .

Evaluation

You can quantize and evaluate a single model using the following command:

Example: Quantize Mask R-CNN with Swin-T at W4/A4 precision:

python tools/test.py configs/swin/mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_3x_coco.py checkpoint/mask_rcnn_swin_tiny_patch4_window7.pth --eval bbox segm --quant-config ./tools/quant_configs/4bit.py

Results

Below are the experimental results of our proposed APHQ-ViT on COCO dataset.

ModelFull Prec.
(APbox / APmask)
MLP Recon.
(APbox / APmask)
W4/A4
(APbox / APmask)
Mask-RCNN-Swin-T46.0 / 41.645.8 / 41.538.9 / 38.1
Mask-RCNN-Swin-S48.5 / 43.348.1 / 43.144.1 / 41.0
Cascade-Mask-RCNN-Swin-T50.4 / 43.750.2 / 43.648.9 / 42.7
Cascade-Mask-RCNN-Swin-S51.9 / 45.051.7 / 44.750.3 / 43.7