How to implement deformable convolution


#1

does anyone know how to implement deformable convolution v1 or v2 in gloun (not c++ cuda)


#2

The NDArray API provides a routine for deformable convolutions: https://mxnet.incubator.apache.org/api/python/symbol/contrib.html#mxnet.symbol.contrib.DeformableConvolution
To use it in Gluon, you need to wrap MXNet symbol in a Gluon SymbolBlock: https://mxnet.incubator.apache.org/api/python/gluon/gluon.html?highlight=symbolbl#mxnet.gluon.SymbolBlock


#3

I am a newbie in mxnet, can you show me how can i do that in a simple example?

Also, should i wait till mxnet provide deformable conv v2 or i can change v1 to v2 ?


#4

Here is a simple example:

import mxnet as mx
from mxnet import nd
from mxnet import gluon

# set context to gpu
ctx=mx.gpu()

# Define data and offset symbols
data = mx.sym.var('data')
offset = mx.sym.var('offset')

# Define the DeformbleConvolution
output = mx.symbol.contrib.DeformableConvolution(data=data, offset=offset, num_deformable_group=1, num_group=1, no_bias=True, num_filter=3,kernel=(3,3),pad=(1,1))

# Wrap DeformableConvolution into a gluon SymbolBlock
net = gluon.SymbolBlock(output, [data, offset])

# Initialize parameters
net.collect_params().initialize(ctx=ctx)

# Create random data for input and offset
input_data = mx.nd.random.normal(shape=(10,3,100,100),ctx=ctx)
offset_data = mx.nd.random.normal(shape=(10,27,100, 100),ctx=ctx)

# Feed data into the DeformableConvolution 
net(input_data,offset_data)

I assume you mean with v1,v2 1-dimensional and 2-dimensional convolutions? MXNet currently supports deformable 2-dimensional convolution: https://mxnet.incubator.apache.org/api/python/symbol/contrib.html#mxnet.symbol.contrib.DeformableConvolution


#5

I meant deformeble convolution v2, the paper released a couple of months ago https://arxiv.org/pdf/1811.11168.pdf


#6

Ok I was not aware of this new type of deformable convolution. It seems the authors of the paper already provide an MXNet implementation: https://github.com/msracver/Deformable-ConvNets/tree/master/DCNv2_op


#7

I don not know how to use DeformableConvolution api in MXNET symbol
Can i use mx.ndarray.contrib.DeformableConvolution to build a net?