Pytorch implementation of FlowNet 2.0: Evolution of Optical Flow Estimation with Deep Networks

Overview

flownet2-pytorch

Pytorch implementation of FlowNet 2.0: Evolution of Optical Flow Estimation with Deep Networks.

Multiple GPU training is supported, and the code provides examples for training or inference on MPI-Sintel clean and final datasets. The same commands can be used for training or inference with other datasets. See below for more detail.

Inference using fp16 (half-precision) is also supported.

For more help, type

python main.py --help

Network architectures

Below are the different flownet neural network architectures that are provided.
A batchnorm version for each network is also available.

  • FlowNet2S
  • FlowNet2C
  • FlowNet2CS
  • FlowNet2CSS
  • FlowNet2SD
  • FlowNet2

Custom layers

FlowNet2 or FlowNet2C* achitectures rely on custom layers Resample2d or Correlation.
A pytorch implementation of these layers with cuda kernels are available at ./networks.
Note : Currently, half precision kernels are not available for these layers.

Data Loaders

Dataloaders for FlyingChairs, FlyingThings, ChairsSDHom and ImagesFromFolder are available in datasets.py.

Loss Functions

L1 and L2 losses with multi-scale support are available in losses.py.

Installation

# get flownet2-pytorch source
git clone https://github.com/NVIDIA/flownet2-pytorch.git
cd flownet2-pytorch

# install custom layers
bash install.sh

Python requirements

Currently, the code supports python 3

  • numpy
  • PyTorch ( == 0.4.1, for <= 0.4.0 see branch python36-PyTorch0.4)
  • scipy
  • scikit-image
  • tensorboardX
  • colorama, tqdm, setproctitle

Converted Caffe Pre-trained Models

We've included caffe pre-trained models. Should you use these pre-trained weights, please adhere to the license agreements.

Inference

# Example on MPISintel Clean   
python main.py --inference --model FlowNet2 --save_flow --inference_dataset MpiSintelClean \
--inference_dataset_root /path/to/mpi-sintel/clean/dataset \
--resume /path/to/checkpoints 

Training and validation

# Example on MPISintel Final and Clean, with L1Loss on FlowNet2 model
python main.py --batch_size 8 --model FlowNet2 --loss=L1Loss --optimizer=Adam --optimizer_lr=1e-4 \
--training_dataset MpiSintelFinal --training_dataset_root /path/to/mpi-sintel/final/dataset  \
--validation_dataset MpiSintelClean --validation_dataset_root /path/to/mpi-sintel/clean/dataset

# Example on MPISintel Final and Clean, with MultiScale loss on FlowNet2C model 
python main.py --batch_size 8 --model FlowNet2C --optimizer=Adam --optimizer_lr=1e-4 --loss=MultiScale --loss_norm=L1 \
--loss_numScales=5 --loss_startScale=4 --optimizer_lr=1e-4 --crop_size 384 512 \
--training_dataset FlyingChairs --training_dataset_root /path/to/flying-chairs/dataset  \
--validation_dataset MpiSintelClean --validation_dataset_root /path/to/mpi-sintel/clean/dataset

Results on MPI-Sintel

Predicted flows on MPI-Sintel

Reference

If you find this implementation useful in your work, please acknowledge it appropriately and cite the paper:

@InProceedings{IMKDB17,
  author       = "E. Ilg and N. Mayer and T. Saikia and M. Keuper and A. Dosovitskiy and T. Brox",
  title        = "FlowNet 2.0: Evolution of Optical Flow Estimation with Deep Networks",
  booktitle    = "IEEE Conference on Computer Vision and Pattern Recognition (CVPR)",
  month        = "Jul",
  year         = "2017",
  url          = "http://lmb.informatik.uni-freiburg.de//Publications/2017/IMKDB17"
}
@misc{flownet2-pytorch,
  author = {Fitsum Reda and Robert Pottorff and Jon Barker and Bryan Catanzaro},
  title = {flownet2-pytorch: Pytorch implementation of FlowNet 2.0: Evolution of Optical Flow Estimation with Deep Networks},
  year = {2017},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/NVIDIA/flownet2-pytorch}}
}

Related Optical Flow Work from Nvidia

Code (in Caffe and Pytorch): PWC-Net
Paper : PWC-Net: CNNs for Optical Flow Using Pyramid, Warping, and Cost Volume.

Acknowledgments

Parts of this code were derived, as noted in the code, from ClementPinard/FlowNetPytorch.

Comments
  • Error when building CUDA kernels with PyTorch 1.6.0

    Error when building CUDA kernels with PyTorch 1.6.0

    I'm unable to build the CUDA kernels for channelnorm, resample2d, correlation when using PyTorch >= 1.5.1. However, I'm able to successfully build them with PyTorch <= 1.4.0. Is there a way to make this work since I need to use PyTorch >= 1.5.1?

    ninja: build stopped: subcommand failed.
    Traceback (most recent call last):
      File "/home/rakesh/software/miniconda2/envs/cu101torch151s2/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1423, in _run_ninja_build
        check=True)
      File "/home/rakesh/software/miniconda2/envs/cu101torch151s2/lib/python3.6/subprocess.py", line 438, in run
        output=stdout, stderr=stderr)
    subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "setup.py", line 32, in <module>
        'build_ext': BuildExtension
      File "/home/rakesh/software/miniconda2/envs/cu101torch151s2/lib/python3.6/site-packages/setuptools/__init__.py", line 163, in setup
        return distutils.core.setup(**attrs)
    
    .
    .
    .
    .
    
      File "/home/rakesh/software/miniconda2/envs/cu101torch151s2/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1163, in _write_ninja_file_and_compile_objects
        error_prefix='Error compiling objects for extension')
      File "/home/rakesh/software/miniconda2/envs/cu101torch151s2/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1436, in _run_ninja_build
        raise RuntimeError(message)
    RuntimeError: Error compiling objects for extension
    
    opened by rakeshjasti 16
  • I keep getting error saying the list index out of range

    I keep getting error saying the list index out of range

    When I try to run flownet2 with this input

    python main.py --batch_size 8 --model FlowNet2C --optimizer=Adam --optimizer_lr=1e-4 --loss=MultiScale --loss_norm=L1
    --loss_numScales=5 --loss_startScale=4 --optimizer_lr=1e-4 --crop_size 384 512
    --training_dataset FlyingChairs --training_dataset_root /home/projects/flownet2-pytorch/FlyingChairs/FlyingChairs_release/data
    --validation_dataset MpiSintelClean --validation_dataset_root /home/projects/flownet2-pytorch/MPI-Sintel-complete/training/clean

    But I keep getting error saying

    File "main.py", line 140, in validation_dataset = args.validation_dataset_class(args, True, **tools.kwargs_from_args(args, 'validation_dataset')) File "/home/projects/flownet2-pytorch/datasets.py", line 108, in init super(MpiSintelClean, self).init(args, is_cropped = is_cropped, root = root, dstype = 'clean', replicates = replicates) File "/home/projects/flownet2-pytorch/datasets.py", line 66, in init self.frame_size = frame_utils.read_gen(self.image_list[0][0]).shape IndexError: list index out of range

    How should I resolve this issue?

    not reproducible 
    opened by kimj09 14
  • About

    About "Convert Official Caffe Pre-trained Models to PyTorch"

    I have followed your instructions to convert the models but failed! So I am wondering whether you could share the well-converted models, besides I am wondering that whether you have implemented the evaluation code to get the EPE performance over different dataset?

    Regards

    opened by PkuRainBow 11
  • run bash install.sh error

    run bash install.sh error

    Compiling correlation kernels by nvcc... In file included from /home/zhuyisheng/anaconda3/envs/py27/lib/python2.7/site-packages/torch/utils/ffi/../../lib/include/THC/THC.h:4:0, from _correlation.c:493: /home/zhuyisheng/anaconda3/envs/py27/lib/python2.7/site-packages/torch/utils/ffi/../../lib/include/THC/THCGeneral.h:9:18: fatal error: cuda.h: No such file or directory #include "cuda.h" ^ compilation terminated. Traceback (most recent call last): File "build.py", line 31, in ffi.build() File "/home/zhuyisheng/anaconda3/envs/py27/lib/python2.7/site-packages/torch/utils/ffi/init.py", line 167, in build _build_extension(ffi, cffi_wrapper_name, target_dir, verbose) File "/home/zhuyisheng/anaconda3/envs/py27/lib/python2.7/site-packages/torch/utils/ffi/init.py", line 103, in _build_extension ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname) File "/home/zhuyisheng/anaconda3/envs/py27/lib/python2.7/site-packages/cffi/api.py", line 697, in compile compiler_verbose=verbose, debug=debug, **kwds) File "/home/zhuyisheng/anaconda3/envs/py27/lib/python2.7/site-packages/cffi/recompiler.py", line 1520, in recompile compiler_verbose, debug) File "/home/zhuyisheng/anaconda3/envs/py27/lib/python2.7/site-packages/cffi/ffiplatform.py", line 22, in compile outputfilename = _build(tmpdir, ext, compiler_verbose, debug) File "/home/zhuyisheng/anaconda3/envs/py27/lib/python2.7/site-packages/cffi/ffiplatform.py", line 58, in _build raise VerificationError('%s: %s' % (e.class.name, e)) cffi.error.VerificationError: CompileError: command 'gcc' failed with exit status 1

    opened by Zhuysheng 10
  • Python3 version

    Python3 version

    I met some problem when I tried to run the code under python3.

    If the code only supports python2 right now, how can I upgrade it?

    $ python3 main.py
    Traceback (most recent call last):
      File "main.py", line 13, in <module>
        import FlowNetC
      File "/notebooks/data/vinet/FlowNetC.py", line 8, in <module>
        from correlation_package.modules.correlation import Correlation
      File "/notebooks/data/vinet/correlation_package/modules/correlation.py", line 3, in <module>
        from ..functions.correlation import CorrelationFunction
      File "/notebooks/data/vinet/correlation_package/functions/correlation.py", line 3, in <module>
        from .._ext import correlation
      File "/notebooks/data/vinet/correlation_package/_ext/correlation/__init__.py", line 3, in <module>
        from ._correlation import lib as _lib, ffi as _ffi
    ImportError: /notebooks/data/vinet/correlation_package/_ext/correlation/_correlation.so: undefined symbol: PyInt_FromLong
    
    opened by HTLife 10
  • Fail to adapt to Pytorch Version 0.3

    Fail to adapt to Pytorch Version 0.3

    I am trying to adapt the code to new Pytorch version and higher python version. I modify the code based on Pytorch source code, especially I modify the customized layers as follows: functions: `

    class ChannelNormFunction(Function):
    
        @staticmethod
        def forward(ctx, input1, norm_deg=2):
            # self.save_for_backward(input1)
            ctx.norm_deg = norm_deg
            assert(input1.is_contiguous() == True)
            with torch.cuda.device_of(input1):
                b, _, h, w = input1.size()
                output = input1.new().resize_(b, 1, h, w).zero_()
                ChannelNorm_cuda_forward(input1, output, ctx.norm_deg)
            ctx.save_for_backward(input1, output)
            return output
    
        @staticmethod
        def backward(ctx, gradOutput):
            input1, output = ctx.saved_tensors
            with torch.cuda.device_of(input1):
                b, c, h, w = input1.size()
                gradInput1 = input1.new().resize_(b,c,h,w).zero_()
                ChannelNorm_cuda_backward(input1, output, gradOutput, gradInput1, ctx.norm_deg)
    
            return gradInput1, None
    

    `

    modules `

    class ChannelNorm(Module):
        def __init__(self, norm_deg=2):
            super(ChannelNorm, self).__init__()
            self.norm_deg = norm_deg
    
        def forward(self, input1):
            return ChannelNormFunction.apply(input1, self.norm_deg)
    

    With other grammatical modifications, I am able to run the code in inference mode. But I fail to train because backpropagation is not working correctly. I met this error:

    File "main.py", line 434, in train_loss, iterations = train(args=args, epoch=epoch, start_iteration=global_iteration, data_loader=train_loader, model=model_and_loss, optimizer=optimizer, logger=train_logger, offset=offset) File "main.py", line 301, in train loss_val.backward() File "/home/cdeng/anaconda3/envs/py27/lib/python2.7/site-packages/torch/autograd/variable.py", line 167, in backward torch.autograd.backward(self, gradient, retain_graph, create_graph, retain_variables) File "/home/cdeng/anaconda3/envs/py27/lib/python2.7/site-packages/torch/autograd/init.py", line 99, in backward variables, grad_variables, retain_graph) File "/home/cdeng/anaconda3/envs/py27/lib/python2.7/site-packages/torch/autograd/function.py", line 91, in apply return self._forward_cls.backward(self, *args) File "/home/cdeng/Thesis/flownet2-pytorch/networks/channelnorm_package/functions/channelnorm.py", line 32, in backward ChannelNorm_cuda_backward(input1, output, gradOutput, gradInput1, ctx.norm_deg) File "/home/cdeng/anaconda3/envs/py27/lib/python2.7/site-packages/torch/utils/ffi/init.py", line 180, in safe_call result = torch._C._safe_call(*args, **kwargs) TypeError: initializer for ctype 'struct THCudaTensor *' must be a cdata pointer, not Variable

    Could someone have a look? And help me locate and fix the bug? Great thanks!

    good first issue 
    opened by MatthewD1993 10
  • Extremely slow for training Flownet2C

    Extremely slow for training Flownet2C

    I'm trying to train FlowNet2 separately. It's very slow when I train the flownet2C, around 22s/batch with batch_size=32 on 2 P40 GPUs, while flownet2S takes 1.5s/batch. I don't know if there any problems, I want to know how fast you train FlowNet2C or FlowNet2

    opened by lliuz 10
  • RuntimeError: function Resample2dFunctionBackward returned an incorrect number of gradients (expected 4, got 3)

    RuntimeError: function Resample2dFunctionBackward returned an incorrect number of gradients (expected 4, got 3)

    Hi~I tried to train flownet2 using MPI-Sintel dataset,but I got such errors and can't make it. My env is: cuda10 pytorch1.1.0 python3 ubuntu18 And I had successfully done inference using model provided by author. Somebody knows how to fix it? Traceback (most recent call last):: 89.164, load: 4.4e-05: 100%|#| 130/130.0 [00:11<00:00, 12.37it/s] File "main.py", line 426, in <module>t] train_loss, iterations = train(args=args, epoch=epoch, start_iteration=global_iteration, data_loader=train_loader, model=model_and_loss, optimizer=optimizer, logger=train_logger, offset=offset) File "main.py", line 292, in train loss_val.backward() File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/site-packages/torch/tensor.py", line 107, in backward torch.autograd.backward(self, gradient, retain_graph, create_graph) File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/site-packages/torch/autograd/__init__.py", line 93, in backward allow_unreachable=True) # allow_unreachable flag RuntimeError: function Resample2dFunctionBackward returned an incorrect number of gradients (expected 4, got 3) Exception in thread Thread-5: Traceback (most recent call last): File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/threading.py", line 916, in _bootstrap_inner self.run() File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/site-packages/torch/utils/data/_utils/pin_memory.py", line 21, in _pin_memory_loop r = in_queue.get(timeout=MP_STATUS_CHECK_INTERVAL) File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/multiprocessing/queues.py", line 113, in get return _ForkingPickler.loads(res) File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/site-packages/torch/multiprocessing/reductions.py", line 276, in rebuild_storage_fd fd = df.detach() File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/multiprocessing/resource_sharer.py", line 57, in detach with _resource_sharer.get_connection(self._id) as conn: File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/multiprocessing/resource_sharer.py", line 87, in get_connection c = Client(address, authkey=process.current_process().authkey) File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/multiprocessing/connection.py", line 493, in Client answer_challenge(c, authkey) File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/multiprocessing/connection.py", line 732, in answer_challenge message = connection.recv_bytes(256) # reject large message File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/multiprocessing/connection.py", line 216, in recv_bytes buf = self._recv_bytes(maxlength) File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/multiprocessing/connection.py", line 407, in _recv_bytes buf = self._recv(4) File "/home/lijinlong/anaconda3/envs/flownet/lib/python3.6/multiprocessing/connection.py", line 379, in _recv chunk = read(handle, remaining) ConnectionResetError: [Errno 104] Connection reset by peer

    bug 
    opened by TyroneLi 9
  • Asking support for Pytorch 1.0

    Asking support for Pytorch 1.0

    When I compile the code (sh install.sh) using Pytorch 1.0 (cuda 10), it reported error about not finding:

    at::globalContext().getCurrentCUDAStream() 
    

    in source.

    As pytorch 1.0 stable release has been released for months, it may be the proper time to move the project foward.

    opened by TomHeaven 9
  • Compile Error

    Compile Error

    I could not complie with the new install.sh. Here is a part of the errors (similar for the three setup.py):

    (...)
    /usr/local/cuda/bin/nvcc -I/home/master/07/yaliangchang/miniconda3/envs/Shift-Net_pytorch/lib/pythoe3.7/site-packages/torch/lib/include -I/home/master/07/yaliangchang/miniconda3/envs/Shift-Net_pytorch/li /python
    3.7/site-packages/torch/lib/include/TH -I/home/master/07/yaliangchang/miniconda3/envs/Shift-Net_pytorch/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/master/07/yaliangchang/
    miniconda3/envs/Shift-Net_pytorch/include/python3.7m -c channelnorm_kernel.cu -o build/temp.linux-x86_64-3.7/channelnorm_kernel.o -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode
    arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_70,code=compute_70 -DTORCH_EXTENSION_NAME=channelnorm_cuda -D_GLIBCXX_USE_CXX11_ABI=0 --compiler-options '-fPIC' -std=c++11
    /usr/include/c++/6/tuple: In instantiation of ‘otatic constexpr bool std::_TC<<anonymous>, _Elements>::_MoveConstructibleTuple() [with _UElements = {std::tuple<at::Tensor, at::Tensor, at::Tensor>}; bool <anonym
    us> = true; _Elements = {at::Tensor, at::Tensor, at::Tensor}]’:
    /usr/include/c++/6/tuple:626:248:   required by substitution of ‘template<class ... _UElemen:s, typename std::enable_if<(((std:_ITC<(sizeof... (_UElements) == 1), at::Tensor, at::Tentor, at::Tensor>::_NotSameTu
    le<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), at::Tensor, at::Tensor, at::Tensor>::_MoveConstructibleTuple<_UElements ...>()) && std::_TC<(1ul == sizeof... (_UElements)), at::Tensor, at::Tens
    or, at::Tensor>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && (3ul >= 1)), bool>::type <anonymous> > constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {std::tu
    ple<at::Tensor, at::Tensor, at::Tensor>}; typename std::enable_if<(((std::_TC<(sizeof... (_UElements) == 1), at::Tensor, at::Tensor, at::Tensor>::_NotSameTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_U
    Elements)), at::Tensor, at::Tensor, at::Tensor>::_MoveConstructibleTuple<_UElements ...>()) && std::_TC<(1ul == sizeof... (_UElements)), at::Tensor, at::Tensor, at::Tensor>::_ImplicitlyMoveConvertibleTuple<_UEle
    ments ...>()) && (3ul >= 1)), bool>::type <anonymous> = <missing>]’
    /home/master/07/yaliangchang/miniconda3/envs/Shift-Net_pytorch/lib/python3.7/site-packages/torch/lib/include/ATen/TensorMethods.h:646:36:   required from here
    /usr/include/c++/6/tuple:483:67: error: mismatched argument pack lengths while expanding ‘std::is_constructible<_Elements, _UElements&&>’
           return __and_<is_constructible<_Elements, _UElements&&>...>::value;
                                                                       ^~~~~
    /usr/include/c++/6/tuple:484:1: error: body of constexpr function ‘static constexpr bool std::_TC<<anonymous>, _Elements>::_MoveConstructibleTuple() [with _UElements = {std::tuple<at::Tensor, at::Tensor, at::Te
    n                                                                 ‘                                                                                                                                              n
    sor>}; bool <anonymous> = true; _Elements = {at::Tensor, at::Tensor, at::Tensor}]’ not a return-statement
         }
     ^
    /usr/include/c++/6/tuple: In instantiation of ‘static constexpr bool std::_TC<<anonymous>, _Elements>::_ImplicitlyMoveConvertibleTuple() [with _UElements = {std::tuple<at::Tensor, at::Tensor, at::Tensor>}; bool
                                                  ‘
    <anonymous> = true; _Elements = {at::Tensor, at::Tensor, at::Tensor}]’:
    /usr/include/c++/6/tuple:626:362:   required by substitution of ‘tem’ate<class ... _UElements, typename std::enable_if<(((std::_TC<(sizeof... (_UElements) == 1), at::Tensor, at::Tensor, at::Tensor>::_NotSameTu
    p                                                               ‘                                                                                                                                                p
    le<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), at::Tensor, at::Tensor, at::Tensor>::_MoveConstructibleTuple<_UElements ...>()) && std::_TC<(1ul == sizeof... (_UElements)), at::Tensor, at::Tens
    or, at::Tensor>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && (3ul >= 1)), bool>::type <anonymous> > constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {std::tu
    ple<at::Tensor, at::Tensor, at::Tensor>}; typename std::enable_if<(((std::_TC<(sizeof... (_UElements) == 1), at::Tensor, at::Tensor, at::Tensor>::_NotSameTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_U
    Elements)), at::Tensor, at::Tensor, at::Tensor>::_MoveConstructibleTuple<_UElements ...>()) && std::_TC<(1ul == sizeof... (_UElements)), at::Tensor, at::Tensor, at::Tensor>::_ImplicitlyMoveConvertibleTuple<_UEle
    ments ...>()) && (3ul >= 1)), bool>::type <anonymous> = <missing>]’
    /home/master/07/yaliangchang/miniconda3/envs/Shift-Net_pytorch/lib/python3.7/site-packages/torch/lib/include/ATen/TensorMethods.h:646:36:   required from here
    /usr/include/c++/6/tuple:489:65: error: mismatched argument pack lengths while expanding ‘std::is_convertible<_UElements&&, _Elements>’
           return __and_<is_convertible<_UElements&&, _Elements>...>::value;
                                                                     ^~~~~
    /usr/include/c++/6/tuple:490:1: error: body of constexpr function ‘static constexpr bool std::_TC<<anonymous>, _Elements>::_ImplicitlyMoveConvertibleTuple() [with _UElements = {std::tuple<at::Tensor, at::Tensor
    ,                                                                 ‘                                                                                                                                              ,
     at::Tensor>}; bool <anonymous> = true; _Elements = {at::Tensor, at::Tensor, at::Tensor}]’ not a return-statement
         }
     ^
    /usr/include/c++/6/tuple: In instantiation of ‘static constexpr bool std::_TC<<anonymous>, _Elements>::_NonNestedTuple() [with _SrcTuple = const std::tuple<at::Tensor, at::Tensor, at::Tensor>&; bool <anonymous>
                                                  ‘
    = true; _Elements = {at::Tensor, at::Tensor, at::Tensor}]’:
    /usr/include/c++/6/tuple:662:419:   required by substitut’n of ‘template<class ... _UElements, class _Dummy, typename std::enable_if<((std::_TC<(1ul == sizeof... (_UElements)), at::Tensor, at::Tensor, at::Tens
    o                                                               ‘                                                                                                                                                o
    r>::_ConstructibleTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), at::Tensor, at::Tensor, at::Tensor>::_ImplicitlyConvertibleTuple<_UElements ...>()) && std::_TC<(std::is_same<_Dummy, void>:
    :value && (1ul == 1)), at::Tensor, at::Tensor, at::Tensor>::_NonNestedTuple<const tuple<_Elements ...>&>()), bool>::type <anonymous> > constexpr std::tuple< <template-parameter-1-1> >::tuple(const std::tuple<_Ar
    gs1 ...>&) [with _UElements = {at::Tensor, at::Tensor, at::Tensor}; _Dummy = void; typename std::enable_if<((std::_TC<(1ul == sizeof... (_UElements)), at::Tensor, at::Tensor, at::Tensor>::_ConstructibleTuple<_UE
    lements ...>() && std::_TC<(1ul == sizeof... (_UElements)), at::Tensor, at::Tensor, at::Tensor>::_ImplicitlyConvertibleTuple<_UElements ...>()) && std::_TC<(std::is_same<_Dummy, void>::value && (1ul == 1)), at::
    Tensor, at::Tensor, at::Tensor>::_NonNestedTuple<const tuple<_Elements ...>&>()), bool>::type <anonymous> = <missing>]’
    /home/master/07/yaliangchang/miniconda3/envs/Shift-Net_pytorch/lib/python3.7/site-packages/torch/lib/include/ATen/TensorMethods.h:646:36:   required from here
    /usr/include/c++/6/tuple:495:244: error: wrong number of template arguments (4, should be 2)
           return  __and_<__not_<is_same<tuple<_Elements...>,
    (...)
    
    $ gcc --version
    gcc (Ubuntu 6.4.0-17ubuntu1) 6.4.0 20180424
    Copyright (C) 2017 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
    $ nvcc -V
    nvcc: NVIDIA (R) Cuda compiler driver
    Copyright (c) 2005-2017 NVIDIA Corporation
    Built on Fri_Sep__1_21:08:03_CDT_2017
    Cuda compilation tools, release 9.0, V9.0.176
    
    opened by amjltc295 9
  • About the MPI-Sintel datasets

    About the MPI-Sintel datasets

    In your command:

    # Example on MPISintel Final and Clean, with MultiScale loss on FlowNet2C model 
    python main.py --batch_size 8 --model FlowNet2C --optimizer=Adam --optimizer_lr=1e-4 --loss=MultiScale --loss_norm=L1 \
    --loss_numScales=5 --loss_startScale=4 --optimizer_lr=1e-4 --crop_size 384 512 \
    --training_dataset FlyingChairs --training_dataset_root /path/to/flying-chairs/dataset  \
    --validation_dataset MpiSintelClean --validation_dataset_root /path/to/mpi-sintel/clean/dataset
    

    We need to pass the path of the MPI-Sintel datasets. So I use the absolute path to the clean folder under the train folder. But the image files and flow files are arranged separately.

    Here the original folder tree of MPI-Sintel datasets, so I am wondering do I need to rearrange the files as the images and flo files are arranged seperately while your code seems can not deal with the original tree structure. So how should I change this?

    image

    opened by PkuRainBow 8
  • Training with MultiScale loss

    Training with MultiScale loss

    Hello, I'm trying to fine-tune the whole FlowNet2 network from the provided pre-trained weights, with the multi-scale loss by:

    ...
    --loss=MultiScale \
    --loss_norm=L1 \
    ...
    

    However, the model returns only single flow output from the last fusion layer

            return flownetfusion_flow
    

    and in the MultiScale class, the type of the flow output, which is passed as an argument, is checked

            if type(output) is tuple:
                target = self.div_flow * target
                for i, output_ in enumerate(output):
                    target_ = self.multiScales[i](target)
                    epevalue += self.loss_weights[i]*EPE(output_, target_)
                    lossvalue += self.loss_weights[i]*self.loss(output_, target_)
                return [lossvalue, epevalue]
            else:
                epevalue += EPE(output, target)
                lossvalue += self.loss(output, target)
                return  [lossvalue, epevalue]
    

    The problem is that the type of model output is not always a tuple, so it falls to the else branch, which is the same as a simple L1loss.

    Looking at the related issue: issue 28, I guess the multiscale loss was designed to train only a part of the model, i.e. FlowNetC/S, separately. Is it right?

    Thank you

    opened by zinuok 0
  • I cannot load the pretrained FlowNetS

    I cannot load the pretrained FlowNetS

    I tried to load the pretrained FlowNetS model (https://drive.google.com/drive/folders/16eo3p9dO_vmssxRoZCmWkTpNjKRzJzn5), but I have the following issues:

    Model_dict of the pretrained model:

    odict_keys(['conv1.0.weight', 'conv1.0.bias', 'conv2.0.weight', 'conv2.0.bias', 'conv3.0.weight', 'conv3.0.bias', 'conv3_1.0.weight', 'conv3_1.0.bias', 'conv4.0.weight', 'conv4.0.bias', 'conv4_1.0.weight', 'conv4_1.0.bias', 'conv5.0.weight', 'conv5.0.bias', 'conv5_1.0.weight', 'conv5_1.0.bias', 'conv6.0.weight', 'conv6.0.bias', 'conv6_1.0.weight', 'conv6_1.0.bias', 'deconv5.0.weight', 'deconv4.0.weight', 'deconv3.0.weight', 'deconv2.0.weight', 'predict_flow6.weight', 'predict_flow5.weight', 'predict_flow4.weight', 'predict_flow3.weight', 'predict_flow2.weight', 'upsampled_flow6_to_5.weight', 'upsampled_flow5_to_4.weight', 'upsampled_flow4_to_3.weight', 'upsampled_flow3_to_2.weight'])

    Model_dict of the original convolutional layers:

    odict_keys(['conv1.0.weight', 'conv1.1.weight', 'conv1.1.bias', 'conv1.1.running_mean', 'conv1.1.running_var', 'conv1.1.num_batches_tracked', 'conv2.0.weight', 'conv2.1.weight', 'conv2.1.bias', 'conv2.1.running_mean', 'conv2.1.running_var', 'conv2.1.num_batches_tracked', 'conv3.0.weight', 'conv3.1.weight', 'conv3.1.bias', 'conv3.1.running_mean', 'conv3.1.running_var', 'conv3.1.num_batches_tracked', 'conv3_1.0.weight', 'conv3_1.1.weight', 'conv3_1.1.bias', 'conv3_1.1.running_mean', 'conv3_1.1.running_var', 'conv3_1.1.num_batches_tracked', 'conv4.0.weight', 'conv4.1.weight', 'conv4.1.bias', 'conv4.1.running_mean', 'conv4.1.running_var', 'conv4.1.num_batches_tracked', 'conv4_1.0.weight', 'conv4_1.1.weight', 'conv4_1.1.bias', 'conv4_1.1.running_mean', 'conv4_1.1.running_var', 'conv4_1.1.num_batches_tracked', 'conv5.0.weight', 'conv5.1.weight', 'conv5.1.bias', 'conv5.1.running_mean', 'conv5.1.running_var', 'conv5.1.num_batches_tracked', 'conv5_1.0.weight', 'conv5_1.1.weight', 'conv5_1.1.bias', 'conv5_1.1.running_mean', 'conv5_1.1.running_var', 'conv5_1.1.num_batches_tracked', 'conv6.0.weight', 'conv6.1.weight', 'conv6.1.bias', 'conv6.1.running_mean', 'conv6.1.running_var', 'conv6.1.num_batches_tracked']

    As a result, I cannot reload the weights of the convolutional layers from pretrained model FlowNetS. Can anyone tell me what's wrong with this matter?

    opened by Jayleelwj 0
  • Flownet2 model for faces

    Flownet2 model for faces

    @aaronp24 @jiapei100 @mkolod @lukeyeager @elezar Hey. This pretrained flownet2 model doesn't work on face video frame pairs. Is there a way I could make it work on faces?

    opened by SURABHI-GUPTA 1
Owner
NVIDIA Corporation
NVIDIA Corporation
A lightweight deep network for fast and accurate optical flow estimation.

FastFlowNet: A Lightweight Network for Fast Optical Flow Estimation The official PyTorch implementation of FastFlowNet (ICRA 2021). Authors: Lingtong

Tone 161 Jan 3, 2023
[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 reimplementation of Optical Flow Estimation using a Spatial Pyramid Network in PyTorch

pytorch-spynet This is a personal reimplementation of SPyNet [1] using PyTorch. Should you be making use of this work, please cite the paper according

Simon Niklaus 269 Jan 2, 2023
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
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
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
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
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
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
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
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
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
Official PyTorch Implementation of Unsupervised Learning of Scene Flow Estimation Fusing with Local Rigidity

UnRigidFlow This is the official PyTorch implementation of UnRigidFlow (IJCAI2019). Here are two sample results (~10MB gif for each) of our unsupervis

Liang Liu 28 Nov 16, 2022
This implements one of result networks from Large-scale evolution of image classifiers

Exotic structured image classifier This implements one of result networks from Large-scale evolution of image classifiers by Esteban Real, et. al. Req

null 54 Nov 25, 2022
NEATEST: Evolving Neural Networks Through Augmenting Topologies with Evolution Strategy Training

NEATEST: Evolving Neural Networks Through Augmenting Topologies with Evolution Strategy Training

Göktuğ Karakaşlı 16 Dec 5, 2022
This is the official pytorch implementation of Student Helping Teacher: Teacher Evolution via Self-Knowledge Distillation(TESKD)

Student Helping Teacher: Teacher Evolution via Self-Knowledge Distillation (TESKD) By Zheng Li[1,4], Xiang Li[2], Lingfeng Yang[2,4], Jian Yang[2], Zh

Zheng Li 9 Sep 26, 2022