Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Depthwise Separable Convolution #301

Closed
ghost opened this issue Aug 17, 2018 · 8 comments
Closed

Support for Depthwise Separable Convolution #301

ghost opened this issue Aug 17, 2018 · 8 comments
Labels

Comments

@ghost
Copy link

ghost commented Aug 17, 2018

First of all, thanks for your excellent open-source dnn library!

I'm looking for a fast depthwise separable convolution implementation.
Is this something that's on the roadmap?

thanks

@emfomenk
Copy link

Hi @zeno40,

Alas we don't have a single depthwise-separable convolution primitive.
However you can easily simulate it via running depthwise convolution followed by the regular 1x1-convolution.

I know our friend team who works on OpenVINO was going to submit a PR with this depthwise-separable convolution as a single primitive, but there is no ETA for this PR.

@ghost
Copy link
Author

ghost commented Aug 17, 2018

Thanks for the information.
I will stack a grouped convolution and a regular 1x1 convolution together in the mean-time.

@ghost ghost closed this as completed Aug 17, 2018
@ghost
Copy link
Author

ghost commented Aug 17, 2018

How can I make a depthwise convolution primitive in mkl-dnn?

thanks

@ghost ghost reopened this Aug 17, 2018
@emfomenk
Copy link

emfomenk commented Aug 18, 2018

You have to use regular convolutions with groups (depthwise convolution is a particular case when the number of groups equal to the number of input/output channels).

For example for the depthwise convolution with input [mb, channels, input_height, input_width], kernel size [kernel_height, kernel_width] and output [mb, channel, output_height, output_width] you need to create an Intel MKL-DNN convolution with the following parameters:

src_desc = {{mb, channels, input_height, input_width}, f32, any};
wei_desc = {{ 
    /* groups = */ channels,
    /* oc =  */ 1,  /* ic = */ 1,
    /* kh = */ kernel_height, 
    /* kw = */ kernel_width}, f32, any};
dst_desc = {{mb, channels, output_height, output_width}, f32, any};
// create convolution as usual

Please note that weights are 5 dimensional arrays (while src and dst are 4D which indicates that the convolution is with groups) and have number of groups equal channels while oc=ic=1.

@ghost
Copy link
Author

ghost commented Aug 18, 2018

Thanks,
It works even when I hold a fixed nchw data-layout for the src and dst descriptors and using direct convolution.
Can I also use the winograd convolution primitives for 3x3 depthwise convolution?

@emfomenk
Copy link

It should work (at least in theory) no matter what layout is. Though I would strongly recommend to allow Intel MKL-DNN to define the most appropriate layout, by passing mkldnn_anyas a format. In that case the most performant implementation would be chosen.

Winograd as of now does not support depthwise convolution. And there no plans. The thing is that Winograd requires extra data movements compare to the direct algorithm and while it is still beneficial for the compute intensive cases, it would most likely be inefficient for the depthwise case, because those convolutions are mostly memory bandwidth bound.

@ghost
Copy link
Author

ghost commented Aug 19, 2018

I use a fixed nchw layout because I also use a Windows port of NNPACK for regular non-strided convolutions with a kernel size equal or below 16x16 (except 1x1).
Is it possible with mkl-dnn to make a 3x3 separable convolution (non-depthwise)?

@ghost
Copy link
Author

ghost commented Aug 20, 2018

Sorry for the last (stupid) question. Separable convolution is just a synonym used for a depthwise separable convolution.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant