Skip to content


Folders and files

Last commit message
Last commit date

Latest commit



24 Commits

Repository files navigation


Official PyTorch implementation of paper:

GMFlow: Learning Optical Flow via Global Matching, CVPR 2022, Oral

Authors: Haofei Xu, Jing Zhang, Jianfei Cai, Hamid Rezatofighi, Dacheng Tao

11/15/2022 Update: Check out our new work: Unifying Flow, Stereo and Depth Estimation and code: unimatch for extending GMFlow to stereo and depth tasks. More pretrained GMFlow models with different speed-accuracy trade-offs are also released. Check out our Colab and HuggingFace demo to play with GMFlow in your browser!

A video introduction (in Chinese) of GMFlow is available at bilibili!


We streamline the optical flow estimation pipeline by reformulating optical flow as a global matching problem.


  • Flexible & Modular design

    We decompose the end-to-end optical flow framework into five components:

    feature extraction, feature enhancement, feature matching, flow propagation and flow refinement.

    One can easily construct a customized optical flow model by combining different components.

  • High accuracy

    With only one refinement, GMFlow outperforms 31-refinements RAFT on the challenging Sintel benchmark.

  • High efficiency

    A basic GMFlow model (without refinement) runs at 57ms (V100) or 26ms (A100) for Sintel data (436x1024).

    GMFlow gains more speedup than RAFT on high-end GPUs (e.g., A100) since GMFlow doesn't require a large number of sequential computation.

    GMFlow also simplifies backward flow computation without requiring to forward the network twice. The bidirectional flow can be used for occlusion detection with forward-backward consistency check.


Our code is based on pytorch 1.9.0, CUDA 10.2 and python 3.8. Higher version pytorch should also work well.

We recommend using conda for installation:

conda env create -f environment.yml
conda activate gmflow


All pretrained models can be downloaded from google drive.

You can run a trained model on a sequence of images and visualize the results:

--inference_dir demo/sintel_market_1 \
--output_path output/gmflow-norefine-sintel_market_1 \
--resume pretrained/gmflow_sintel-0c07dcb3.pth

You can also predict bidirectional flow with --pred_bidir_flow enabled and use --fwd_bwd_consistency_check for forward-backward consistency check. More examples can be found in scripts/


The datasets used to train and evaluate GMFlow are as follows:

By default the dataloader assumes the datasets are located in folder datasets and are organized as follows:

├── FlyingChairs_release
│   └── data
├── FlyingThings3D
│   ├── frames_cleanpass
│   ├── frames_finalpass
│   └── optical_flow
├── HD1K
│   ├── hd1k_challenge
│   ├── hd1k_flow_gt
│   ├── hd1k_flow_uncertainty
│   └── hd1k_input
│   ├── testing
│   └── training
├── Sintel
│   ├── test
│   └── training

It is recommended to symlink your dataset root to datasets:

ln -s $YOUR_DATASET_ROOT datasets

Otherwise, you may need to change the corresponding paths in


You can evaluate a trained GMFlow model by running:

CUDA_VISIBLE_DEVICES=0 python --eval --val_dataset things sintel --resume pretrained/gmflow_things-e9887eda.pth 

More evaluation scripts can be found in scripts/

For submission to Sintel and KITTI online test sets, you can run scripts/


All training scripts on FlyingChairs, FlyingThings3D, Sintel and KITTI datasets can be found in scripts/ and scripts/

Note that the basic GMFlow model (without refinement) can be trained on 4x 16GB V100 GPUs. For training GMFlow with refinement, 8x 16GB V100 or 4x 32GB V100 or 4x 40GB A100 GPUs are required by default. You may need to tune the batch size and training iterations according to your hardware.

We support using tensorboard to monitor and visualize the training process. You can first start a tensorboard session with

tensorboard --logdir checkpoints

and then access http://localhost:6006 in your browser.


If you find our work useful in your research, please consider citing our paper:

  title={GMFlow: Learning Optical Flow via Global Matching},
  author={Xu, Haofei and Zhang, Jing and Cai, Jianfei and Rezatofighi, Hamid and Tao, Dacheng},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},


This project would not have been possible without relying on some awesome repos : RAFT, LoFTR, DETR, Swin, mmdetection and Detectron2. We thank the original authors for their excellent work.