Home

Awesome

Think Match

release Documentation Status docker Docker Pulls discord channel QQ group GitHub stars

ThinkMatch is developed and maintained by ThinkLab at Shanghai Jiao Tong University. This repository is developed for the following purposes:

Official documentation: https://thinkmatch.readthedocs.io

Source code: https://github.com/Thinklab-SJTU/ThinkMatch

Introduction to Graph Matching

Graph Matching (GM) is a fundamental yet challenging problem in computer vision, pattern recognition and data mining. GM aims to find node-to-node correspondence among multiple graphs, by solving an NP-hard combinatorial problem named Quadratic Assignment Problem (QAP). Recently, there is growing interest in developing deep learning based graph matching methods.

Graph matching techniques have been applied to the following applications:

In this repository, we mainly focus on image keypoint matching because it is a popular testbed for existing graph matching methods.

Readers are referred to the following survey for more technical details about graph matching:

Deep Graph Matching Algorithms

ThinkMatch currently contains pytorch source code of the following deep graph matching methods:

When to use ThinkMatch

ThinkMatch is designed as a research protocol for deep graph matching. It is recommended if you have any of the following demands:

When not to use ThinkMatch

You may find the environment setup in ThinkMatch complicated and the details of graph matching hard to understand. pygmtools offers a user-friendly API, and is recommended for the following cases:

You can simply install the user-friendly package by

$ pip install pygmtools

Official documentation: https://pygmtools.readthedocs.io

Source code: https://github.com/Thinklab-SJTU/pygmtools

Deep Graph Matching Benchmarks

PascalVOC - 2GM

modelyearaerobikebirdboatbottlebuscarcatchaircowtabledoghorsembkiepersonplantsheepsofatraintvmean
GMN20180.41630.59640.60270.47950.79180.70200.67350.64880.39240.61280.66930.59760.61060.59750.37210.78180.68000.49930.84210.91410.6240
PCA-GM20190.49790.61930.65310.57150.78820.75560.64660.69690.41640.63390.50730.67050.66710.61640.44470.81160.67820.59220.78450.90420.6478
NGM20190.50100.63500.57900.53400.79800.77100.73600.68200.41100.66400.40800.60300.61900.63500.45600.77100.69300.65500.79200.88200.6413
NHGM20190.52400.62200.58300.55700.78700.77700.74400.70700.42000.64600.53800.61000.61900.60800.46800.79100.66800.55100.80900.88700.6458
IPCA-GM20200.53780.66220.67140.61200.80390.75270.72550.72520.44550.65240.54300.67240.67900.64210.47930.84350.70790.63980.83800.90830.6770
CIE-H20200.52500.68580.70150.57060.82070.77000.70730.73130.43830.69940.62370.70180.70310.66410.47630.85250.71720.64000.83850.91680.6892
BBGM20200.61870.71060.79690.78960.87400.94010.89470.80220.56760.79140.64580.78920.76150.75120.65190.98180.77290.77010.94940.93930.7899
NGM-v220210.61840.71180.77620.78750.87330.93630.87700.79770.55350.77810.89520.78800.80110.79230.62580.97710.77690.75740.96650.93230.8011
NHGM-v220210.59950.71540.77240.79020.87730.94570.89030.81810.59950.81290.86950.78110.76450.77500.64400.98720.77780.75380.97870.92800.8040
COMMON20230.65600.75200.80800.79500.89300.92300.90100.81800.61600.80700.95000.82000.81600.79500.66600.98900.78900.80900.99300.93800.8270

Willow Object Class - 2GM & MGM

modelyearremarkCarDuckFaceMotorbikeWinebottlemean
GMN2018-0.67900.76700.99800.69200.83100.7934
PCA-GM2019-0.87600.83601.00000.77600.88400.8744
NGM2019-0.84200.77600.99400.76800.88300.8530
NHGM2019-0.86500.72200.99900.79300.89400.8550
NMGM2019-0.78500.92101.00000.78700.94800.8880
IPCA-GM2020-0.90400.88601.00000.83000.88300.9006
CIE-H2020-0.85810.82060.99940.88360.88710.8898
BBGM2020-0.96800.89901.00000.99800.99400.9718
GANN-MGM2020self-supervised0.96000.96421.00001.00000.98790.9906
NGM-v22021-0.97400.93401.00000.98600.98300.9754
NHGM-v22021-0.97400.93901.00000.98600.98900.9780
NMGM-v22021-0.97600.94471.00001.00000.99020.9822
COMMON2023-0.97600.98201.00001.00000.99600.9910

SPair-71k - 2GM

modelyearaerobikebirdboatbottlebuscarcatchaircowdoghorsemtbikepersonplantsheeptraintvmean
GMN20180.59910.50990.74280.46720.63280.75520.69500.64620.57510.73020.58660.59140.63200.51160.86870.57870.69980.92380.6526
PCA-GM20190.64670.45710.78110.51280.63810.72720.61220.62780.62550.68220.59060.61150.64860.57730.87420.60420.72460.92830.6595
NGM20190.66440.52620.76960.49600.67660.78780.67640.68270.59170.73640.63910.60660.70740.60890.87540.63870.79790.91500.6887
IPCA-GM20200.69010.52860.80370.54250.66530.80010.68470.71360.61360.74790.66310.65140.69560.63910.91120.65400.82910.97500.7116
CIE-H20200.71460.57100.81680.56720.67940.82460.73390.74490.62590.78040.68720.66260.73740.66040.92460.67170.82280.97510.7334
BBGM20200.72500.64550.87800.75810.69270.93950.88590.79920.74560.83150.78780.77100.76500.76340.98200.85540.96780.99310.8215
NGM-v220210.68770.63310.86770.70130.69710.94670.87400.77370.72050.80670.74260.72530.79460.73400.98880.81230.94260.98670.8020
NHGM-v220210.62020.57810.86420.68460.68720.93350.80810.76560.69190.79870.66230.71710.78120.69530.98240.84440.93160.99260.7799
COMMON20230.77300.68200.92000.79500.70400.97500.91600.82500.72200.88000.80000.74100.83400.82800.99900.84400.98200.99800.8450

ThinkMatch includes the flowing datasets with the provided benchmarks:

TODO We also plan to include the following datasets in the future:

ThinkMatch also supports the following graph matching settings:

Get Started

Docker (RECOMMENDED)

Get the recommended docker image by

docker pull runzhongwang/thinkmatch:torch1.6.0-cuda10.1-cudnn7-pyg1.6.3-pygmtools0.5.1

Other combinations of torch and cuda are also available. See available images at docker hub.

See details in ThinkMatch-runtime.

Manual configuration (for Ubuntu)

This repository is developed and tested with Ubuntu 16.04, Python 3.7, Pytorch 1.6, cuda10.1, cudnn7 and torch-geometric 1.6.3.

  1. Install and configure Pytorch 1.6 (with GPU support).

  2. Install ninja-build: apt-get install ninja-build

  3. Install python packages:

    pip install tensorboardX scipy easydict pyyaml xlrd xlwt pynvml pygmtools
    
  4. Install building tools for LPMP:

    apt-get install -y findutils libhdf5-serial-dev git wget libssl-dev
    
    wget https://github.com/Kitware/CMake/releases/download/v3.19.1/cmake-3.19.1.tar.gz && tar zxvf cmake-3.19.1.tar.gz
    cd cmake-3.19.1 && ./bootstrap && make && make install
    
  5. Install and build LPMP:

    python -m pip install git+https://git@github.com/rogerwwww/lpmp.git
    

    You may need gcc-9 to successfully build LPMP. Here we provide an example installing and configuring gcc-9:

    apt-get update
    apt-get install -y software-properties-common
    add-apt-repository ppa:ubuntu-toolchain-r/test
    
    apt-get install -y gcc-9 g++-9
    update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9
    
  6. Install torch-geometric:

    export CUDA=cu101
    export TORCH=1.6.0
    /opt/conda/bin/pip install torch-scatter==2.0.5 -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
    /opt/conda/bin/pip install torch-sparse==0.6.8 -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
    /opt/conda/bin/pip install torch-cluster==1.5.8 -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
    /opt/conda/bin/pip install torch-spline-conv==1.2.0 -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
    /opt/conda/bin/pip install torch-geometric==1.6.3
    
  7. If you have configured gcc-9 to build LPMP, be sure to switch back to gcc-7 because this code repository is based on gcc-7. Here is also an example:

    update-alternatives --remove gcc /usr/bin/gcc-9
    update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 --slave /usr/bin/g++ g++ /usr/bin/g++-7
    

Available datasets

Note: All following datasets can be automatically downloaded and unzipped by pygmtools, but you can also download the dataset yourself if a download failure occurs.

  1. PascalVOC-Keypoint

    1. Download VOC2011 dataset and make sure it looks like data/PascalVOC/TrainVal/VOCdevkit/VOC2011

    2. Download keypoint annotation for VOC2011 from Berkeley server or google drive and make sure it looks like data/PascalVOC/annotations

    3. The train/test split is available in data/PascalVOC/voc2011_pairs.npz. This file must be added manually.

    Please cite the following papers if you use PascalVOC-Keypoint dataset:

    @article{EveringhamIJCV10,
      title={The pascal visual object classes (voc) challenge},
      author={Everingham, Mark and Van Gool, Luc and Williams, Christopher KI and Winn, John and Zisserman, Andrew},
      journal={International Journal of Computer Vision},
      volume={88},
      pages={303–338},
      year={2010}
    }
    
    @inproceedings{BourdevICCV09,
      title={Poselets: Body part detectors trained using 3d human pose annotations},
      author={Bourdev, L. and Malik, J.},
      booktitle={International Conference on Computer Vision},
      pages={1365--1372},
      year={2009},
      organization={IEEE}
    }
    
  2. Willow-Object-Class

    1. Download Willow-ObjectClass dataset from the official site or hugging face

    2. Unzip the dataset and make sure it looks like data/WillowObject/WILLOW-ObjectClass

    Please cite the following paper if you use Willow-Object-Class dataset:

    @inproceedings{ChoICCV13,
      author={Cho, Minsu and Alahari, Karteek and Ponce, Jean},
      title = {Learning Graphs to Match},
      booktitle = {International Conference on Computer Vision},
      pages={25--32},
      year={2013}
    }
    
  3. CUB2011

    1. Download CUB-200-2011 dataset.

    2. Unzip the dataset and make sure it looks like data/CUB_200_2011/CUB_200_2011

    Please cite the following report if you use CUB2011 dataset:

    @techreport{CUB2011,
      Title = {{The Caltech-UCSD Birds-200-2011 Dataset}},
      Author = {Wah, C. and Branson, S. and Welinder, P. and Perona, P. and Belongie, S.},
      Year = {2011},
      Institution = {California Institute of Technology},
      Number = {CNS-TR-2011-001}
    }
    
  4. IMC-PT-SparseGM

    1. Download the IMC-PT-SparseGM dataset from google drive or baidu drive (code: g2cj) or hugging face.

    2. Unzip the dataset and make sure it looks like data/IMC-PT-SparseGM/annotations for 50 anchor points and data/IMC-PT-SparseGM/annotations_100 for 100 anchor points

    Please cite the following papers if you use IMC-PT-SparseGM dataset:

    @article{JinIJCV21,
      title={Image Matching across Wide Baselines: From Paper to Practice},
      author={Jin, Yuhe and Mishkin, Dmytro and Mishchuk, Anastasiia and Matas, Jiri and Fua, Pascal and Yi, Kwang Moo and Trulls, Eduard},
      journal={International Journal of Computer Vision},
      pages={517--547},
      year={2021}
    }
    
    
    @InProceedings{WangCVPR23,
        author    = {Wang, Runzhong and Guo, Ziao and Jiang, Shaofei and Yang, Xiaokang and Yan, Junchi},
        title     = {Deep Learning of Partial Graph Matching via Differentiable Top-K},
        booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
        month     = {June},
        year      = {2023}
    }
    
  5. SPair-71k

    1. Download SPair-71k dataset

    2. Unzip the dataset and make sure it looks like data/SPair-71k

    Please cite the following papers if you use SPair-71k dataset:

    @article{min2019spair,
       title={SPair-71k: A Large-scale Benchmark for Semantic Correspondence},
       author={Juhong Min and Jongmin Lee and Jean Ponce and Minsu Cho},
       journal={arXiv prepreint arXiv:1908.10543},
       year={2019}
    }
    
    @InProceedings{min2019hyperpixel, 
       title={Hyperpixel Flow: Semantic Correspondence with Multi-layer Neural Features},
       author={Juhong Min and Jongmin Lee and Jean Ponce and Minsu Cho},
       booktitle={ICCV},
       year={2019}
    }
    

For more information, please see pygmtools.

Run the Experiment

Run training and evaluation

python train_eval.py --cfg path/to/your/yaml

and replace path/to/your/yaml by path to your configuration file, e.g.

python train_eval.py --cfg experiments/vgg16_pca_voc.yaml

Default configuration files are stored inexperiments/ and you are welcomed to try your own configurations. If you find a better yaml configuration, please let us know by raising an issue or a PR and we will update the benchmark!

Pretrained Models

ThinkMatch provides pretrained models. The model weights are available via google drive

To use the pretrained models, firstly download the weight files, then add the following line to your yaml file:

PRETRAINED_PATH: path/to/your/pretrained/weights

Chat with the Community

If you have any questions, or if you are experiencing any issues, feel free to raise an issue on GitHub.

We also offer the following chat rooms if you are more comfortable with them:

Citing ThinkMatch

If you find any of the models useful in your research, please cite the corresponding papers (BibTeX citations are available for each model in the models/ directory).

If you like this framework, you may also cite the underlying library pygmtools which is called during training & testing:

@article{wang2024pygm,
  author  = {Runzhong Wang and Ziao Guo and Wenzheng Pan and Jiale Ma and Yikai Zhang and Nan Yang and Qi Liu and Longxuan Wei and Hanxue Zhang and Chang Liu and Zetian Jiang and Xiaokang Yang and Junchi Yan},
  title   = {Pygmtools: A Python Graph Matching Toolkit},
  journal = {Journal of Machine Learning Research},
  year    = {2024},
  volume  = {25},
  number  = {33},
  pages   = {1-7},
  url     = {https://jmlr.org/papers/v25/23-0572.html},
}