Uninformative error on Deconvolution Op


#1
In [3]: a = mx.nd.ones((2,2))
   ...: b = mx.nd.one_hot(mx.nd.arange(2), 2)
   ...:
   ...: a = mx.nd.reshape(a, (1,1,2,2))
   ...: b = mx.nd.reshape(b, (1,1,2,2))
   ...:

In [4]: mx.nd.Deconvolution(data=b, weight=a, no_bias=True, kernel=(2,2), num_filter=1)
Out[4]:

[[[[1. 1. 0.]
   [1. 2. 1.]
   [0. 1. 1.]]]]
<NDArray 1x1x3x3 @cpu(0)>

In [5]: mx.nd.Deconvolution(data=b, weight=a, no_bias=True, kernel=(2,2), num_filter=1, pad=(2,2))
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)

Not exactly sure what’s going on here


#2

Hi @dmadeka,

With a pad of (2,2) the result would be empty, so this is why you’re getting the error here, although I agree the error message could be more informative. Check the example below that starts with a (4,4) identity matrix and apply deconvolution with progressively larger padding size, and you’ll see the same error when the padding exceeds (2,2) in this case.

In [1]: import mxnet as mx
   ...:
   ...: a = mx.nd.array([[[[1,1],
   ...:                    [1,1]]]])
   ...: b = mx.nd.array([[[[1,0,0,0],
   ...:                    [0,1,0,0],
   ...:                    [0,0,1,0],
   ...:                    [0,0,0,1]]]])
   ...:

In [2]: mx.nd.Deconvolution(data=b, weight=a, no_bias=True, kernel=(2,2), num_filter=1, pad=(0,0))
Out[2]:

[[[[ 1.  1.  0.  0.  0.]
   [ 1.  2.  1.  0.  0.]
   [ 0.  1.  2.  1.  0.]
   [ 0.  0.  1.  2.  1.]
   [ 0.  0.  0.  1.  1.]]]]
<NDArray 1x1x5x5 @cpu(0)>

In [3]: mx.nd.Deconvolution(data=b, weight=a, no_bias=True, kernel=(2,2), num_filter=1, pad=(1,1))
Out[3]:

[[[[ 2.  1.  0.]
   [ 1.  2.  1.]
   [ 0.  1.  2.]]]]
<NDArray 1x1x3x3 @cpu(0)>

In [4]: mx.nd.Deconvolution(data=b, weight=a, no_bias=True, kernel=(2,2), num_filter=1, pad=(2,2))
Out[4]:

[[[[ 2.]]]]
<NDArray 1x1x1x1 @cpu(0)>

In [5]: mx.nd.Deconvolution(data=b, weight=a, no_bias=True, kernel=(2,2), num_filter=1, pad=(3,3))
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)