MXNet Forum

In FullyConnected AssertionError: Argument data must have NDArray type


#1

I have following code in my forward function

for i in range(5):
    x2, self.h[i] = self.lstm_cell[i](x2, [self.h[i], self.c[i]])

these cells are defined in __init__ as

self.lstm_cell = [gluon.rnn.LSTMCell(hidden_size=100) for i in range(5)]
for i in range(5):
     self.lstm_cell[i].initialize()
self.h = [nd.random.uniform(shape=(15, 100)) for i in range(5)]
self.c = [nd.random.uniform(shape=(15, 100)) for i in range(5)]

and this line got an error, trace back is

File "C:\E\project\code\model.py", line 80, in forward
x2, self.h[i] = self.lstm_cell[i](x2, [self.h[i], self.c[i]])
  File "C:\D\Programs\Python37\lib\site-packages\mxnet\gluon\block.py", line 471, in __call__
return self.forward(*args)
  File "C:\D\Programs\Python37\lib\site-packages\mxnet\gluon\rnn\rnn_cell.py", line 289, in forward
return super(RecurrentCell, self).forward(inputs, states)
  File "C:\D\Programs\Python37\lib\site-packages\mxnet\gluon\block.py", line 713, in forward
return self.hybrid_forward(ndarray, x, *args, **params)
  File "C:\D\Programs\Python37\lib\site-packages\mxnet\gluon\rnn\rnn_cell.py", line 498, in hybrid_forward
num_hidden=self._hidden_size*4, name=prefix+'h2h')
  File "<string>", line 59, in FullyConnected
AssertionError: Argument data must have NDArray type, but got [
[[ 0.08959287  0.31618172  0.07252222 ...  0.25765175  0.07648147
   0.03656705]

but this x2 is just an ndarray, how could I get it working?


#2

Possibly due to the list in [self.h[i], self.c[i]]? Could you add more details about the code if that’s not the issue?


#3

I added several details, maybe they are what you need