资源算法Pytorch-Correlation-extension

Pytorch-Correlation-extension

2020-01-08 | |  34 |   0 |   0

Pytorch Correlation module

this is a custom C++/Cuda implementation of Correlation module, used e.g. in FlowNetC

This tutorial was used as a basis for implementation, as well asNVIDIA's cuda code

  • Build and Install C++ and CUDA extensions by executing python setup.py install,

  • Benchmark C++ vs. CUDA by running python benchmark.py {cpu, cuda},

  • Run gradient checks on the code by running python grad_check.py --backend {cpu, cuda}.

Requirements

This module is expected to compile for Pytorch 1.2, on Python > 3.5 and Python 2.7.

Installation

this module is available on pip

pip install spatial-correlation-sampler

For a cpu-only version, you can install from source with

python setup_cpu.py install

Known Problems

This module needs compatible gcc version and CUDA to be compiled. Namely, CUDA 9.1 and below will need gcc5, while CUDA 9.2 and 10.0 will need gcc7 See this issue for more information

Usage

API has a few difference with NVIDIA's module

  • output is now a 5D tensor, which reflects the shifts horizontal and vertical.

input (B x C x H x W) -> output (B x PatchH x PatchW x oH x oW)
  • Output sizes oH and oW are no longer dependant of patch size, but only of kernel size and padding

  • Patch size patch_size is now the whole patch, and not only the radii.

  • stride1 is now stride andstride2 is dilation_patch, which behave like dilated convolutions

  • equivalent max_displacement is then dilation_patch * (patch_size - 1) / 2.

  • to get the right parameters for FlowNetC, you would have

kernel_size=1
patch_size=21,
stride=1,
padding=0,
dilation_patch=2

Benchmark

  • default parameters are from benchmark.py, FlowNetC parameters are same as use in FlowNetC with a batch size of 4, described in this paper, implemented here and here.

  • Feel free to file an issue to add entries to this with your hardware !

CUDA Benchmark

  • See here for a benchmark script working with NVIDIA's code, and Pytorch.

  • Benchmark are launched with environment variable CUDA_LAUNCH_BLOCKING set to 1.

  • Only float32 is benchmarked.

  • FlowNetC correlation parameters where launched with the following command:

CUDA_LAUNCH_BLOCKING=1 python benchmark.py --scale ms -k1 --patch 21 -s1 -p0 --patch_dilation 2 -b4 --height 48 --width 64 -c256 cuda

CUDA_LAUNCH_BLOCKING=1 python NV_correlation_benchmark.py --scale ms -k1 --patch 21 -s1 -p0 --patch_dilation 2 -b4 --height 48 --width 64 -c256
implementationCorrelation parametersdevicepassmin timeavg time
oursdefault980 GTXforward5.745 ms5.851 ms
oursdefault980 GTXbackward77.694 ms77.957 ms
NVIDIAdefault980 GTXforward13.779 ms13.853 ms
NVIDIAdefault980 GTXbackward73.383 ms73.708 ms






oursFlowNetC980 GTXforward26.102 ms26.179 ms
oursFlowNetC980 GTXbackward208.091 ms208.510 ms
NVIDIAFlowNetC980 GTXforward35.363 ms35.550 ms
NVIDIAFlowNetC980 GTXbackward283.748 ms284.346 ms

Notes

  • The overhead of our implementation regarding kernel_size > 1 during backward needs some investigation, feel free to dive in the code to improve it !

  • The backward pass of NVIDIA is not entirely correct when stride1 > 1 and kernel_size > 1, because not everything is computed, see here.

CPU Benchmark

  • No other implementation is avalaible on CPU.

  • It is obviously not recommended to run it on CPU if you have a GPU.

Correlation parametersdevicepassmin timeavg time
defaultE5-2630 v3 @ 2.40GHzforward159.616 ms188.727 ms
defaultE5-2630 v3 @ 2.40GHzbackward282.641 ms294.194 ms
FlowNetCE5-2630 v3 @ 2.40GHzforward2.138 s2.144 s
FlowNetCE5-2630 v3 @ 2.40GHzbackward7.006 s7.075 s


上一篇:tensorboardx-s4tf

下一篇:django-mlogger

用户评价
全部评价

热门资源

  • Keras-ResNeXt

    Keras ResNeXt Implementation of ResNeXt models...

  • seetafaceJNI

    项目介绍 基于中科院seetaface2进行封装的JAVA...

  • spark-corenlp

    This package wraps Stanford CoreNLP annotators ...

  • capsnet-with-caps...

    CapsNet with capsule-wise convolution Project ...

  • inferno-boilerplate

    This is a very basic boilerplate example for pe...