Python Keras中的图像序列处理ConvLSTM与LSTM体系结构
我需要训练一个基于序列的10x10图像分割。以下是我要使用的lstm和CONVLSM模型:Python Keras中的图像序列处理ConvLSTM与LSTM体系结构,python,tensorflow,keras,lstm,keras-layer,Python,Tensorflow,Keras,Lstm,Keras Layer,我需要训练一个基于序列的10x10图像分割。以下是我要使用的lstm和CONVLSM模型: def lstmModel(): # Model definition model = Sequential() model.add(LSTM(50, batch_input_shape=(1, None, inp.shape[1]*inp.shape[2]), return_sequences=True, stateful=True)) model.add(Dense(o
def lstmModel():
# Model definition
model = Sequential()
model.add(LSTM(50, batch_input_shape=(1, None, inp.shape[1]*inp.shape[2]), return_sequences=True, stateful=True))
model.add(Dense(out.shape[1]*out.shape[2], activation='softmax'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.summary()
return model
def convlstmModel():
# Model definition
model = Sequential()
model.add(ConvLSTM2D(12, kernel_size=5, padding = "same", batch_input_shape=(1, None, inp.shape[1], inp.shape[2], 1), return_sequences=True, stateful=True))
model.add(Conv2D(20, 3, padding='same', activation='softmax'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.summary()
return model
我训练了10个随机10x10图像序列的模型。LSTM模型对我来说似乎很好,但CONVLSM模型显示Conv2D层的尺寸不匹配:
ValueError: Input 0 is incompatible with layer conv2d_1: expected ndim=4, found ndim=5
非常感谢您的帮助。谢谢 错误消息暗示您的输入数据将以5维而不是4维的形式进入conv2d层。该模型应接收如下形状的输入:
(samples, time, rows, cols, channels)
假设您使用的是最后一个后端通道(tensorflow)。然后,通过conv2d层逐个发送
(时间、行、列、通道)
的每个片段。但是,错误消息暗示传递的维度是5,而不是预期的4。验证输入数据的形状,如有必要,可以修改答案。LSTM
层用于“时间序列”。Conv
层用于“静态图像”
你需要像(批处理、步骤、特征)
另一个要求:
(批次、witdh、高度、特征)
现在,ConvLSTM2D
将两者混合,需要(批次、台阶、宽度、高度、特征)
离开ConvLSTM2D
时,您有一个额外的步骤
维度,该维度不受convlst2d
支持
如果要保留此维度,请将卷积与TimeDistributed
包装一起使用:
model.add(TimeDistributed(Conv2D(...))
请注意,与其他只有3个维度的模型相比,您仍然拥有所有5个维度
您应该使用某种重塑或其他操作使其适合您的训练数据
既然你的问题没有说明什么,我们现在只能回答这些了