Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

LSTM doesn't work with Symbols - "'Symbol' object has no attribute 'shape'" #9486

Closed
aodhan-domhnaill opened this issue Jan 19, 2018 · 4 comments

Comments

@aodhan-domhnaill
Copy link

I am using the following versions,

$ pip list | grep mxnet
mxnet (1.0.0.post1)
$ python --version
Python 3.6.3

When I run,

import mxnet as mx
from mxnet import gluon

class Net(gluon.Block):
    def __init__(self, recurrent_width, forward_width, **kwargs):
        super(Net, self).__init__(**kwargs)
        with self.name_scope():
            self._rnn = gluon.rnn.LSTM(recurrent_width)
            self._nn  = gluon.nn.Dense(forward_width)

    def forward(self, x):
        return self._nn(self._rnn(x))

net = Net(10, 10)
net(mx.sym.var('data'))

I get,

$ python shape_error.py 
Traceback (most recent call last):
  File "shape_error.py", line 15, in <module>
    net(mx.sym.var('data'))
  File "/usr/local/lib/python3.6/site-packages/mxnet/gluon/block.py", line 304, in __call__
    return self.forward(*args)
  File "shape_error.py", line 12, in forward
    return self._nn(self._rnn(x))
  File "/usr/local/lib/python3.6/site-packages/mxnet/gluon/block.py", line 304, in __call__
    return self.forward(*args)
  File "/usr/local/lib/python3.6/site-packages/mxnet/gluon/rnn/rnn_layer.py", line 173, in forward
    batch_size = inputs.shape[self._layout.find('N')]
AttributeError: 'Symbol' object has no attribute 'shape'

So the problem is occuring here because RNN Layer checks the shape right away.

How can I fix this?

@eric-haibin-lin
Copy link
Member

@szha

@szha
Copy link
Member

szha commented Jan 19, 2018

Block doesn't support Symbol.

@aodhan-domhnaill
Copy link
Author

@szha Is there a way to fix this? I am trying to use SageMaker, and the examples do this save call. For example, MNIST saves the symbolic graph.

@aodhan-domhnaill
Copy link
Author

Never mind. I just needed to use HybridSequential.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants