README.md 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
# PWCNet reimplement using paddlepaddle DyGraph
PWC-Net: CNNs for Optical Flow Using Pyramid, Warping, and Cost Volume.
# Environment 
```
cenntos7
paddle develop version (after 20191201) install from source
python3.7
SciPy 1.1.0
```
code will update for paddle v1.7 later.
# Compile correlation op
```
cd correlation_op
sh make.sh
```
# Datasets
1.Please download the `FlyingChairs dataset` and `FlyingChairs_train_val.txt` from https://lmb.informatik.uni-freiburg.de/resources/datasets

Or you can use `./data/download.sh` to download datasets.

We split the data to train and val by using `FlyingChairs_train_val.txt` with `1 for train and 2 for val`.
# Inference
Note that the paddle models `pwc_net_paddle.pdparams` and `pwc_net_chairs_paddle.pdparams` are transferred from the pytorch pth files `pwc_net.pth.tar` and `pwc_net_chairs.pth.tar`.

Run
```
python infer.py
```

| Input img1 | Input img2 |
|-------|------------|
| <img src='data/frame_0010.png' width=500> | <img src='data/frame_0011.png' width=500> |

|prediction with pwc_net_paddle.pdparams| prediction with pwc_net_chairs_paddle.pdparams|
|-------------|-------------|
|<img src='tmp/hsv_pd.png' width=500> | <img src='tmp/hsv_pd_chairs.png' width=500> |

# First Train with L2 loss
A single gpu is supported. Multi gpus will be supported later.

You should check parameters in `my_args.py` as you like.

And change them in `train.sh`.
```
--data_root
--train_val_txt
--batch_size
```
Then run
```
./train.sh
```
Some results during training can be seen
```
./img1.png
./img2.png
./hsv_pd.png # ground truth
./hsv_predict.png # output of model
```

# Finetune with L1 loss
finetune from your best pretrain model by adding --pretrained your_best_model_name eg. `--pretrained epoch_7_pwc_net_paddle`

Run
```
./finetune.sh
```
# Note
This code reimplement PWCNet like the code of `https://github.com/NVlabs/PWC-Net`
If you want to want to train like the paper
```
@InProceedings{Sun2018PWC-Net,
  author    = {Deqing Sun and Xiaodong Yang and Ming-Yu Liu and Jan Kautz},
  title     = {{PWC-Net}: CNNs for Optical Flow Using Pyramid, Warping, and Cost Volume},
  booktitle = CVPR,
  year      = {2018},
}
```
Please use all the datasets in `./data/download.sh` if you like. And use the code in `./data/datasets.py`.

Reference works
```
https://github.com/NVlabs/PWC-Net
https://github.com/ClementPinard/FlowNetPytorch
https://github.com/NVIDIA/flownet2-pytorch/blob/master/datasets.py
```