0

I have a collection of 11*11*21 3D data that I want to use a 3D convnet to classify. By using gluon's dataloader with a batch size of 64, my input tensor for the network was (64L, 11L, 11L, 21L). When I tried to run the program I got the following error.

"infer_shape error. Arguments:
data: (64L, 11L, 11L, 21L)"

I then realized that 3D converts take 5D tensors as inputs and thus I am stuck on how to create a 5D tensor input for the network.

If it helps here is the code I am currently using to create my data for the convnet.

train_dataset = mx.gluon.data.ArrayDataset((noA_list+A_list),     (label_noA+label_A))
test_dataset = mx.gluon.data.ArrayDataset((noA_test_list+A_list_test),(label_noA_test+label_A_test))
train_data = mx.gluon.data.DataLoader(train_dataset, batch_size= 64,shuffle= True, num_workers = cpucount)
test_data = mx.gluon.data.DataLoader(test_dataset,batch_size= 64,shuffle= True, num_workers = cpucount)
eisbehr
  • 12,243
  • 7
  • 38
  • 63
accAscrub
  • 609
  • 1
  • 6
  • 11

1 Answers1

0

Yes, you would need 5-dimensional tensor for using Conv3d. By default, the tensor format should be NCDHW where:

‘N’ - batch size, ‘C’ - channel, ‘H’ - height ‘W’ - width ‘D’ - depth.

Convolution is applied on the ‘D’, ‘H’ and ‘W’ dimensions.

So, if you are missing channel dimension (and you are working with greyscale data), you can create this dimension:

# a.shape is (64, 11, 11, 21)
a = mx.nd.random.uniform(shape=(64, 11, 11, 21))
# adding 'channel' dimension
a.expand_dims(1)
# new a.shape is (64, 1, 11, 11, 21)
Sergei
  • 1,617
  • 15
  • 31
  • I ran your code and a.shape still seems to be (64L, 11L, 11L, 21L), could I be doing something wrong? – accAscrub Aug 07 '18 at 18:23
  • Oh, sorry for confusion. Of course, `a` doesn't change, it is the result of the function which has proper dimension. So, just assign the result of the last execution to a new variable like `b = a.expand_dims(1)` or reuse `a` like `a = a.expand_dims(1)`. – Sergei Aug 08 '18 at 21:25