Python 培训结束后,如何打印LSTM层的输出?
谁能给我一个建议,在培训结束后如何输出LSTM层的3个序列Python 培训结束后,如何打印LSTM层的输出?,python,tensorflow,keras,Python,Tensorflow,Keras,谁能给我一个建议,在培训结束后如何输出LSTM层的3个序列 inputs = Input(shape=(100, 1, )) lstm = LSTM(3, return_sequences=True)(inputs) outputs = TimeDistributed(Dense(1))(lstm) model = Model(inputs=inputs, outputs=outputs) model.compile(loss='mean_squared_error', optimizer='
inputs = Input(shape=(100, 1, ))
lstm = LSTM(3, return_sequences=True)(inputs)
outputs = TimeDistributed(Dense(1))(lstm)
model = Model(inputs=inputs, outputs=outputs)
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(x, y)
另一个问题:如果代码编写如下
inputs = Input(shape=(100, 1, ))
lstm = LSTM(3, return_sequences=True)(inputs)
outputs = TimeDistributed(Dense(1))(lstm)
model = Model(inputs=inputs, outputs=outputs)
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(x, y)
然后发生了一个错误:
TypeError: Output tensors to a Model must be Keras tensors. Found:
Tensor("add_1:0", shape=(?,), dtype=float32)
有人能帮我吗?非常感谢。我想我现在知道你想要什么了。您想打印 LSTM层为输入提供了一些值 下面是我将如何做到这一点至少有三种方法 此函数允许我们查看lstm层的输出 请注意,我们可以更改要查看输出的图层 但只需将[model.layers[1].output]中的1更改为其他2即可
lstm_out = K.function([model.inputs[0],
K.learning_phase()],
[model.layers[1].output])
# pass in the input and set the the learning phase to 0
print(lstm_out([X, 0]))
你的模型对我很合适。第一个问题不清楚。输出3个LSTM序列是什么意思?太棒了。您可以将其标记为答案,这样其他人也可以从中受益。
lstm_out = K.function([model.inputs[0],
K.learning_phase()],
[model.layers[1].output])
# pass in the input and set the the learning phase to 0
print(lstm_out([X, 0]))