Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Add the Gluon Implementation of Deformable Convolution #14810

Merged
merged 5 commits into from
May 5, 2019

Conversation

suyz526
Copy link
Contributor

@suyz526 suyz526 commented Apr 26, 2019

Description

The gluon implementation of deformable convolution

Checklist

Essentials

  • Changes are complete (i.e. I finished coding on this PR)
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • For user-facing API changes, API doc string has been updated.

	modified:   python/mxnet/gluon/contrib/__init__.py
	new file:   python/mxnet/gluon/contrib/cnn/__init__.py
	new file:   python/mxnet/gluon/contrib/cnn/conv_layers.py
	new file:   tests/python/gpu/test_gluon_contrib_gpu.py
@suyz526 suyz526 requested a review from szha as a code owner April 26, 2019 12:43
@suyz526
Copy link
Contributor Author

suyz526 commented Apr 26, 2019

@ChaiBapchya @sandeep-krishnamurthy @vandanavk @aaronmarkham @larroy

Hi,
things became complex after rebase...So I moved here with a new request.
I really have no idea about the Website error.

@suyz526
Copy link
Contributor Author

suyz526 commented Apr 26, 2019

http:https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html

and where can I find the BUILD_ID for a preview?

out_width = floor((width+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1])+1

Reference:
.. [1] Dai, Jifeng, et al. "Deformable convolutional networks." CoRR, abs/1703.06211 1.2 (2017): 3.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess about the Sphinx error is that it doesn't like this line.
Referring to the docs on citations, you can call it what you like, so maybe pick something more descriptive than "1" and maybe you won't have a collision. It actually says to use a non-numeric label.
Maybe to align with how this is categorized in the rst docs, call this section Citations, and then when anyone looks it up we know how it is supposed to work...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I simplified the citations as it is in Gluon BN layer:
https://mxnet.incubator.apache.org/api/python/gluon/nn.html#mxnet.gluon.nn.BatchNorm

Besides, in the doc of Gluon.Contrib syncbatchnorm:
https://mxnet.incubator.apache.org/api/python/gluon/contrib.html?highlight=syncbatchnorm#id3

it seems to be able to create a hyperlink with an underline, e.g. [1]_

Now the website error is gone, thanks very much for your help.

@suyz526
Copy link
Contributor Author

suyz526 commented Apr 29, 2019

@mxnet-label-bot update [Gluon, pr-awaiting-review]

@marcoabreu marcoabreu added Gluon pr-awaiting-review PR is waiting for code review labels Apr 29, 2019
@aaronmarkham
Copy link
Contributor

http:https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html

and where can I find the BUILD_ID for a preview?

If you click on "Show all checks" in the CI zone of this PR, you'll find one called "ci/jenkins/mxnet-validation/website". Click details. In the deploy stage (look for the green check marks), you'll see Julia selected. Select "Docs". Then click the last shell script. Then look all the way at the bottom of the output. There's your new link for a preview.

@aaronmarkham
Copy link
Contributor

@suyz526
Copy link
Contributor Author

suyz526 commented Apr 30, 2019

http:https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
and where can I find the BUILD_ID for a preview?

If you click on "Show all checks" in the CI zone of this PR, you'll find one called "ci/jenkins/mxnet-validation/website". Click details. In the deploy stage (look for the green check marks), you'll see Julia selected. Select "Docs". Then click the last shell script. Then look all the way at the bottom of the output. There's your new link for a preview.

I see, thanks very much!

Copy link
Member

@wkcn wkcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for your contribution!

@wkcn wkcn merged commit 4d7bae1 into apache:master May 5, 2019
@wkcn
Copy link
Member

wkcn commented May 5, 2019

Merged. Thank you!

access2rohit pushed a commit to access2rohit/incubator-mxnet that referenced this pull request May 14, 2019
* 	modified:   docs/api/python/gluon/contrib.md
	modified:   python/mxnet/gluon/contrib/__init__.py
	new file:   python/mxnet/gluon/contrib/cnn/__init__.py
	new file:   python/mxnet/gluon/contrib/cnn/conv_layers.py
	new file:   tests/python/gpu/test_gluon_contrib_gpu.py

* 	modified:   python/mxnet/gluon/contrib/cnn/conv_layers.py

* 	modified:   python/mxnet/gluon/contrib/cnn/conv_layers.py

* Update conv_layers.py

* Update conv_layers.py
@lucinyaLi
Copy link

I met some error when I used the deformableconv layer presented above.
The error is :
MXNetError: [14:16:07] src/operator/contrib/././nn/deformable_im2col.h:94: only implemented in GPU
And I found some code you wrote
ctx = mx.gpu() net.initialize(force_reinit=True, ctx=ctx)
And in my code, only
if args.resume.strip(): net.load_parameters(args.resume.strip()) async_net.load_parameters(args.resume.strip()) else: with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") net.initialize() async_net.initialize()
I change my code to net.initialize(force_reinit=True, ctx=ctx), but there is another error :
RuntimeError: Parameter 'ssd0_vggatrousextractor0_init_scale' was not initialized on context cpu(0). It was only initialized on [gpu(1)].

Can I get your help ?

@suyz526
Copy link
Contributor Author

suyz526 commented Jun 18, 2019

Hi,

currently, the deformable convolution layer only supports the computation on GPU, so you need to make sure that all the parameter are stored on GPU. This can be done with

ctx = mx.gpu()  #ctx = mx.gpu(gpu_id)  
net.initialize(ctx=ctx) 

or in your case,
net.load_parameters(path, ctx=ctx)

Do you have some CustomOp in your network, which only supports CPU?

@lucinyaLi
Copy link

lucinyaLi commented Jun 18, 2019

@ suyz526
This is a part of my net, I change some original conv layer in SSD into the deformable conv. There is nothing else I have changed.
`

with self.name_scope():
        # we use pre-trained weights from caffe, initial scale must change
        init_scale = mx.nd.array([0.229, 0.224, 0.225]).reshape((1, 3, 1, 1)) * 255
        self.init_scale = self.params.get_constant('init_scale', init_scale)
        self.stages = nn.HybridSequential()
        for l, f in zip(layers, filters):
            stage = nn.HybridSequential(prefix='')
            with stage.name_scope():
                    for _ in range(l):
                        stage.add(DeformableConvolution(f, kernel_size=3, padding=1, **self.init))
                        if batch_norm:
                            stage.add(nn.BatchNorm())
                        stage.add(nn.Activation('relu'))
            self.stages.add(stage)

and then
net.initialize(ctx=ctx) # where ctx=gpu(1)

net.load_parameters(path, ctx=ctx)`

I think all the parameter are stored on GPU. Is it right ? But the error :
RuntimeError: Parameter 'ssd0_vggatrousextractor0_init_scale' was not initialized on context cpu(0). It was only initialized on [gpu(1)].
What the error mean is that I should initialize the self.init_scale in CPU?

@suyz526
Copy link
Contributor Author

suyz526 commented Jun 18, 2019

CustomOp
This is a part of my net, I change some original conv layer in SSD into the deformable conv. There is nothing else I have changed.
with self.name_scope():
init_scale = mx.nd.array([0.229, 0.224, 0.225]).reshape((1, 3, 1, 1)) * 255
self.init_scale = self.params.get_constant('init_scale', init_scale)
self.stages = nn.HybridSequential()
for l, f in zip(layers, filters):
stage = nn.HybridSequential(prefix='')
with stage.name_scope():
for _ in range(l):
stage.add(DeformableConvolution(f, kernel_size=3, padding=1, **self.init))
if batch_norm:
stage.add(nn.BatchNorm())
stage.add(nn.Activation('relu'))
self.stages.add(stage)
and then
net.initialize(ctx=ctx) # where ctx=gpu(1)
net.load_parameters(path, ctx=ctx)
I think all the parameter are stored on GPU. Is it right ? But the error :
RuntimeError: Parameter 'ssd0_vggatrousextractor0_init_scale' was not initialized on context cpu(0). It was only initialized on [gpu(1)].
What the error mean is that I should initialize the self.init_scale in CPU?

Try
init_scale = mx.nd.array([0.229, 0.224, 0.225], ctx=ctx).reshape((1, 3, 1, 1)) * 255

@lucinyaLi
Copy link

@suyz526
init_scale = mx.nd.array([0.229, 0.224, 0.225], ctx=mx.gpu(1)).reshape((1, 3, 1, 1)) * 255
Or
init_scale = mx.nd.array([0.229, 0.224, 0.225], ctx=mx.cpu(0)).reshape((1, 3, 1, 1)) * 255
I tried the two ways.
It does no work. the error still exists.

@suyz526
Copy link
Contributor Author

suyz526 commented Jun 18, 2019

@suyz526
init_scale = mx.nd.array([0.229, 0.224, 0.225], ctx=mx.gpu(1)).reshape((1, 3, 1, 1)) * 255
Or
init_scale = mx.nd.array([0.229, 0.224, 0.225], ctx=mx.cpu(0)).reshape((1, 3, 1, 1)) * 255
I tried the two ways.
It does no work. the error still exists.

sry, this step is unnecessary. How about your input data?

@lucinyaLi
Copy link

@suyz526
init_scale = mx.nd.array([0.229, 0.224, 0.225], ctx=mx.gpu(1)).reshape((1, 3, 1, 1)) * 255
Or
init_scale = mx.nd.array([0.229, 0.224, 0.225], ctx=mx.cpu(0)).reshape((1, 3, 1, 1)) * 255
I tried the two ways.
It does no work. the error still exists.

sry, this step is unnecessary. How about your input data?

Nonono. I am very grateful for your help.
Just now, I found that this error is irrelevant to the deformable conv layers. It exists also in original SSD .
When I want to change the original code 'net = get_model(net_name, pretrained_base=True)' into 'net = get_model(net_name, pretrained_base=True, ctx=ctx)', the error exists.
And I ask this question in the SSD gluon forum, the URL is :
https://discuss.gluon.ai/t/topic/12903
I am looking forward for your further help if you want. And thanks again.

haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
* 	modified:   docs/api/python/gluon/contrib.md
	modified:   python/mxnet/gluon/contrib/__init__.py
	new file:   python/mxnet/gluon/contrib/cnn/__init__.py
	new file:   python/mxnet/gluon/contrib/cnn/conv_layers.py
	new file:   tests/python/gpu/test_gluon_contrib_gpu.py

* 	modified:   python/mxnet/gluon/contrib/cnn/conv_layers.py

* 	modified:   python/mxnet/gluon/contrib/cnn/conv_layers.py

* Update conv_layers.py

* Update conv_layers.py
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Gluon pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants