用于图像预测的ConvLSTM模型的输入形状

时间:2019-05-13 20:25:54

标签: python machine-learning neural-network deep-learning lstm

我正在尝试使用ConvLSTM模型进行图像预测。但是我在理解应该输入到神经网络的数据集时遇到了麻烦。

我在互联网上进行搜索,发现了诸如“使用ConvLSTM进行降水预测”之类的示例,以及使用ConvLSTM模型进行预测的其他一些模型。在第一次试验中,我选择了降水问题中提供的模型,以查看该模型如何对我的数据集做出反应。

def fn_get_model_convLSTM_tframe_5():

model = Sequential()
model.add(ConvLSTM2D(filters=64, kernel_size=(7, 7),
                     input_shape=(None, 101, 101, 1), padding='same',  return_sequences=True, 
                     activation='tanh', recurrent_activation='hard_sigmoid',
                     kernel_initializer='glorot_uniform', unit_forget_bias=True, 
                     dropout=0.3, recurrent_dropout=0.3, go_backwards=True ))
model.add(BatchNormalization())

model.add(ConvLSTM2D(filters=32, kernel_size=(7, 7), padding='same', return_sequences=True, 
                     activation='tanh', recurrent_activation='hard_sigmoid', 
                     kernel_initializer='glorot_uniform', unit_forget_bias=True, 
                     dropout=0.4, recurrent_dropout=0.3, go_backwards=True ))
model.add(BatchNormalization())

model.add(ConvLSTM2D(filters=32, kernel_size=(7, 7), padding='same', return_sequences=True, 
                     activation='tanh', recurrent_activation='hard_sigmoid', 
                     kernel_initializer='glorot_uniform', unit_forget_bias=True, 
                     dropout=0.4, recurrent_dropout=0.3, go_backwards=True ))
model.add(BatchNormalization())


model.add(ConvLSTM2D(filters=32, kernel_size=(7, 7), padding='same', return_sequences=False, 
                     activation='tanh', recurrent_activation='hard_sigmoid', 
                     kernel_initializer='glorot_uniform', unit_forget_bias=True, 
                     dropout=0.4, recurrent_dropout=0.3, go_backwards=True ))
model.add(BatchNormalization())

model.add(Conv2D(filters=1, kernel_size=(1, 1),
               activation='sigmoid',
               padding='same', data_format='channels_last')) 

print(model.summary())
return model

完整的代码可以在这里找到: https://github.com/TeaPearce/precipitation-prediction-convLSTM-keras/blob/master/precip_v09.py

  As I understood the image fed into the model had the shape of 101x101 with 4 color channels. The same is the case for my dataset (I am not giving all the details regarding my dataset as I am quite sure ConvLSTM model is suitable for my dataset and for running out of redundant discussion). 

  I have the images of size 35x45 with four color channels. In total, I have 35 sequences and each sequence contains 140 sequential images. Additionally I have 1 more sequence on which I should do prediction as it contains 120 images (I need to fulfill it till the 140) I have tried to reshape my dataset and fit it into array of size (35, 140, 35, 45, 4). So know I have array so called trainx for training dataset. But the thing is that I am confused about the labels that I should provide (Even I am not sure whether I should provide or not as we are talking about sequential images).

 Can anyone please help me on preparing this dataset for neural network and explain the datashape that I should provide clearly

1 个答案:

答案 0 :(得分:1)

input_shape = {None,101,101,1)

输入形状为101x101,具有 1 个通道

如果您有4个通道的图像,则将输入形状设为(None,101,101,4)