apache / mxnet

Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more
https://mxnet.apache.org
Apache License 2.0
20.78k stars 6.79k forks source link

TypeError: Compose expect `Symbol` as arguments #5178

Closed poorfriend closed 7 years ago

poorfriend commented 7 years ago

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_CTCCUDNN 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 64*256 """

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)) #16*64
# 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)) #4*32
# 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 commented 7 years ago

@piiswrong

Godricly commented 7 years ago

Maybe updating to latest version will help. #5114

poorfriend commented 7 years ago

@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 plotnetwork , outshapes, = 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 commented 7 years ago

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

ysh329 commented 7 years ago

same problem.

TypeError: Compose expect `Symbol` as arguments
szha commented 7 years ago

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!