1

I am trying to use a RNN in MXNet to do a classification. My data roughly looks like the matrices m0 and m1 I created. m0 represents e.g. energy consumption of a device over time, while m1 is my label to tell how the device is to be classified (e.g. binary in this case). My goal is to detect the category of a device by looking at the energy consumption over time. I keep getting errors about a shape mismatch and can't find a solution by changing input parameters. You can see my code and error messages below. I appreciate any suggestions on how to handle this problem.

require(mxnet)

m0 <- matrix(runif(200*100), 100, 200)
m1 <- matrix(round(runif(1*200)), 1, 200)

num.round      <- 10
update.period  <- 1
num.rnn.layer  <- 1
seq.len        <- 100
num.hidden     <- 1
num.embed      <- 1
num.label      <- 1
batch.size     <- 1
input.size     <- 1
learning.rate  <- 0.1

X.train <- list(data = m0, label = m1)

model <- mx.rnn(train.data = X.train,
                eval.data = NULL,
                num.rnn.layer = num.rnn.layer,
                seq.len = seq.len,
                num.hidden = num.hidden,
                num.embed = num.embed,
                num.label = num.label,
                batch.size = batch.size,
                input.size = input.size,
                ctx = mx.cpu(),
                num.round = num.round,
                update.period = update.period,
                initializer = mx.init.uniform(0.1),
                learning.rate = learning.rate)

[16:07:02] d:\program files (x86)\jenkins\workspace\mxnet\mxnet\src\operator\tensor./matrix_op-inl.h:144: Using target_shape will be deprecated.

[16:07:02] d:\program files (x86)\jenkins\workspace\mxnet\mxnet\src\operator\tensor./matrix_op-inl.h:144: Using target_shape will be deprecated.

[16:07:02] d:\program files (x86)\jenkins\workspace\mxnet\mxnet\src\operator\tensor./matrix_op-inl.h:144: Using target_shape will be deprecated.

[16:07:02] D:\Program Files (x86)\Jenkins\workspace\mxnet\mxnet\dmlc-core\include\dmlc/logging.h:304:

[16:07:02] D:\Program Files (x86)\Jenkins\workspace\mxnet\mxnet\src\ndarray\ndarray.cc:299: Check failed: from.shape() == to->shape() operands shape mismatchfrom.shape=(1,1) to.shape=(1,100) Error in exec$update.arg.arrays(arg.arrays, match.name, skip.null):

[16:07:02] D:\Program Files (x86)\Jenkins\workspace\mxnet\mxnet\src\ndarray\ndarray.cc:299: Check failed: from.shape() == to->shape() operands shape mismatchfrom.shape=(1,1) to.shape=(1,100)

fjba
  • 11
  • 3

1 Answers1

0

The reason for the dimension mismatch is that you're passing a dimension for label that doesn't match the sequence length. An RNN has an output for each tap of the sequence, so if your length is 100, it will have 100 outputs, one for each time step. You can fix this error by setting m1 to be matrix(round(runif(100*200)), 100, 200), but you cannot do what you want (i.e. predict one number for the entire sequence) using the simplified mx.rnn() interface. You'd need to implement your own network based on the code here. In order to achieve the single-output that you're looking for, you can discard all but last time-step's output and run that through a Softmax layer.

Sina Afrooze
  • 960
  • 6
  • 11