'Operands shape mismatch' when num_hidden>1
Hi,
Running the following example regression code with num_hidden>1 generates an 'Operands shape mismatch' error (it works with the deafult num_hidden=1). The problem is the same as the following issue: https://github.com/dmlc/mxnet/issues/949:
`data(BostonHousing, package="mlbench") train.ind = seq(1, 506, 3) train.x = data.matrix(BostonHousing[train.ind, -14]) train.y = BostonHousing[train.ind, 14] test.x = data.matrix(BostonHousing[-train.ind, -14]) test.y = BostonHousing[-train.ind, 14]
data <- mx.symbol.Variable("data")
fc1 <- mx.symbol.FullyConnected(data, num_hidden=2)
lro <- mx.symbol.LinearRegressionOutput(fc1) mx.set.seed(0) model <- mx.model.FeedForward.create(lro, X=train.x, y=as.array(train.y), ctx=mx.cpu(), num.round=50, array.batch.size=20, learning.rate=2e-6, momentum=0.9, eval.metric=mx.metric.rmse)`
The error is:
Auto detect layout of input matrix, use rowmajor.. Start training with 1 devices [02:07:10] C:\Users\g\Downloads\mxnet-20160229\mxnet-20160229\dmlc-core\include\dmlc/logging.h:245: [02:07:10] C:\Users\g\Downloads\mxnet-20160229\mxnet-20160229\src\ndarray\ndarray.cc:227: Check failed: from.shape() == to->shape() operands shape mismatch Error: [02:07:10] C:\Users\g\Downloads\mxnet-20160229\mxnet-20160229\src\ndarray\ndarray.cc:227: Check failed: from.shape() == to->shape() operands shape mismatch
The traceback() is:
6: stop(list(message = "[02:07:10] C:\Users\g\Downloads\mxnet-20160229\mxnet-20160229\src\ndarray\ndarray.cc:227: Check failed: from.shape() == to->shape() operands shape mismatch", call = NULL, cppstack = NULL)) 5: .External(list(name = "CppMethod__invoke_void", address = <pointer: 0x0000000009d78150>, dll = list(name = "Rcpp", path = "C:/Users/g/Documents/R/win-library/3.2/Rcpp/libs/x64/Rcpp.dll", dynamicLookup = TRUE, handle = <pointer: 0x000000006abc0000>, info = <pointer: 0x0000000003f0ee00>), numParameters = -1L), <pointer: 0x0000000009d759b0>, <pointer: 0x0000000009d5b800>, .pointer, ...) 4: exec$update.arg.arrays(arg.arrays, match.name, skip.null) 3: mx.exec.update.arg.arrays(train.execs[[i]], s, match.name = TRUE) 2: mx.model.train(symbol, ctx, input.shape, params$arg.params, params$aux.params, 1, num.round, optimizer = optimizer, train.data = X, eval.data = eval.data, metric = eval.metric, epoch.end.callback = epoch.end.callback, batch.end.callback = batch.end.callback, kvstore = kvstore) 1: mx.model.FeedForward.create(lro, X = train.x, y = as.array(train.y), ctx = mx.cpu(), num.round = 50, array.batch.size = 20, learning.rate = 2e-06, momentum = 0.9, eval.metric = mx.metric.rmse)
I compiled my own libmxnet.dll without cudnn (because I have an older GPU), but i'm not sure this is relevant, as the default example works both on cpu and gpu. I'm using R 3.2.3 and latest mxnet files. Any ideas what I'm doing wrong please?
Thanks, Gavin.
Problem solved. Basically, it's my lack of understanding of NN structure. For regression, the output layer always needs num_hidden=1.