PyTorch implementation of Deformable Convolution

Overview

PyTorch implementation of Deformable Convolution

!!!Warning: There is some issues in this implementation and this repo is not maintained any more, please consider using for example: TORCHVISION.OPS.DEFORM_CONV

TODO List

  • implement offsets mapping in pytorch
  • all tests passed
  • deformable convolution module
  • Fine-tuning the deformable convolution modules
  • scaled mnist demo
  • improve speed with cached grid array
  • use MNIST dataset from pytorch (instead of Keras)
  • support input image with different width and height
  • benchmark with tensorflow implementation

Deformable Convolutional Networks

Dai, Jifeng, Haozhi Qi, Yuwen Xiong, Yi Li, Guodong Zhang, Han Hu, and Yichen Wei. 2017. “Deformable Convolutional Networks.” arXiv [cs.CV]. arXiv. http://arxiv.org/abs/1703.06211

The following animation is generated by Felix Lau (with his tensorflow implementation):

Also Check out Felix Lau's summary of the paper: https://medium.com/@phelixlau/notes-on-deformable-convolutional-networks-baaabbc11cf3

Comments
  • What is the size of the offset?

    What is the size of the offset?

    Hi, I have read the paper“Deformable Convolutional Networks”and your pytoch-deform-conv code. Then I think that the size of offset maybe bckenel[0]*kenel[1]hw. Maybe I understand it wrong. Can you explain it?

    opened by guoswang 3
  • GPU mode is not available !

    GPU mode is not available !

    Hello oeway

    Firstly, thanks for sharing your pytorch version code of deformable convolution. When I tried to port your code to another code which uses CUDA mode, it gives me an error saying like below.

    'Type torch.cuda.FloatTensor doesn't implement stateless method range'

    However, when I change it to CPU mode, there is no error.

    It seems like 'torch.range' does not fit on GPU mode in torch. Then what should be the solution?

    Thanks in advance

    opened by shwoo93 3
  • Why only fine tuning on deformable  convnet

    Why only fine tuning on deformable convnet

    Hi, why train first on the convnet and only after do finetuning on the deformable convnet? why not straight traing on deformable (with freezing the ofsets as written in the paper)

    opened by Esaada 1
  • Offset output channel

    Offset output channel

    https://github.com/oeway/pytorch-deform-conv/blob/e7a664f1e868f254d758e1cde11d82ea66972aa4/torch_deform_conv/layers.py#L33 Your implementation is not the same as the original paper described in section 2.1. Offset output channel dimension should be 2 x N, where N is the conv kernel size k*k in 2D case. That is, the offset is shared across the channel dimension. You could refer to the implementation of https://github.com/ChunhuanLin/deform_conv_pytorch

    opened by zhujiagang 1
  • Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

    Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

    Hi, when I run scale_mnist.py, I get into this trouble. I find that process exits when it imports Keras. If someone knows how to solve this problem, please tell me. Thanks! ^.^

    opened by felixysz 1
  • indexing with a detached variable

    indexing with a detached variable

    Hi oeway,

    Any chance you can help me understand your code? On this line, you index the input with a detached variable, so I'm wondering how you propagate the gradient backward through the vals_lt, etc.. It seems like mapped_vals would not have any parent nodes with gradients? Does that make sense? When I try to do a similar thing here for a spatial transformer network, it gives me a no nodes require gradients error.

    Do you get around this by freezing the entire network? I feel like you would get the same error if the network wasn't frozen. Any insight you can provide into this would be appreciated.

    EDIT: Ok, I get that the gradient propagates through the coords_offset_lt value... can you describe where you got this interpolation algorithm from? Thanks :)

    opened by ncullen93 1
  • related to TF_version #4

    related to TF_version #4

    The issue proposed in issue 4. I test the situation of : both network is training on the dataset (not deform mnist), the test accuracy

    ---original net---
    test_data:             99.03%
    test_scaled_data: 62.22%
    ---deformable net---
    test_data:              98.67%
    test_scaled_data: 54.43%
    

    I think the train phase should use undeform data, this can show the advantage of the deformable CNN's advantage.

    opened by AceCoooool 0
  • related to TF_version #4

    related to TF_version #4

    The issue proposed in issue 4. I test the situation of : both network is training on the dataset (not deform mnist), the test accuracy

    ---original net---
    test_data:             99.03%
    test_scaled_data: 62.22%
    ---deformable net---
    test_data:              98.67%
    test_scaled_data: 54.43%
    

    I think the train phase should use undeform data, this can show the advantage of the deformable CNN's advantage.

    opened by AceCoooool 0
  • The deform-conv layers reduce the detection accuracy

    The deform-conv layers reduce the detection accuracy

    I trained your deform-conv on the origin data. It gets 70% on origin test and 89% on scaled data, while the the normal CNN model trained on origin data gets 99% on origin test and 64% on scaled data. The deform-conv may not work. So I try to delete two of the deform-conv, keep one left. It gets 93% on origin test and 97% on scaled data. Your deform-conv may not work. I think you should check it.

    opened by BearManlc 0
  • Weighting in deformed kernel

    Weighting in deformed kernel

    I am a little bit confused how the weighting is done of each input element of the deformed kernel in your implementation.

    In your implementation it looks like you are first calculating the offsets and with these rearrange the input in the ConvOffset2D module (so ConvOffset2D just outputs the rearranged features according to the learned offsets). After that, on the rearranged feature maps you apply a normal Conv2D, which should then do the actual weighting for the deformed kernel, right?

    Is this the same as in the original paper where I understand it that way that the weighting is applied directly to the deformed input elements (kernel elements with offsets) , like

    sum_p_n[ w(p_n) * x(p_0 + p_n + p_delta)]

    I don't see if this is the same or if this has a different assumption on deformable confolutions than the original paper.

    opened by mbcel 0
  • Confusion about the shape of offset

    Confusion about the shape of offset

    Hello,

    I am confused about the shape of offset. The paper mentions: "The grid R defines the receptive field size and dilation. For example,R = {(−1,−1),(−1,0),...,(0,1),(1,1)}. In deformable convolution, the regular grid R is aug- mented with offsets {∆pn |n = 1, ..., N }, where N = |R|. The output offset fields have the same spatial resolution with the input feature map. The channel dimension 2N corresponds to N 2D offsets." So, I think the shape of offset field would be [2*9, H, W] if 3x3 kernel is used. While in your implementation, the shape of offset seems to be [batch_size, 2*n_channels, H, W]?

    opened by ChiWeiHsiao 7
  • about the implementation.. view instead of permute ?

    about the implementation.. view instead of permute ?

    Hello. Thanks for sharing the code. I have a question about the implementation of offset, in [https://github.com/oeway/pytorch-deform-conv/blob/master/torch_deform_conv/deform_conv.py#L182] the code :

    offsets = offsets.view(batch_size, -1, 2)
    

    the input tensor offsets in b * (2c) * h * w after first normal conv, I think the offset of defom-conv is the output channels, therefore is the code should be ? :

    offsets = offsets.view(b, 2*c, h, w)
    offsets = offsets.permute(0, 2, 3, 1)
    
    opened by chenchr 5
Owner
Wei Ouyang
I am working with Deep Learning based image analysis and modeling, excited about biology, deep neural nets, open source, Python and JavaScript.
Wei Ouyang
PyTorch implementation of Deformable Convolution

PyTorch implementation of Deformable Convolution !!!Warning: There is some issues in this implementation and this repo is not maintained any more, ple

Wei Ouyang 893 Dec 18, 2022
MoCoPnet - Deformable 3D Convolution for Video Super-Resolution

Deformable 3D Convolution for Video Super-Resolution Pytorch implementation of l

Xinyi Ying 28 Dec 15, 2022
The pytorch implementation of DG-Font: Deformable Generative Networks for Unsupervised Font Generation

DG-Font: Deformable Generative Networks for Unsupervised Font Generation The source code for 'DG-Font: Deformable Generative Networks for Unsupervised

null 130 Dec 5, 2022
Official implementation of NPMs: Neural Parametric Models for 3D Deformable Shapes - ICCV 2021

NPMs: Neural Parametric Models Project Page | Paper | ArXiv | Video NPMs: Neural Parametric Models for 3D Deformable Shapes Pablo Palafox, Aljaz Bozic

PabloPalafox 109 Nov 22, 2022
This is the code for Deformable Neural Radiance Fields, a.k.a. Nerfies.

Deformable Neural Radiance Fields This is the code for Deformable Neural Radiance Fields, a.k.a. Nerfies. Project Page Paper Video This codebase conta

Google 1k Jan 9, 2023
[CVPRW 2021] Code for Region-Adaptive Deformable Network for Image Quality Assessment

RADN [CVPRW 2021] Code for Region-Adaptive Deformable Network for Image Quality Assessment [Paper on arXiv] Overview Update [2021/5/7] add codes for W

IIGROUP 53 Dec 28, 2022
Deformable DETR is an efficient and fast-converging end-to-end object detector.

Deformable DETR: Deformable Transformers for End-to-End Object Detection.

null 2k Jan 5, 2023
DPT: Deformable Patch-based Transformer for Visual Recognition (ACM MM2021)

DPT This repo is the official implementation of DPT: Deformable Patch-based Transformer for Visual Recognition (ACM MM2021). We provide code and model

CASIA-IVA-Lab 111 Dec 21, 2022
Code for ICCV 2021 paper: ARAPReg: An As-Rigid-As Possible Regularization Loss for Learning Deformable Shape Generators..

ARAPReg Code for ICCV 2021 paper: ARAPReg: An As-Rigid-As Possible Regularization Loss for Learning Deformable Shape Generators.. Installation The cod

Bo Sun 132 Nov 28, 2022
A multi-scale unsupervised learning for deformable image registration

A multi-scale unsupervised learning for deformable image registration Shuwei Shao, Zhongcai Pei, Weihai Chen, Wentao Zhu, Xingming Wu and Baochang Zha

ShuweiShao 2 Apr 13, 2022
Some code of the implements of Geological Modeling Using 3D Pixel-Adaptive and Deformable Convolutional Neural Network

3D-GMPDCNN Geological Modeling Using 3D Pixel-Adaptive and Deformable Convolutional Neural Network PyTorch implementation of "Geological Modeling Usin

null 5 Nov 21, 2022
3D2Unet: 3D Deformable Unet for Low-Light Video Enhancement (PRCV2021)

3DDUNET This is the code for 3D2Unet: 3D Deformable Unet for Low-Light Video Enhancement (PRCV2021) Conference Paper Link Dataset We use SMOID dataset

null 1 Jan 7, 2022
PyTorch implementation of "Conformer: Convolution-augmented Transformer for Speech Recognition" (INTERSPEECH 2020)

PyTorch implementation of Conformer: Convolution-augmented Transformer for Speech Recognition. Transformer models are good at capturing content-based

Soohwan Kim 565 Jan 4, 2023
Official pytorch implementation of paper "Inception Convolution with Efficient Dilation Search" (CVPR 2021 Oral).

IC-Conv This repository is an official implementation of the paper Inception Convolution with Efficient Dilation Search. Getting Started Download Imag

Jie Liu 111 Dec 31, 2022
🍀 Pytorch implementation of various Attention Mechanisms, MLP, Re-parameter, Convolution, which is helpful to further understand papers.⭐⭐⭐

?? Pytorch implementation of various Attention Mechanisms, MLP, Re-parameter, Convolution, which is helpful to further understand papers.⭐⭐⭐

xmu-xiaoma66 7.7k Jan 5, 2023
PyTorch implementation of the R2Plus1D convolution based ResNet architecture described in the paper "A Closer Look at Spatiotemporal Convolutions for Action Recognition"

R2Plus1D-PyTorch PyTorch implementation of the R2Plus1D convolution based ResNet architecture described in the paper "A Closer Look at Spatiotemporal

Irhum Shafkat 342 Dec 16, 2022
An implementation of Video Frame Interpolation via Adaptive Separable Convolution using PyTorch

This work has now been superseded by: https://github.com/sniklaus/revisiting-sepconv sepconv-slomo This is a reference implementation of Video Frame I

Simon Niklaus 984 Dec 16, 2022
PyTorch reimplementation of the paper Involution: Inverting the Inherence of Convolution for Visual Recognition [CVPR 2021].

Involution: Inverting the Inherence of Convolution for Visual Recognition Unofficial PyTorch reimplementation of the paper Involution: Inverting the I

Christoph Reich 100 Dec 1, 2022
Implementation of the "PSTNet: Point Spatio-Temporal Convolution on Point Cloud Sequences" paper.

PSTNet: Point Spatio-Temporal Convolution on Point Cloud Sequences Introduction Point cloud sequences are irregular and unordered in the spatial dimen

Hehe Fan 63 Dec 9, 2022