mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

3D dilation support

Open KnightOfTheMoonlight opened this issue 8 years ago • 13 comments

From mxnet api symbol.convolution, 3d dilation is supported. For your reference:

Parameters: dilate (Shape(tuple), optional, default=[]) – Convolution dilate: (h, w) or (d, h, w). Defaults to 1 for each dimension.

However, When I run the code, I find in fact, 3d dilation may not be included in mxnet.

Ubuntu 16.04 mxnet 1.0.0 python

code

import mxnet as mx data = mx.nd.arange(1029).reshape((3,1,7,7,7))

x = mx.sym.Variable('data', shape=(3,1,7,7,7)) conv3D = mx.sym.Convolution(data=x, kernel=(3, 3, 3), pad=(2, 2, 2), dilate=(2, 2, 2), num_filter=2) conv3D_exe = conv3D.simple_bind(mx.gpu(),data=data.shape)

Error Message:

Dilate is not supported in 3d convolution `--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) in () 11 # conv3D_ex = conv3D.simple_bind(mx.gpu(), arg_dicts={'data':data}) 12 # conv3D_exe = conv3D_bn.simple_bind(mx.gpu(), data=data.shape) ---> 13 conv3D_exe = conv3D_maxpl.simple_bind(mx.gpu(), data=data.shape) 14 args = conv3D_exe.arg_dict 15

xxx/mxnet/python/mxnet/symbol.pyc in simple_bind(self, ctx, grad_req, type_dict, group2ctx, shared_arg_names, shared_exec, shared_buffer, **kwargs) 1477 error_msg += "%s: %s\n" % (k, v) 1478 error_msg += "%s" % e -> 1479 raise RuntimeError(error_msg) 1480 1481 # update shared_buffer

RuntimeError: simple_bind error. Arguments: data: (3L, 1L, 7L, 7L, 7L) Error in operator convolution3: [20:54:34] src/operator/./convolution-inl.h:495: Check failed: param_.dilate.Size() == 1U (8 vs. 1) Dilate is not supported in 3d convolution

Stack trace returned 10 entries: [bt] (0) xxx/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4dmlc15LogMessageFatalD1Ev+0x3c) [0x7f9e0723ccfc] [bt] (1) xxx/mxnet/python/mxnet/../../lib/libmxnet.so(ZNK5mxnet2op15ConvolutionProp10InferShapeEPSt6vectorIN4nnvm6TShapeESaIS4_EES7_S7+0x2c9a) [0x7f9e0814e9fa] [bt] (2) xxx/mxnet/python/mxnet/../../lib/libmxnet.so(+0x131b46a) [0x7f9e07e9246a] [bt] (3) xxx/mxnet/python/mxnet/../../lib/libmxnet.so(+0x274bc23) [0x7f9e092c2c23] [bt] (4) xxx/mxnet/python/mxnet/../../lib/libmxnet.so(+0x274cfda) [0x7f9e092c3fda] [bt] (5) xxx/mxnet/python/mxnet/../../lib/libmxnet.so(+0x274dfc6) [0x7f9e092c4fc6] [bt] (6) xxx/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4nnvm11ApplyPassesENS_5GraphERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS7_EE+0x32c) [0x7f9e092ebb2c] [bt] (7) xxx/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4nnvm9ApplyPassENS_5GraphERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x3c9) [0x7f9e082859c9] [bt] (8) xxx/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4nnvm4pass10InferShapeENS_5GraphESt6vectorINS_6TShapeESaIS3_EENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x1f3) [0x7f9e08289373] [bt] (9) xxx/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet4exec13GraphExecutor4InitEN4nnvm6SymbolERKNS_7ContextERKSt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_St4lessISD_ESaISt4pairIKSD_S4_EEERKSt6vectorIS4_SaIS4_EESR_SR_RKSt13unordered_mapISD_NS2_6TShapeESt4hashISD_ESt8equal_toISD_ESaISG_ISH_ST_EEERKSS_ISD_iSV_SX_SaISG_ISH_iEEERKSN_INS_9OpReqTypeESaIS18_EERKSt13unordered_setISD_SV_SX_SaISD_EEPSN_INS_7NDArrayESaIS1I_EES1L_S1L_PSS_ISD_S1I_SV_SX_SaISG_ISH_S1I_EEEPNS_8ExecutorERKSS_INS2_9NodeEntryES1I_NS2_13NodeEntryHashENS2_14NodeEntryEqualESaISG_IKS1S_S1I_EEE+0x612) [0x7f9e082df082]

What have you tried to solve it?

I tried to check the source code of src/operator/convolution-inl.h where the error comes from. And I found all these codes related to dilation.

format: (line number) (code snapshot)

DMLC_DECLARE_PARAMETER 69 DMLC_DECLARE_FIELD(dilate).set_default(TShape()) 70 .describe("convolution dilate: (h, w) or (d, h, w)");

Forward function 133 if (param_.kernel.ndim() > 2) { LOG(FATAL) << "Volume convolution is not implmented in mshadow"; }

177 param_.dilate[0], 178 param_.dilate[1]);

Backward function 212 if (param_.kernel.ndim() > 2) { LOG(FATAL) << "Volume convolution is not implmented in mshadow"; }

266 param_.dilate[0], 267 param_.dilate[1]);

479 CHECK_EQ(param_.dilate.Size(), 1U) << "Dilate is not supported in 3d convolution";

InferShape function 448 } else if (param_.kernel.ndim() == 3) { 449 // 3d conv_v1

init function 385 CHECK_EQ(param_.kernel.ndim(), 3U) << param_.kernel.ndim() << "D convolution not supported"; 386 param_.layout = param_.layout ? param_.layout.value(): mshadow::kNCDHW; 387 if (param_.stride.ndim() == 0) param_.stride = Shape3(1, 1, 1); 388 if (param_.dilate.ndim() == 0) param_.dilate = Shape3(1, 1, 1); 389 if (param_.pad.ndim() == 0) param_.pad = Shape3(0, 0, 0);

As you can see, this code is not consistent. Some parts say 3d dilation supported other parts not.

KnightOfTheMoonlight avatar Dec 17 '17 10:12 KnightOfTheMoonlight

https://mxnet.incubator.apache.org/api/python/gluon.html#mxnet.gluon.nn.Conv3D

dongzhuoyao avatar Dec 17 '17 11:12 dongzhuoyao

@dongzhuoyao I have revised my issue to make it more clear. So did you run the code from gluon interface? I run the code from mxnet v1.0.0 (the most recent version).

I will run the code from gluon anyway. Thanks for your suggestion.

KnightOfTheMoonlight avatar Dec 18 '17 00:12 KnightOfTheMoonlight

given your four line code, I can run it with no error. @KnightOfTheMoonlight

dongzhuoyao avatar Dec 18 '17 00:12 dongzhuoyao

@dongzhuoyao Really?! Could you share your settings? I just tried gluon interface. Code like this: net = gluon.nn.Sequential() net.add(gluon.nn.Conv3D(2, (3,3,3), strides=(2,2,2), padding=(2,2,2), dilation=(2,2,2))) net.add(gluon.nn.BatchNorm()) net.add(gluon.nn.MaxPool3D((3,3,3),stride=(1,1,1)))

I still got this 3d dilation not supported error. I checked my mxnet version. I install it by "pip install mxnet-cu80=1.0.0"

By the way, I think that gluon interface is just a wrapper for mxnet. Then if the core mxnet code does not support 3d dilation, the gluon interface will be the same, right?

So I'm really curious how could you get no error.

KnightOfTheMoonlight avatar Dec 18 '17 03:12 KnightOfTheMoonlight

my mxnet version is 0.12.0

this code is ok.

import mxnet as mx
print mx.__version__
data = mx.nd.arange(1029).reshape((3,1,7,7,7))
x = mx.sym.Variable('data', shape=(3,1,7,7,7))
conv3D = mx.sym.Convolution(data=x, kernel=(3, 3, 3), pad=(2, 2, 2), dilate=(2, 2, 2), num_filter=2)

this code is the same error as you.

import mxnet.gluon as gluon
net = gluon.nn.Sequential()
net.add(gluon.nn.Conv3D(2, (3,3,3), strides=(2,2,2), padding=(2,2,2), dilation=(2,2,2)))
net.add(gluon.nn.BatchNorm())
net.add(gluon.nn.MaxPool3D((3,3,3),stride=(1,1,1)))

I think there is something wrong between gluon and mxnet. maybe a bug. @KnightOfTheMoonlight

dongzhuoyao avatar Dec 18 '17 03:12 dongzhuoyao

@dongzhuoyao Thanks for your suggestion. I have tested the 0.12.0 version. I found that even this code works, conv3D = mx.sym.Convolution(data=x, kernel=(3, 3, 3), pad=(2, 2, 2), dilate=(2, 2, 2), num_filter=2) when I add the following code to make it more real, I get the same error: conv3D_exe = conv3D.simple_bind(mx.gpu(),data=data.shape) I forgot to post this line in my issue, I just revised it again. Btw, this no-3d-dilation 3d-conv code can run with no errors: conv3D = mx.sym.Convolution(data=x, kernel=(3, 3, 3), pad=(2, 2, 2), num_filter=2) conv3D_exe = conv3D.simple_bind(mx.gpu(),data=data.shape) So I think in fact maybe 3d dilation is not supported. I will check the source code deeply, and wish the authors can check this issue.

KnightOfTheMoonlight avatar Dec 19 '17 23:12 KnightOfTheMoonlight

Try cudnn_off=true

chinakook avatar Dec 23 '17 13:12 chinakook

@chinakook Thanks for your suggestion. As I can remember mxnet has said 3d conv related things are based on cudnn calculation. But I still tried setting cudnn_off. Here is the code:

import mxnet as mx
print(mx.__version__)

data = mx.nd.arange(1029).reshape((3,1,7,7,7)) # NCDHW
data_shape=(3,1,7,7,7)
x = mx.sym.Variable('data')
conv3D = mx.sym.Convolution(data=x, kernel=(3, 3, 3), pad=(2, 2, 2), dilate=(2, 2, 2), num_filter=2, cudnn_off=True)
conv3D_exe = conv3D.simple_bind(mx.gpu(),data=data.shape)

Here is the related error:

RuntimeError: simple_bind error. Arguments:
data: (3L, 1L, 7L, 7L, 7L)
Error in operator convolution0: [13:42:28] src/operator/./convolution-inl.h:495: Check failed: param_.dilate.Size() == 1U (8 vs. 1) Dilate is not supported in 3d convolution

KnightOfTheMoonlight avatar Feb 01 '18 03:02 KnightOfTheMoonlight

proposed labels: "Bug", "Python", "Gluon", "CUDA"

zhiz21 avatar Mar 20 '18 03:03 zhiz21

cuDNN didn't support 3d dilation convolution yet, will use another method to achieve the same functionality. @sandeep-krishnamurthy please add label 'feature request'. thanks

stu1130 avatar Oct 01 '18 16:10 stu1130

@stu1130 @sandeep-krishnamurthy Hi, may I ask the status of this issue? It seems until now, dilation in 3D Conv is not supported in MXNet. I tried the same code snippet, the error still shows Dilate is not supported in 3d convolution

import mxnet as mx
data = mx.nd.arange(1029).reshape((3,1,7,7,7))

x = mx.sym.Variable('data', shape=(3,1,7,7,7))
conv3D = mx.sym.Convolution(data=x, kernel=(3, 3, 3), pad=(2, 2, 2), dilate=(2, 2, 2), num_filter=2)
conv3D_exe = conv3D.simple_bind(mx.gpu(),data=data.shape)

bryanyzhu avatar Jan 27 '20 18:01 bryanyzhu

@bryanyzhu sorry we didn't have time to work on this. Right the 3D Conv still didn't support dilation.

stu1130 avatar Jan 27 '20 18:01 stu1130

@stu1130 Got it, thank you.

bryanyzhu avatar Jan 27 '20 18:01 bryanyzhu