我有一个包含每日降水图图像的数据集。我正在尝试使用ConvLSTM2D构建降水临近预报模型。
请帮助我弄清楚如何改变阵列的形状。
以此作为参考:https://github.com/wqxu/ConvLSTM/blob/master/radar_forecast.py
请帮助我解决此错误:
Error when checking input: expected conv_lst_m2d_167_input to have 5 dimensions, but got array with shape (1785, 400, 320, 3)
如果我向X_Train的重塑数组添加另一个尺寸:
X_Train = np.array(X).reshape(-1, 400, 320, 1, 3)[:1785] # converting list to a numpy array
我收到以下错误[1785发生了什么事?]:
Error when checking input: expected conv_lst_m2d_167_input to have 5 dimensions, but got array with shape (400, 320, 1, 3)
如果我向ConvLSTM2D输入层的input_shape添加另一个尺寸:
model.add(ConvLSTM2D(filters=128, kernel_size=(3, 3), input_shape=(None, 400, 320, 1, 3), padding='same', return_sequences=True))
我收到以下错误:
ValueError: Input 0 is incompatible with layer conv_lst_m2d_5:expected ndim=5, found ndim=6
此刻,我正试图找到任何实际可行的情况,以便我可以从那里开始。如果可以的话,请帮忙。
基本上我想知道问题是否出在我数组的维数上?如果可以,该如何更改?
import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers.convolutional import Conv3D
from keras.layers.convolutional_recurrent import ConvLSTM2D
from keras.layers.normalization import BatchNormalization
DATADIR = "C:/Users/StephanIliffe/Documents/data"
training_data = []
def create_training_data():
path = os.path.join(DATADIR, "Input") # path to jpg precipitation maps
class_num = 1
for img in os.listdir(path):
img_array = cv2.imread(os.path.join(path, img))
new_array = cv2.resize(img_array, (400, 320))
training_data.append([new_array, class_num])
create_training_data()
X = []
X_Train = []
X_Test = []
for features, label in training_data:
X.append(features)
X_Train = np.array(X).reshape(-1, 400, 320, 3)[:1785] # converting list to a numpy array
X_Test = np.array(X).reshape(-1, 400, 320, 3)[765:] # converting list to a numpy array
model = Sequential()
model.add(ConvLSTM2D(filters=128, kernel_size=(3, 3),
input_shape=(None, 400, 320, 3),
padding='same', return_sequences=True))
model.add(BatchNormalization())
model.add(ConvLSTM2D(filters=128, kernel_size=(3, 3),
padding='same', return_sequences=True))
model.add(BatchNormalization())
model.add(ConvLSTM2D(filters=128, kernel_size=(3, 3),
padding='same', return_sequences=True))
model.add(BatchNormalization())
model.add(ConvLSTM2D(filters=128, kernel_size=(3, 3),
padding='same', return_sequences=True))
model.add(BatchNormalization())
model.add(Conv3D(filters=1, kernel_size=(3, 3, 3),
activation='sigmoid',
padding='same', data_format='channels_last'))
model.compile(loss='mean_squared_error', optimizer='adadelta')
model.fit(X_Train, X_Test, batch_size=30, epochs=10, validation_split=0.05)
答案 0 :(得分:2)
好吧,这正是错误的意思:expected conv_lst_m2d_167_input to have 5 dimensions, but got array with shape (400, 320, 1, 3)
。您的输入数据有四个维度。它必须有五个:(samples, time, rows, columns, channels)
。