Keras:如何连接输入层和输出层?

2024-04-25 23:49:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从以下位置复制网络: 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 ...

模型与模型.编译():

^{pr2}$

但我得到了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)

Tags: https模型inputoutputmodelpdfmaintrain