【发布时间】:2018-09-01 03:19:13
【问题描述】:
我正在尝试使用以下ConvLSTM2D 架构从低分辨率图像序列中估计高分辨率图像序列:
import numpy as np, scipy.ndimage, matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Convolution2D, ConvLSTM2D, MaxPooling2D, UpSampling2D
from sklearn.metrics import accuracy_score, confusion_matrix, cohen_kappa_score
from sklearn.preprocessing import MinMaxScaler, StandardScaler
np.random.seed(123)
raw = np.arange(96).reshape(8,3,4)
data1 = scipy.ndimage.zoom(raw, zoom=(1,100,100), order=1, mode='nearest') #low res
print (data1.shape)
#(8, 300, 400)
data2 = scipy.ndimage.zoom(raw, zoom=(1,100,100), order=3, mode='nearest') #high res
print (data2.shape)
#(8, 300, 400)
X_train = data1.reshape(data1.shape[0], 1, data1.shape[1], data1.shape[2], 1)
Y_train = data2.reshape(data2.shape[0], 1, data2.shape[1], data2.shape[2], 1)
#(samples,time, rows, cols, channels)
model = Sequential()
input_shape = (data1.shape[0], data1.shape[1], data1.shape[2], 1)
#samples, time, rows, cols, channels
model.add(ConvLSTM2D(16, kernel_size=(3,3), activation='sigmoid',padding='same',input_shape=input_shape))
model.add(ConvLSTM2D(8, kernel_size=(3,3), activation='sigmoid',padding='same'))
print (model.summary())
model.compile(loss='mean_squared_error',
optimizer='adam',
metrics=['accuracy'])
model.fit(X_train, Y_train,
batch_size=1, epochs=10, verbose=1)
x,y = model.evaluate(X_train, Y_train, verbose=0)
print (x,y)
此声明将导致以下Value 错误:
ValueError: Input 0 is in compatible with layer conv_lst_m2d_2: expected ndim=5, found ndim=4
我该如何纠正这个ValueError?我认为问题出在输入形状上,但无法弄清楚到底出了什么问题。
请注意,输出也应该是图像序列,而不是分类结果。
【问题讨论】:
标签: tensorflow scikit-learn keras