---
title: NeuFlow_v2
canonical_url: "https://www.modelscope.cn/models/z878570312/NeuFlow_v2"
md_url: "https://www.modelscope.cn/models/z878570312/NeuFlow_v2.md"
repository: z878570312/NeuFlow_v2
last_updated: 2024-08-27
license: "Apache License 2.0"
pipeline_tag: optical-flow
tasks:
  - optical-flow
library_name:
  - pytorch
frameworks:
  - pytorch
downloads: 16
stars: 1
tags:
  - "Optical flow"
---

# NeuFlow_v2

> NeuFlow_v2 - z878570312 在 ModelScope 开源的模型。NeuFlow v2是目前最高效的光流估计，在保持接近于state-of-the-art的精度同时， 提高10－70倍推理速度。

z878570312/NeuFlow_v2 是 ModelScope 魔搭社区上的optical-flow模型，采用 Apache License 2.0 许可。

- **Repository**: z878570312/NeuFlow_v2
- **License**: Apache License 2.0
- **Tasks**: optical-flow
- **Tags**: Optical flow
- **Downloads**: 16
- **Stars**: 1
- **Last updated**: 2024-08-27

Source: https://www.modelscope.cn/models/z878570312/NeuFlow_v2

---

# NeuFlow_v2

官方PyTorch实现论文：

[NeuFlow v2: Push High-Efficiency Optical Flow To the Limit](https://arxiv.org/abs/2408.10161)

作者： [Zhiyong Zhang](https://www.linkedin.com/in/zhiyong-zhang-0772a0159/), [Aniket Gupta](https://scholar.google.com/citations?hl=zh-CN&user=arsUOq0AAAAJ), [Huaizu Jiang](https://jianghz.me/), [Hanumant Singh](https://scholar.google.com/citations?user=1UEU5PEAAAAJ)

## 安装 (需要 PyTorch >= 2.0)

```
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
```

## 推理

使用预训练模型neuflow_mixed.pth推理, 预训练模型由混合数据集训练得到（Viper，FlyingThings，Sintel，Kitti):
```
python infer.py
```

<img src="example_result.jpg" width="400" >

## 数据集

用于训练和评估的数据集如下：

* [FlyingChairs](https://lmb.informatik.uni-freiburg.de/resources/datasets/FlyingChairs.en.html#flyingchairs)
* [FlyingThings3D](https://lmb.informatik.uni-freiburg.de/resources/datasets/SceneFlowDatasets.en.html)
* [Sintel](http://sintel.is.tue.mpg.de/)
* [KITTI](http://www.cvlibs.net/datasets/kitti/eval_scene_flow.php?benchmark=flow)
* [HD1K](http://hci-benchmark.iwr.uni-heidelberg.de/) 

Dataloader默认数据集被放置在 `datasets` 文件夹下，并以以下方式组织：

```
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
```

链接数据集文件夹到 `datasets`：

```shell
ln -s $YOUR_DATASET_ROOT datasets
```

将图片和光流文件转成.npy格式来加速数据加载。这个脚本给了一个例子用来转化FlyingThings cleanpass数据。
```
python images_flows_to_npy.py
```

## 训练

简单的训练脚本：
```
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
```

我们使用8张A5000显卡在FlyingThings数据集上训练，使用如下命令：
```
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
```

## 评估

```
python eval.py \
--resume neuflow_things.pth
```
