mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

AssertionError when fitting the lstm model

Open KCHWang opened this issue 10 years ago • 6 comments

I am getting the following error when training my own lstm model.

I define "train_iter" as follows: train_iter = mx.io.NDArrayIter(X_train, y_train, batch_size=batch_size) where X_train and y_train are numpy.ndarray. The shapes of X_train and y_train are (203, 15, 18) and (203, 15), which means that I have 203 examples and the sequence length is 15.

Here comes the error information: Traceback (most recent call last): File "train_lstm.py", line 57, in model.fit(X=train_iter) File "/mxnet/example/rnn/../../python/mxnet/model.py", line 745, in fit self._init_params(dict(data.provide_data+data.provide_label)) File "/mxnet/example/rnn/../../python/mxnet/model.py", line 486, in _init_params assert(arg_shapes is not None) AssertionError

Any idea what might go wrong? Lots of thanks!

KCHWang avatar Jul 13 '16 08:07 KCHWang

BYW, I get rid of the embedding layer as defined in the lstm.py and put my X_train directly to hidden layer. Is this why it is not working?

KCHWang avatar Jul 13 '16 08:07 KCHWang

Is your provided_data empty?

Godricly avatar Jul 13 '16 16:07 Godricly

@Godricly Thanks for your reply! I am pretty sure that X_train and y_train are not empty. I did print their shape right before build this train_iter = mx.io.NDArrayIter(X_train, y_train, batch_size=batch_size).

KCHWang avatar Jul 14 '16 01:07 KCHWang

What I'm asking is not the actual data, but the provided_data and provided_label attributes. They are used in LSTM to infer network shape. Go checking them in your your DataIter and the DataBatch.

Godricly avatar Jul 14 '16 04:07 Godricly

@Godricly thanks! It seems that you are right! I just wrote my own iterator.

KCHWang avatar Jul 14 '16 10:07 KCHWang

I have the same question with Mr Wang. Do you have a solution? How to train my own data in the lstm

lyndd avatar Nov 02 '16 12:11 lyndd