A lightweight deep network for fast and accurate optical flow estimation.

Overview

FastFlowNet: A Lightweight Network for Fast Optical Flow Estimation

The official PyTorch implementation of FastFlowNet (ICRA 2021).

Authors: Lingtong Kong, Chunhua Shen, Jie Yang

Network Architecture

Dense optical flow estimation plays a key role in many robotic vision tasks. It has been predicted with satisfying accuracy than traditional methods with advent of deep learning. However, current networks often occupy large number of parameters and require heavy computation costs. These drawbacks have hindered applications on power- or memory-constrained mobile devices. To deal with these challenges, in this paper, we dive into designing efficient structure for fast and accurate optical flow prediction. Our proposed FastFlowNet works in the well-known coarse-to-fine manner with following innovations. First, a new head enhanced pooling pyramid (HEPP) feature extractor is employed to intensify high-resolution pyramid feature while reducing parameters. Second, we introduce a novel center dense dilated correlation (CDDC) layer for constructing compact cost volume that can keep large search radius with reduced computation burden. Third, an efficient shuffle block decoder (SBD) is implanted into each pyramid level to acclerate flow estimation with marginal drops in accuracy. The overall architecture of FastFlowNet is shown as below.

NVIDIA Jetson TX2

Optimized by TensorRT, proposed FastFlowNet can approximate real-time inference on the Jetson TX2 development board, which represents the first real-time solution for accurate optical flow on embedded devices. For training, please refer to PWC-Net and IRR-PWC, since we use the same datasets, augmentation methods and loss functions. Currently, only pytorch implementation and pre-trained models are available. A demo video for real-time inference on embedded device is shown below, note that there is time delay between real motion and visualized optical flow.

Optical Flow Performance

Experiments on both synthetic Sintel and real-world KITTI datasets demonstrate the effectiveness of proposed approaches, which consumes only 1/10 computation of comparable networks (PWC-Net and LiteFlowNet) to get 90% of their performance. In particular, FastFlowNet only contains 1.37 M parameters and runs at 90 or 5.7 fps with one desktop NVIDIA GTX 1080 Ti or embedded Jetson TX2 GPU on Sintel resolution images. Comprehensive comparisons among well-known flow architectures are listed in the following table. Times and FLOPs are measured on Sintel resolution images with PyTorch implementations.

Sintel Clean Test (AEPE) KITTI 2015 Test (Fl-all) Params (M) FLOPs (G) Time (ms) 1080Ti Time (ms) TX2
FlowNet2 4.16 11.48% 162.52 24836.4 116 1547
SPyNet 6.64 35.07% 1.20 149.8 50 918
PWC-Net 4.39 9.60% 8.75 90.8 34 485
LiteFlowNet 4.54 9.38% 5.37 163.5 55 907
FastFlowNet 4.89 11.22% 1.37 12.2 11 176

Some visual examples of our FastFlowNet on several image sequences are presented as follows.

Usage

Our experiment environment is with CUDA 9.0, Python 3.6 and PyTorch 0.4.1. First, you should build and install the Correlation module in ./model/correlation_package/ with command below

$ python setup.py build
$ python setup.py install

To benchmark running speed and calculate model parameters, you can run

$ python benchmark.py

A demo for predicting optical flow given two time adjacent images, please run

$ python demo.py

Note that you can change the pre-trained models from different datasets for specific applications. The model ./checkpoints/fastflownet_ft_mix.pth is fine-tuned on mixed Sintel and KITTI, which may obtain better generalization ability.

License and Citation

This software and associated documentation files (the "Software"), and the research paper (FastFlowNet: A Lightweight Network for Fast Optical Flow Estimation) including but not limited to the figures, and tables (the "Paper") are provided for academic research purposes only and without any warranty. Any commercial use requires my consent. When using any parts of the Software or the Paper in your work, please cite the following paper:

@inproceedings{Kong:2021:FastFlowNet, 
 title = {FastFlowNet: A Lightweight Network for Fast Optical Flow Estimation}, 
 author = {Lingtong Kong and Chunhua Shen and Jie Yang}, 
 booktitle = {2021 IEEE International Conference on Robotics and Automation (ICRA)}, 
 year = {2021}
}
Comments
  • TensorRT docker image with FastFlowNet

    TensorRT docker image with FastFlowNet

    opened by pullmyleg 3
  • Results are inconsistent with expectations

    Results are inconsistent with expectations

    Platform: xavier. jetpack4.4.1 cuda:10.2 pytorch:1.6

    the correlation_packege in this repo is for pytorch0.4 which is not suite for pytorch 1.6, so I used flownet2's (https://github.com/NVIDIA/flownet2-pytorch/tree/master/networks/correlation_package)

    then everything is ok.

    the output is :

    /usr/local/lib/python3.6/dist-packages/torch/nn/functional.py:3384: UserWarning: Default grid_sample and affine_grid behavior has changed to align_corners=False since 1.3.0. Please specify align_corners=True if the old behavior is desired. See the documentation of grid_sample for details. warnings.warn("Default grid_sample and affine_grid behavior has changed "

    but the result is not same in the repository.

    flow

    opened by dongxuanlb 3
  • RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

    RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

    Hello, I use the model to train my dataset, but the tensor size after pooling and up sampling is different, so the torch.cat command cannot be executed(such as cat6 = torch.cat([cv6, r16, flow7_up], 1)). I used the following function to process the data, and then this error occurred. Do you know how to solve this problem? Or how to deal with the problem of inconsistent tensor size?

    image

    opened by Wenjie64 2
  • Low KITTI 2015 flow accuracy by using pertained weights

    Low KITTI 2015 flow accuracy by using pertained weights

    Hi there,

    I tested the accuracy of the model using pretrained weights in checkpoints/ on KITTI 2015 flow training dataset, and got lower accuracy than that reported in your paper.

    Using ./checkpoints/fastflownet_ft_mix.pth gives accuracy of

    NOC
    0.203071 0.203071 0.284329 0.284329 0.216956 0.216956 1.000000 
    OCC
    0.301341 0.301341 0.306706 0.306706 0.302163 0.302163 1.000000 
    

    ./checkpoints/fastflownet_ft_kitti.pth gives accuracy of

    NOC
    0.242663 0.242663 0.172001 0.172001 0.230589 0.230589 1.000000 
    OCC
    0.310403 0.310403 0.192049 0.192049 0.292272 0.292272 1.000000 
    

    The paper shows the model could give (8.21%) Fl-all on KITTI 2015 flow training dataset.

    So I'm wondering if the weights that can reproduced the accuracies in paper is included in this repo ? Please clarify.

    Thanks so much !

    opened by magsail 1
  • run demo.py error

    run demo.py error

    run on colab.research.google.com; and output: sh: 1: ping: not found sh: 1: ping: not found sh: 1: ping: not found sh: 1: ping: not found Traceback (most recent call last): File "/content/drive/MyDrive/FastFlowNet-main/demo.py", line 45, in output = model(input_t).data File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "/content/drive/MyDrive/FastFlowNet-main/models/FastFlowNet.py", line 134, in forward cv6 = torch.index_select(self.corr(f16, f26), dim=1, index=self.index.to(f16).long()) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "/content/drive/MyDrive/FastFlowNet-main/models/correlation_package/correlation.py", line 59, in forward result = CorrelationFunction(self.pad_size, self.kernel_size, self.max_displacement,self.stride1, self.stride2, self.corr_multiply)(input1, input2) File "/usr/local/lib/python3.7/dist-packages/torch/autograd/function.py", line 262, in call "Legacy autograd function with non-static forward method is deprecated. " RuntimeError: Legacy autograd function with non-static forward method is deprecated. Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function)

    opened by jkl469 1
  • problems of optical flow results when finetuning on real scene?

    problems of optical flow results when finetuning on real scene?

    Hi, have you tried training on real scene such as market or subway? I have finetuned the model according to IRR-PWC by using your './checkpoints/fastflownet_ft_mix.pth' in subway real scene, but the results are much worse than flownet2's. And I met another weird problem: during predicting, whether I multiply the optical flow result by div_flow(20), there seems no difference on the flow-png(flow result transferred to png). flownet2_1857 fastflow_train_1857_347

    opened by poincarelee 5
  • div_flow parameter

    div_flow parameter

    Hi, i am running your code. I saw in your paper the ground-truth flow was divided by 20 before training, but seems didn't see this parameter in FastFlowNet.py, have you used this div_flow parameter in code?

    opened by poincarelee 1
  • didn't process the occlusion loss?

    didn't process the occlusion loss?

    Hi, I have been trying to train fastflownet. After reference to the IRR-PWC, I found occlusion wasn't considered in fastflownet model, So I'd like to ask: if I want to use occlusion loss, how can occlusion be added to model part?

    opened by poincarelee 1
  • magic factors when upsample flow

    magic factors when upsample flow

    There are some magic factors when upsample flow to higher resolution: https://github.com/ltkong218/FastFlowNet/blob/main/models/FastFlowNet.py#L140

    https://github.com/ltkong218/FastFlowNet/blob/main/models/FastFlowNet.py#L147

    https://github.com/ltkong218/FastFlowNet/blob/main/models/FastFlowNet.py#L154

    https://github.com/ltkong218/FastFlowNet/blob/main/models/FastFlowNet.py#L161

    What's the meaninig of 0.625, 1.25, 2.5, 5? Is there any geometry motivation?

    I think the factors should be 2, because when you upsample a flow to a resolution with double height and width, the flow is double due to double pixels between origin points and corresponding points.

    opened by ahangchen 1
Owner
Tone
Computer Vision, Deep Learning
Tone
Pytorch implementation of FlowNet 2.0: Evolution of Optical Flow Estimation with Deep Networks

flownet2-pytorch Pytorch implementation of FlowNet 2.0: Evolution of Optical Flow Estimation with Deep Networks. Multiple GPU training is supported, a

NVIDIA Corporation 2.8k Dec 27, 2022
[CVPR 2022] Deep Equilibrium Optical Flow Estimation

Deep Equilibrium Optical Flow Estimation This is the official repo for the paper Deep Equilibrium Optical Flow Estimation (CVPR 2022), by Shaojie Bai*

CMU Locus Lab 136 Dec 18, 2022
A fast model to compute optical flow between two input images.

DCVNet: Dilated Cost Volumes for Fast Optical Flow This repository contains our implementation of the paper: @InProceedings{jiang2021dcvnet, title={

Huaizu Jiang 8 Sep 27, 2021
Just Go with the Flow: Self-Supervised Scene Flow Estimation

Just Go with the Flow: Self-Supervised Scene Flow Estimation Code release for the paper Just Go with the Flow: Self-Supervised Scene Flow Estimation,

Himangi Mittal 50 Nov 22, 2022
A project that uses optical flow and machine learning to detect aimhacking in video clips.

waldo-anticheat A project that aims to use optical flow and machine learning to visually detect cheating or hacking in video clips from fps games. Che

waldo.vision 542 Dec 3, 2022
A project that uses optical flow and machine learning to detect aimhacking in video clips.

waldo-anticheat A project that aims to use optical flow and machine learning to visually detect cheating or hacking in video clips from fps games. Che

waldo.vision 383 Nov 1, 2021
Traditional deepdream with VQGAN+CLIP and optical flow. Ready to use in Google Colab

VQGAN-CLIP-Video cat.mp4 policeman.mp4 schoolboy.mp4 forsenBOG.mp4

null 23 Oct 26, 2022
Demo code for paper "Learning optical flow from still images", CVPR 2021.

Depthstillation Demo code for "Learning optical flow from still images", CVPR 2021. [Project page] - [Paper] - [Supplementary] This code is provided t

null 130 Dec 25, 2022
Learning Optical Flow from a Few Matches (CVPR 2021)

Learning Optical Flow from a Few Matches This repository contains the source code for our paper: Learning Optical Flow from a Few Matches CVPR 2021 Sh

Shihao Jiang (Zac) 159 Dec 16, 2022
Unsupervised Learning of Multi-Frame Optical Flow with Occlusions

This is a Pytorch implementation of Janai, J., Güney, F., Ranjan, A., Black, M. and Geiger, A., Unsupervised Learning of Multi-Frame Optical Flow with

Anurag Ranjan 110 Nov 2, 2022
Demo code for ICCV 2021 paper "Sensor-Guided Optical Flow"

Sensor-Guided Optical Flow Demo code for "Sensor-Guided Optical Flow", ICCV 2021 This code is provided to replicate results with flow hints obtained f

null 10 Mar 16, 2022
MMFlow is an open source optical flow toolbox based on PyTorch

Documentation: https://mmflow.readthedocs.io/ Introduction English | 简体中文 MMFlow is an open source optical flow toolbox based on PyTorch. It is a part

OpenMMLab 688 Jan 6, 2023
UnFlow: Unsupervised Learning of Optical Flow with a Bidirectional Census Loss

UnFlow: Unsupervised Learning of Optical Flow with a Bidirectional Census Loss This repository contains the TensorFlow implementation of the paper UnF

Simon Meister 270 Nov 6, 2022
[CVPR2021 Oral] FFB6D: A Full Flow Bidirectional Fusion Network for 6D Pose Estimation.

FFB6D This is the official source code for the CVPR2021 Oral work, FFB6D: A Full Flow Biderectional Fusion Network for 6D Pose Estimation. (Arxiv) Tab

Yisheng (Ethan) He 201 Dec 28, 2022
Dewarping Document Image By Displacement Flow Estimation with Fully Convolutional Network.

Dewarping Document Image By Displacement Flow Estimation with Fully Convolutional Network

null 111 Dec 27, 2022
Dewarping Document Image By Displacement Flow Estimation with Fully Convolutional Network

Dewarping Document Image By Displacement Flow Estimation with Fully Convolutional Network

null 39 Aug 2, 2021
Re-implementation of the Noise Contrastive Estimation algorithm for pyTorch, following "Noise-contrastive estimation: A new estimation principle for unnormalized statistical models." (Gutmann and Hyvarinen, AISTATS 2010)

Noise Contrastive Estimation for pyTorch Overview This repository contains a re-implementation of the Noise Contrastive Estimation algorithm, implemen

Denis Emelin 42 Nov 24, 2022
This is the offical website for paper ''Category-consistent deep network learning for accurate vehicle logo recognition''

The Pytorch Implementation of Category-consistent deep network learning for accurate vehicle logo recognition This is the offical website for paper ''

Wanglong Lu 28 Oct 29, 2022
The implementation of the paper "A Deep Feature Aggregation Network for Accurate Indoor Camera Localization".

A Deep Feature Aggregation Network for Accurate Indoor Camera Localization This is the PyTorch implementation of our paper "A Deep Feature Aggregation

null 9 Dec 9, 2022