farizrahman4u / seq2seq

Sequence to Sequence Learning with Keras
GNU General Public License v2.0
3.17k stars 845 forks source link

A Bug in class Sequential(Model)???? #192

Closed lhl881210 closed 7 years ago

lhl881210 commented 7 years ago

Hi, @farizrahman4u and @abhaikollara

Thanks a lot.

I still have a problem as following. I set the length of input was 2, and length of output was 50. However, it showed a message ”assert input_shape and len(input_shape) >= 2”. Could you please tell me how to fix this problem?

Thanks!

Traceback (most recent call last): File "I:/seq2seq-DI (1)/CNN_S2S_train_2-50.py", line 188, in <module> Seq2Seq(output_dim=output_node_num, output_length=output_seq_len,input_shape=(input_seq_len, img_features_dim),hidden_dim=hidden_dim ) File "C:\Python\Python35\lib\site-packages\keras\models.py", line 466, in add output_tensor = layer(self.outputs[0]) File "C:\Python\Python35\lib\site-packages\keras\engine\topology.py", line 585, in __call__ output = self.call(inputs, **kwargs) File "C:\Python\Python35\lib\site-packages\keras\engine\topology.py", line 2027, in call output_tensors, _, _ = self.run_internal_graph(inputs, masks) File "C:\Python\Python35\lib\site-packages\keras\engine\topology.py", line 2217, in run_internal_graph shapes = _to_list(layer.compute_output_shape([x._keras_shape for x in computed_tensors])) File "C:\Python\Python35\lib\site-packages\recurrentshop\engine.py", line 698, in compute_output_shape output_shape = self.model.compute_output_shape(input_shape) File "C:\Python\Python35\lib\site-packages\keras\engine\topology.py", line 2095, in compute_output_shape output_shape = layer.compute_output_shape(input_shapes) File "C:\Python\Python35\lib\site-packages\keras\engine\topology.py", line 2095, in compute_output_shape output_shape = layer.compute_output_shape(input_shapes) File "C:\Python\Python35\lib\site-packages\recurrentshop\engine.py", line 145, in compute_output_shape return self.model.compute_output_shape(input_shape) File "C:\Python\Python35\lib\site-packages\keras\engine\topology.py", line 2093, in compute_output_shape output_shape = layer.compute_output_shape(input_shapes[0]) File "C:\Python\Python35\lib\site-packages\keras\layers\core.py", line 848, in compute_output_shape assert input_shape and len(input_shape) >= 2 AssertionError

lhl881210 commented 7 years ago

I made a model. You can try it for finding the bug. Thanks.

` from seq2seq import Seq2Seq from keras.models import Sequential from keras.layers.convolutional import Convolution2D from keras.layers.wrappers import TimeDistributed from keras.layers.core import Dense, Activation, Flatten,Dropout from keras.applications.vgg16 import VGG16

img_features_dim=100 input_seq_len =5 output_seq_len = 20 hidden_dim = 100 output_node_num = 4 img_shape=(140,140,3) img_seq_shape=(input_seq_len,140,140,3) batch_size =100

cnn = Sequential() cnn.add( VGG16(weights='imagenet',include_top=False,input_shape=img_shape))

model = Sequential() model.add(TimeDistributed(cnn,input_shape=img_seq_shape,name="conve4")) model.add(TimeDistributed(Activation('relu'))) model.add(TimeDistributed(Dropout(0.5))) model.add(TimeDistributed(Flatten())) model.add(TimeDistributed(Dense(1000))) model.add(TimeDistributed(Activation('relu'))) model.add(TimeDistributed(Dropout(0.5))) model.add(TimeDistributed(Dense(100))) model.add(TimeDistributed(Activation('relu'))) model.add(TimeDistributed(Dropout(0.5))) model.add(TimeDistributed(Dense(img_features_dim))) model.add(TimeDistributed(Activation('sigmoid')))

model.add( Seq2Seq( batch_input_shape=(batch_size,input_seq_len, img_features_dim), output_dim=output_node_num, output_length=output_seq_len, hidden_dim=hidden_dim ) )

model.add(TimeDistributed(Dense(output_node_num,activation='sigmoid',name='output')))

model.summary() `

abhaikollara commented 7 years ago

Update RecurrentShop, the issue has now been fixed

lhl881210 commented 7 years ago

@abhaikollara Thanks very much. It's working!