CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

Is 3D convolution supported ?

Open pinzhang10 opened this issue 10 years ago • 8 comments

I tried 3D convolution using

c = Convolution(w, inp, (kW:kH:KD:1), mapDims=outMap, stride=(hStride:vStride:dStride:1), sharing = true, autoPadding = true, lowerPad = 0, upperPad = 0, transpose=false, imageLayout='CHW', maxTempMemSizeInSamples = 0, tag='')

And I got the error below: EXCEPTION occurred: Convolution operation currently only supports 1D or 2D convolution on 3D tensors.

I am wondering if 3D convolution is supported by CNTK now?

pinzhang10 avatar Jul 29 '16 19:07 pinzhang10

I think that's a bug in CNTK. 3D convolution is not supported for the old image layout (HWC), but it is for the new layout (cudnn or CHW), so CNTK attempts to change the layout, which does not work for 4D tensors. You can fix it by changing line 377 in file ConvolutionalNodes.h from

SetDims(ImageDimensions(outputShape, ImageLayoutKind::CHW).AsTensorShape;

to

    if (m_imageLayout != ImageLayoutKind::CHW)
    {
        SetDims(ImageDimensions(outputShape, ImageLayoutKind::CHW).AsTensorShape(m_imageLayout), HasMBLayout());
    }
    else
    {
        SetDims(outputShape, HasMBLayout());
    }

So the change is only done when needed.

e-thereal avatar Aug 03 '16 08:08 e-thereal

@e-thereal

I will try it now. Thank you so much !!!

Really appreciate!

pinzhang10 avatar Aug 04 '16 14:08 pinzhang10

We are looking into this, expect a fix in master soon, plus clarified documentation.

frankseide avatar Aug 04 '16 19:08 frankseide

@e-thereal @frankseide

It worked!

Just one thing, using Convolution(), the parameter stride should be "stride=(hStride:vStride:dStride:inMap)". "stride = 1" doesn't work.

pinzhang10 avatar Aug 04 '16 19:08 pinzhang10

Yes, the last parameter must match the input dimension, otherwise it would not be able to reduce. This is not nice. That is a quirk that we are going to address as well.

It was necessary to distinguish from images that have no channel dimension, e.g. a B&W image that is just a [W x H] tensor. For 2D convolution, it is clear. But for N-dim convolution, the system would not know whether H is supposed to match the input dimension or not. We need a better way of denoting this.

frankseide avatar Aug 04 '16 21:08 frankseide

Hi @e-thereal, @cha-zhang put this fix in master. Will be in upcoming 1.7 binary. Thanks!

frankseide avatar Aug 22 '16 21:08 frankseide

Great. Thanks for letting me know.

2016-08-22 23:31 GMT+02:00 Frank Seide [email protected]:

Closed #726 https://github.com/Microsoft/CNTK/issues/726.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/CNTK/issues/726#event-763665680, or mute the thread https://github.com/notifications/unsubscribe-auth/AMdybCOQyyWeIr2cEuUUZBtFBdAfltODks5qihVFgaJpZM4JYf0f .

e-thereal avatar Aug 22 '16 22:08 e-thereal

Just one thing, using Convolution(), the parameter stride should be "stride=(hStride:vStride:dStride:inMap)". "stride = 1" doesn't work

If you use ConvolutionalLayer{} instead, you will not need to specify it. If you use this, please for now always specify init=..., don't leave it to default.

frankseide avatar Aug 22 '16 22:08 frankseide