NeuFlow_v2

September 2, 2024 ยท View on GitHub

Official PyTorch implementation of paper:

NeuFlow v2: Push High-Efficiency Optical Flow To the Limit

Authors: Zhiyong Zhang, Aniket Gupta, Huaizu Jiang, Hanumant Singh

Installation (PyTorch >= 2.0 is required)

conda create --name neuflow python==3.8
conda activate neuflow
conda install pytorch==2.0.1 torchvision==0.15.2 pytorch-cuda=11.7 -c pytorch -c nvidia
pip install numpy opencv-python

Inference with HuggingFace ๐Ÿค—

Install huggingface-hub

pip install huggingface-hub

Inference uses our pretrained model, trained with multiple datasets, neuflow_mixed.pth:

python infer_hf.py

Inference

Inference uses our pretrained model, trained with multiple datasets, neuflow_mixed.pth:

python infer.py

Datasets

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

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

datasets
โ”œโ”€โ”€ FlyingChairs_release
โ”‚ย ย  โ””โ”€โ”€ data
โ”œโ”€โ”€ FlyingThings3D
โ”‚ย ย  โ”œโ”€โ”€ frames_cleanpass
โ”‚ย ย  โ”œโ”€โ”€ frames_finalpass
โ”‚ย ย  โ””โ”€โ”€ optical_flow
โ”œโ”€โ”€ HD1K
โ”‚ย ย  โ”œโ”€โ”€ hd1k_challenge
โ”‚ย ย  โ”œโ”€โ”€ hd1k_flow_gt
โ”‚ย ย  โ”œโ”€โ”€ hd1k_flow_uncertainty
โ”‚ย ย  โ””โ”€โ”€ hd1k_input
โ”œโ”€โ”€ KITTI
โ”‚ย ย  โ”œโ”€โ”€ testing
โ”‚ย ย  โ””โ”€โ”€ training
โ”œโ”€โ”€ Sintel
โ”‚ย ย  โ”œโ”€โ”€ test
โ”‚ย ย  โ””โ”€โ”€ training

Symlink your dataset root to datasets:

ln -s $YOUR_DATASET_ROOT datasets

Convert all your images and flows to .npy format to speed up data loading. This script provides an example of converting FlyingThings cleanpass data.

python images_flows_to_npy.py

Training

Simple training script:

python train.py \
--checkpoint_dir $YOUR_CHECKPOINT_DIR \
--stage things \
--val_dataset things sintel kitti \
--batch_size 32 \
--num_workers 4 \
--lr 1e-4 \
--val_freq 1000 \
--resume neuflow_things.pth \
--strict_resume

We trained on the FlyingThings dataset using 8x A5000 GPUs with the following command:

python -m torch.distributed.launch --nproc_per_node=8 --master_port=29501 train.py \
--checkpoint_dir $YOUR_CHECKPOINT_DIR \
--stage things \
--val_dataset things sintel kitti \
--batch_size 256 \
--num_workers 8 \
--lr 8e-4 \
--val_freq 500 \
--distributed

Evaluation

python eval.py \
--resume neuflow_things.pth