Keras:如何将输入层与输出层连接在一起?

时间:2018-10-07 00:53:52

标签: python tensorflow keras

我正在尝试从以下位置复制网络: https://arxiv.org/pdf/1604.07176.pdf

我看到它们的实现 https://github.com/wentaozhu/protein-cascade-cnn-lstm/blob/master/cb6133.py

我正在尝试仅在Q8任务上进行训练,而没有溶剂型任务。我试图将[512,50]嵌入层连接到[512,22]输出层,但是我不断遇到各种错误。这是我目前尝试连接的方式:

main_input = Input(shape=(maxlen_seq,), dtype='int32', name='main_input')
# Defining an embedding layer mapping from the words (n_words) to a vector of len 50
# input_orig = K.reshape(input, (maxlen_seq, n_words))
x = Embedding(input_dim=n_words, output_dim=50, input_length=maxlen_seq)(main_input)

aux_input = Input(shape=(maxlen_seq, n_words), name='aux_input')
x = concatenate([x, aux_input], axis=-1)
# ... rest of model ...

该模型可以使用model.compile()进行编译:

__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
main_input (InputLayer)         (None, 512)          0                                            
__________________________________________________________________________________________________
embedding_27 (Embedding)        (None, 512, 50)      1100        main_input[0][0]                 
__________________________________________________________________________________________________
aux_input (InputLayer)          (None, 512, 22)      0                                            
__________________________________________________________________________________________________
concatenate_54 (Concatenate)    (None, 512, 72)      0           embedding_27[0][0]               
                                                                 aux_input[0][0]                  
________________________________________________________________________________________
...

但是我得到一个ValueError: Error when checking input: expected aux_input to have 3 dimensions, but got array with shape (4464, 512)

模型定义为:

model = Model([main_input, aux_input], [y1, y2])

并适合:

model.fit({'main_input':X_train,
           'aux_input': X_train},
          {'main_output': y_train,
           'aux_output': y_train},
          batch_size=128, epochs=20, callbacks=[early, best_model],
          validation_data=({'main_input':X_val,
                            'aux_input': X_val},
                           {'main_output': y_val,
                            'aux_output': y_val}),
                            verbose=1)

0 个答案:

没有答案