Keras 尺寸 LSTM 净 3 暗淡预期



>我对 LSTM 顺序网络的输入尺寸和形状有问题。我正在寻找正确的方法来重塑和调整这个input_merged(?, 1, 2400, 60( 到 LSTM 输入已成功连接,但不接受来自 LSTM 净输入的新维度。

程序

inp1 = Input(features_set3.shape)
inp2 = Input(features_set4.shape)
print("  shapeINP1 ")
print(inp1.shape)
print("  shapeINP2 ")
print(inp2.shape)
input_merged = Concatenate(axis=2)([inp1, inp2])
print(input_merged.shape)
print("  OK  ")
lstm = LSTM(units=50, return_sequences=True, input_shape=input_merged.shape)(input_merged)
model = Sequential()  
model.add(LSTM)  

记录尺寸误差和输入形状

b'你好,TensorFlow!" 42 使用 TensorFlow 后端。

features_set (1200, 60(

features_set3 (1, 1200, 60) DataConversionWarning:输入 dtype int64 的数据已通过 MinMaxScalr 转换为 float64。 warnings.warn(msg, DataConversionWarning(

features_set2

(1200, 60(

features_set4

(1, 1200, 60(

形状INP1

(?, 1, 1200, 60(

形状INP2

(?, 1, 1200, 60(

(?, 1, 2400, 60(

还行 回溯(最近一次调用(: prog10-t12.py",第 84 行,模块中 lstm = LSTM(units=50, return_sequences=True, input_shape=input_merged.shape((input_merged(

文件 "C:\ProgramData\Anaconda3\lib\site-packages\keras\layers\recurrent.py",第 532 行,在调用中 返回超级(RNN,自我(。呼叫(输入,夸格( 文件"base_layer.py",第 414 行,在调用中 self.assert_input_compatibility(输入( 文件 "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\base_layer.py",第 311 行,第 assert_input_compatibility 行 str(K.ndim(x

(((

值错误:输入 0 与图层 lstm_1 不兼容:预期 ndim=3,发现 ndim=4

你应该先重塑你的输入张量:

inp1 = keras.layers.Reshape((1200, 60))(inp1)
inp2 = keras.layers.Reshape((1200, 60))(inp2)

input_merged = keras.layers.Reshape((2400, 60))(input_merged)

这会将input_merged的形状更改为(None, 2400, 60),从而被 LSTM 层接受

最新更新