2016-06-15 5 views
0

staple, verwende ich Keras, um einen Auto-Encoder zu implementieren, gefolgt von einer TimeDistributed Ebene. Ich traf mich jedoch mit einem AssertionError.AssertionError Wenn ich Autoencoder mit TimeDistributed Layer mit Keras

Traceback-Log:

Traceback (most recent call last): 
    File "test3.py", line 115, in <module> 
    model.fit(x_train, y_train, batch_size=batch_size, validation_split=0.05, nb_epoch=1, shuffle=True) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/keras/engine/training.py", line 1022, in fit 
    self._make_test_function() 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/keras/engine/training.py", line 686, in _make_test_function 
    **self._function_kwargs) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/keras/backend/theano_backend.py", line 528, in function 
    return Function(inputs, outputs, updates=updates, **kwargs) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/keras/backend/theano_backend.py", line 514, in __init__ 
    **kwargs) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/compile/function.py", line 322, in function 
    output_keys=output_keys) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/compile/pfunc.py", line 480, in pfunc 
    output_keys=output_keys) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/compile/function_module.py", line 1827, in orig_function 
    output_keys=output_keys).create(
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/compile/function_module.py", line 1507, in __init__ 
    optimizer_profile = optimizer(fgraph) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/gof/opt.py", line 102, in __call__ 
    return self.optimize(fgraph) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/gof/opt.py", line 90, in optimize 
    ret = self.apply(fgraph, *args, **kwargs) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/gof/opt.py", line 233, in apply 
    sub_prof = optimizer.optimize(fgraph) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/gof/opt.py", line 86, in optimize 
    self.add_requirements(fgraph) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/tensor/opt.py", line 1434, in add_requirements 
    fgraph.attach_feature(ShapeFeature()) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/gof/fg.py", line 566, in attach_feature 
    attach(self) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/tensor/opt.py", line 1261, in on_attach 
    self.on_import(fgraph, node, reason='on_attach') 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/tensor/opt.py", line 1314, in on_import 
    self.set_shape(r, s) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/tensor/opt.py", line 1113, in set_shape 
    shape_vars.append(self.unpack(s[i])) 
    File "/home/xiaoyong/xiaoyong/local/lib/python2.7/site-packages/theano/tensor/opt.py", line 1035, in unpack 
    assert s_i >= 0 
AssertionError 

Mein Modell ist:

activation = LeakyReLU(alpha=0.3) 

input_model = Input(shape=(timestamp, gene_classes,)) 
model0 = BatchNormalization()(input_model) 
model1 = Convolution1D(512, 3, activation='relu', border_mode='same', W_regularizer=l2(0.01))(model0) 
encoded = MaxPooling1D(pool_length=2, border_mode='same')(model1) 
model2 = Convolution1D(512, 3, activation='relu', border_mode='same', W_regularizer=l2(0.01))(encoded) 
decoded = UpSampling1D(length=2)(model2) 
model3 = TimeDistributed(Dense(64, activation='relu'))(decoded) 
model3 = BatchNormalization()(model3) 
model3 = Dropout(0.5)(model3) 
model3 = TimeDistributed(Dense(30, activation='softmax'))(model3) 
model = Model(input_model, model3) 
sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True, clipvalue=2) 
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=["accuracy"]) 
+0

Auf den ersten Blick sieht das wie ein Fehler aus, kein Problem mit Ihrem Modell. Versuche es auf dem [keras issue tracker] (https://github.com/fchollet/keras/issues) zu melden und melde dich mit Ergebnissen zurück. – nemo

+0

Ich habe berichtet, aber noch keine Antwort. Vielen Dank. – Brian

+0

Bitte teilen Sie uns die URL für andere mit dem gleichen Problem. – nemo

Antwort

0

hatte ich die gleiche Fehlermeldung. Der Code für einen Teil des Netzwerks sieht ungefähr so ​​aus. Wie Sie sehen können, verwende ich auch Convolution1D.

qenc = Sequential() 
qenc.add(Embedding(output_dim=WORD2VEC_EMBED_SIZE, input_dim=vocab_size, 
        input_length=seq_maxlen, 
        weights=[embedding_weights])) 
qenc.add(LSTM(QA_EMBED_SIZE, return_sequences=True)) 
qenc.add(Dropout(0.3)) 
qenc.add(Convolution1D(QA_EMBED_SIZE // 2, 5, border_mode="valid")) 
qenc.add(MaxPooling1D(pool_length=2, border_mode="valid")) 
qenc.add(Dropout(0.3)) 
qenc.add(Flatten()) 

experimentierten I ein wenig mit den Parametern und den border_mode von „gleich“ zu „gültig“ in der Schicht MaxPooling1D der Fehler behoben ändert. Ich ging dann zurück und änderte auch den border_mode in der Convolution1D. Das kann oder kann nicht für Sie von einem Modellierungs-POV funktionieren, aber das ist die Problemumgehung, die ich verwendet habe - hoffe, dass dies hilft. Meine Keras Version ist 1.0.5.