How to implement deformable convolution

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

The NDArray API provides a routine for deformable convolutions:
To use it in Gluon, you need to wrap MXNet symbol in a Gluon SymbolBlock:

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 ?

Here is a simple example:

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

# set context to 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

# 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 

I assume you mean with v1,v2 1-dimensional and 2-dimensional convolutions? MXNet currently supports deformable 2-dimensional convolution:

1 Like

I meant deformeble convolution v2, the paper released a couple of months ago

Ok I was not aware of this new type of deformable convolution. It seems the authors of the paper already provide an MXNet implementation:

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

You may need to clone the sources of incubator-mxnet and copy these source files into src/operator/contrib,and recompile it. There seems no way to use DeformableConvolution v2 unless you install mxnet from sources.

1 Like