Reference:
1. 光流估计——从传统方法到深度学习
2. Flownet2 NVIDIA pytorch最新安装教程 有效的避坑教程
3. 使用NVIDIA flownet2-pytorch实现生成光流
默认背景:已安装好Anaconda3,cuda 10.0,cuDnn 7.6.0
jupyter notebook --generate-config
生成配置文件c.NotebookApp.notebook_dir = 'D:\ForPython\workplace'
%USERPROFILE%
删掉即可github下载 | 百度网盘下载-提取码:2333
conda create -n pytorch python=3.5
conda activate pytorch
版本根据情况选择:win10 + cuda10 + python3.5 对应下载
附-以上2个文件的网盘链接 提取码:2333
pip install D:\ForPython\pytorch\torch-1.0.1-cp35-cp35m-win_amd64.whl
pip install D:\ForPython\pytorch\torchvision-0.4.0-cp35-cp35m-win_amd64.whl
python
import torch
x=torch.rand(4,3)
print(x)
# 成功运行即可 ↓
# tensor([[0.8313, 0.3844, 0.0501],
# [0.8976, 0.7217, 0.2202],
# [0.2422, 0.4707, 0.3695],
# [0.8791, 0.2858, 0.5675]])
python setup.py install
# 报错
# fatal error C1021: invalid preprocessor command 'warning'
打开torch/torch.h文件删掉这段warning ↓
#warning \
"Including torch/torch.h for C++ extensions is deprecated. Please include torch/extension.h"
再次运行
python setup.py install
又报了error,此时打开 THCNumerics.cuh
D:\ForPython\ANACONDA\envs\pytorch\Lib\site-packages\torch\lib\include\THC\THCNumerics.cuh
将以下内容 ↓ 注释掉
static inline __host__ __device__ bool lt(at::Half a, at::Half b) { return a < b; }
static inline __host__ __device__ bool le(at::Half a, at::Half b) { return a <= b; }
static inline __host__ __device__ bool gt(at::Half a, at::Half b) { return a > b; }
static inline __host__ __device__ bool ge(at::Half a, at::Half b) { return a >= b; }
static inline __host__ __device__ bool eq(at::Half a, at::Half b) { return a == b; }
static inline __host__ __device__ bool ne(at::Half a, at::Half b) { return a != b; }
环境配置完毕,在flownet2文件目录下执行python main.py -h
,可查看帮助指令
(pytorch) D:\ForPython\workplace\flownet\flownet2-pytorch-master>python main.py --help
usage: main.py [-h] [--start_epoch START_EPOCH] [--total_epochs TOTAL_EPOCHS]
[--batch_size BATCH_SIZE] [--train_n_batches TRAIN_N_BATCHES]
[--crop_size CROP_SIZE [CROP_SIZE ...]]
[--gradient_clip GRADIENT_CLIP]
[--schedule_lr_frequency SCHEDULE_LR_FREQUENCY]
[--schedule_lr_fraction SCHEDULE_LR_FRACTION]
[--rgb_max RGB_MAX] [--number_workers NUMBER_WORKERS]
[--number_gpus NUMBER_GPUS] [--no_cuda] [--seed SEED]
[--name NAME] [--save SAVE]
[--validation_frequency VALIDATION_FREQUENCY]
[--validation_n_batches VALIDATION_N_BATCHES]
[--render_validation] [--inference] [--inference_visualize]
[--inference_size INFERENCE_SIZE [INFERENCE_SIZE ...]]
[--inference_batch_size INFERENCE_BATCH_SIZE]
[--inference_n_batches INFERENCE_N_BATCHES] [--save_flow]
[--resume PATH] [--log_frequency LOG_FREQUENCY]
[--skip_training] [--skip_validation] [--fp16]
[--fp16_scale FP16_SCALE]
[--model {FlowNet2CSS,FlowNet2S,ChannelNorm,FlowNet2,FlowNet2C,tofp32,FlowNet2SD,Resample2d,tofp16,FlowNet2CS}]
anaconda activate pytorch
cd D:\ForPython\workplace\flownet\flownet2-pytorch-master
d:
python main.py -h
# 提示:No module named 'tensorboardX'
# No module named 'setproctitle'
# No module named 'colorama'
# No module named 'tqdm'
# 还会出现很多其它包的缺失,缺什么安装什么即可
pip install tensorboardX
pip install setproctitle
pip install colorama
pip install tqdm
# 若安装速度太慢,可加上镜像源,例如:
pip install --index-url https://pypi.douban.com/simple tqdm
# 这里注意按装 scipy
# 若版本太高,会出现
# ImportError: cannot import name ‘imread’
# 指定版本为1.2.1 亲测可行
pip install --index-url https://pypi.douban.com/simple scipy==1.2.1
安装setproctitle遇到的error: Microsoft Visual C++ 14.0 is required.
点击下载Microsoft Visual C++ Build Tools 2015,默认安装即可。
无法科学上网,折腾了好久才下好,为方便其它小伙伴,已传到网盘。
网盘链接-提取码:2333,包括:
目前我只使用到MPI-Sintel-complete这个数据集和checkpoints
# 激活pytorch环境
conda activate pytorch
# 进入flownet2工作目录
cd D:\ForPython\workplace\flownet\flownet2-pytorch-master
d:
# 键入命令,选择模型、输出类型、输出路径、数据集类型、数据集路径、权重文件路径等
python main.py
--inference
--model FlowNet2
--save_flow
--save ./output/me_samm_006_1_2
--inference_dataset ImagesFromFolder
--inference_dataset_root ./datasets/micro_expression/samm/006/006_1_2/2
--resume ./models/checkpoints/FlowNet2_checkpoint.pth.tar
python main.py --help
查看./output/inference/run.epoch-0-flow-field
文件夹,生成的.flo文件。Traceback (most recent call last):
File "main.py", line 111, in
args.current_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).rstrip()
File "D:\ForPython\ANACONDA\envs\pytorch\lib\subprocess.py", line 316, in check_output
**kwargs).stdout
File "D:\ForPython\ANACONDA\envs\pytorch\lib\subprocess.py", line 383, in run
with Popen(*popenargs, **kwargs) as process:
File "D:\ForPython\ANACONDA\envs\pytorch\lib\subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "D:\ForPython\ANACONDA\envs\pytorch\lib\subprocess.py", line 957, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
解决方案:打开main.py 将line111,123,124注释掉。参考->问答区issue108
ImportError: DLL load failed: 页面文件太小,无法完成操作。
IndexError: Traceback (most recent call last):
File "D:\ForPython\ANACONDA\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "D:\ForPython\ANACONDA\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 138, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "D:\ForPython\workplace\flownet\flownet2-pytorch-master\datasets.py", line 348, in __getitem__
img1 = frame_utils.read_gen(self.image_list[index][0])
File "D:\ForPython\workplace\flownet\flownet2-pytorch-master\utils\frame_utils.py", line 10, in read_gen
if im.shape[2] > 3:
IndexError: tuple index out of range
解决方案:后台进程太多了,关掉就好了(尤其那个腾讯会议占gpu60%+,点名批评!)
pip install --index-url https://pypi.douban.com/simple numpy tqdm matplotlib eel ffmpeg
有三种使用方式,命令行、Python、GUI,这里使用命令行。
# 进入到flowiz所在文件目录
cd D:\ForPython\workplace\flownet\youngqh-flowiz-master\flowiz
# demo/flo/*.flo 为 flo 所在文件夹路径
# --outdir 输出 png 存放的目录
python -m flowiz demo/flo/*.flo --outdir demo/png/
# (注意,只能一张一张图片处理)例如:
python -m flowiz demo/flo/samm006_1_2/2.flo --outdir demo/png/samm006_1_2