Keras:训练时出现价值错误

时间:2018-07-03 10:43:48

标签: python python-3.x tensorflow keras deep-learning

我有这样的深度学习架构:

main_input_1 = Input(shape=(50,1), dtype='float32', name='main_input_1')
main_input_2 = Input(shape=(50,1), dtype='float32', name='main_input_2')
lstm_out=LSTM(32,activation='tanh',recurrent_activation='sigmoid',return_sequences=True)
mean_pooling=AveragePooling1D(pool_size=2,strides=2,padding='valid')

lstm_out_1=lstm_out(main_input_1)
lstm_out_2=lstm_out(main_input_2)
mean_pooling_1=mean_pooling(lstm_out_1)
mean_pooling_2=mean_pooling(lstm_out_2)

concatenate_layer=Concatenate()([mean_pooling_1,mean_pooling_2])

logistic_regression_output=Dense(1,activation='softmax',name='main_output')(concatenate_layer)


model = Model(inputs=[main_input_1, main_input_2], outputs=[main_output])

我使各层平行运行(两面都具有相同的结构)。我正在使用Keras的功能性api进行相同的操作。但是在运行它时,出现以下错误:

Traceback (most recent call last):
  File "Main_Architecture.py", line 38, in <module>
    model = Model(inputs=[main_input_1, main_input_2], outputs=[main_output])
  File "/home/tpradhan/anaconda3/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/home/tpradhan/anaconda3/lib/python3.6/site-packages/keras/engine/network.py", line 91, in __init__
    self._init_graph_network(*args, **kwargs)
  File "/home/tpradhan/anaconda3/lib/python3.6/site-packages/keras/engine/network.py", line 192, in _init_graph_network
    'Found: ' + str(x))
ValueError: Output tensors to a Model must be the output of a TensorFlow `Layer` (thus holding past layer metadata). Found: [0.00000000e+00 5.09370000e-06 8.19930500e-04 ... 9.61476653e-02
 3.62692160e-03 3.62692160e-03]

我阅读了类似错误的问题,但对我没有帮助。请帮助我解决问题。

1 个答案:

答案 0 :(得分:1)

您正在为输出参数传递图层名称。您应该传递the layer(换句话说,参数值应该是引用输出层的变量)。

model = Model(inputs=[main_input_1, main_input_2], outputs=[logistic_regression_output])