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

TypeError: Compose expect Symbol as arguments #5178

Closed
poorfriend opened this issue Feb 28, 2017 · 6 comments
Closed

TypeError: Compose expect Symbol as arguments #5178

poorfriend opened this issue Feb 28, 2017 · 6 comments

Comments

@poorfriend
Copy link

I want to implement CNN_BLSTM_CTC with CUDNN, but an error arise:
Traceback (most recent call last):
File "/home/Documents/MyCode/VLPR/view.py", line 25, in
output = CNN_MultiBLSTM_CTC_CUDNN(num_hidden, num_label, num_lstm_layer)
File "/home/Documents/MyCode/VLPR/blstm.py", line 325, in CNN_MultiBLSTM_CTC_CUDNN
output, _ = cell.unroll(num_length, inputs=hidden, merge_outputs=True, layout='NTC')
File "/home/mxnet/python/mxnet/rnn/rnn_cell.py", line 637, in unroll
inputs = symbol.Concat(inputs, dim=0)
File "/home/mxnet/python/mxnet/_ctypes/symbol.py", line 191, in creator
s._compose(*args, name=name, **symbol_kwargs)
File "/home/mxnet/python/mxnet/symbol.py", line 241, in _compose
raise TypeError('Compose expect Symbol as arguments')
TypeError: Compose expect Symbol as arguments

Here is my code, How can I fix it

`def CNN_MultiBLSTM_CTC_CUDNN(num_hidden, num_label, num_lstm_layer, num_class = 70, num_length = 32):

data = mx.sym.Variable('data')
label = mx.sym.Variable('label')

wordvec = CNN(data)
hidden = [mx.symbol.Flatten(wordvec[i]) for i in range(num_length)]

cell = mx.rnn.FusedRNNCell(num_hidden, num_layers=num_lstm_layer, mode='lstm', bidirectional=True)

output, _ = cell.unroll(num_length, inputs=hidden, merge_outputs=True, layout='NTC')

pred = mx.sym.Reshape(output, shape=(-1, num_hidden))

pred = mx.sym.FullyConnected(data=pred, num_hidden=num_class)

label = mx.sym.Reshape(data=label, shape=(-1,))
label = mx.sym.Cast(data=label, dtype='int32')
sm = mx.sym.WarpCTC(data=pred, label=label, label_length=num_label, input_length=num_length)

return sm`

def CNN3(indata):
"""the net is similar to VGG16
each image size is 64256
"""
# stage 1
body = CNN_Module(data=indata, kernel=(3, 3), pad=(1, 1), num_filter=64, stride=(1, 1), num_module=2, BatchNorm=True)
body = mx.symbol.Pooling(data=body, pool_type="max", kernel=(2, 2), stride=(2, 2)) #32
128
# stage 2
body = CNN_Module(data=body, kernel=(3, 3), pad=(1, 1), num_filter=128, stride=(1, 1), num_module=2, BatchNorm=True)
body = mx.symbol.Pooling(data=body, pool_type="max", kernel=(2, 2), stride=(2, 2)) #1664
# stage 3
body = CNN_Module(data=body, kernel=(3, 3), pad=(1, 1), num_filter=256, stride=(1, 1), num_module=2, BatchNorm=True)
body = mx.symbol.Pooling(data=body, pool_type="max", kernel=(2, 2), stride=(2, 2)) #8
32
# stage 4
body = CNN_Module(data=body, kernel=(3, 3), pad=(1, 1), num_filter=256, stride=(1, 1), num_module=2, BatchNorm=True)
body = mx.symbol.Pooling(data=body, pool_type="max", kernel=(2, 1), stride=(2, 1)) #432
# stage 5
body = CNN_Module(data=body, kernel=(3, 3), pad=(1, 1), num_filter=512, stride=(1, 1), num_module=2, BatchNorm=True)
body = mx.symbol.Pooling(data=body, pool_type="max", kernel=(2, 1), stride=(2, 1)) #2
32
# stage 5
body = CNN_Module(data=body, kernel=(2, 1), pad=(0, 0), num_filter=512, stride=(1, 1), num_module=1, BatchNorm=True)
body = mx.sym.SliceChannel(data=body, num_outputs=32, axis=3, squeeze_axis=1)

return body
@poorfriend
Copy link
Author

@piiswrong

@Godricly
Copy link
Contributor

Maybe updating to latest version will help. #5114

@poorfriend
Copy link
Author

poorfriend commented Mar 1, 2017

@Godricly , Thank ,it works. but when I run

output = CNN_MultiBLSTM_CTC_CUDNN(num_hidden, num_label, num_lstm_layer) mx.viz.plot_network(output,shape = {'data': (5,1,64,256),'label':(5,8)}).view()

another error arise:
infer_shape error. Arguments:
Traceback (most recent call last):
data: (5, 1, 64, 256)
File "/home/Documents/MyCode/VLPR/view.py", line 48, in
label: (5, 8)
mx.viz.plot_network(output,shape = {'data': (5,1,64,256),'label':(5,8)}).view()
File "/home/mxnet/python/mxnet/visualization.py", line 206, in plot_network
_, out_shapes, _ = interals.infer_shape(**shape)
File "/home/mxnet/python/mxnet/symbol.py", line 562, in infer_shape
res = self._infer_shape_impl(False, *args, **kwargs)
File "/home/mxnet/python/mxnet/symbol.py", line 645, in _infer_shape_impl
ctypes.byref(complete)))
File "/home/mxnet/python/mxnet/base.py", line 77, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: Error in operator warpctc0: Shape inconsistent, Provided=(40,), inferred shape=(80,)

I guess this is caused by bidirectional lstm, but I don't know how to fix it, can you help me

@poorfriend
Copy link
Author

@piiswrong, Can I used fusedrnn to struct a multilayer bidirectional lstm

@ysh329
Copy link
Contributor

ysh329 commented Apr 14, 2017

same problem.

TypeError: Compose expect `Symbol` as arguments

@szha
Copy link
Member

szha commented Sep 29, 2017

This issue is closed due to lack of activity in the last 90 days. Feel free to ping me to reopen if this is still an active issue. Thanks!

@szha szha closed this as completed Sep 29, 2017
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

4 participants