您好,我需要有关构建Unet的帮助。在检查模型目标时,我不断收到错误消息:传递给模型的Numpy数组列表不是模型期望的大小。预计会看到1个数组,但获得了以下2个数组的列表。
我的Input_shape =(2,256,256,120,1)与我的面罩大小相同。
我正在使用Keras DataGenerator。
def __data_generation(self, list_IDs_temp):
X = np.empty([self.batch_size,self.n_channels, *self.dim])
Y = np.empty([self.batch_size, 3 ,*self.dim])
X_ = []
y_ = []
# Generate data
for i, ID in enumerate(list_IDs_temp):
img = nib.load(im_path + ID).get_data()
mask = nib.load(label_path + ID).get_data()
mask = np.clip(mask, 0, 255)
cmask = (mask * 1. / 255)
out = cmask
X_.append(img)
y_.append(out)
X = np.expand_dims(X_, -1)
y = np.expand_dims(y_, -1)
# y = np.concatenate((1 - y, y), -1)
X = np.array(X)
y = np.array(y)
print ('### Dataset loaded')
print ('\t{}'.format(im_path))
print ('\t{}\t{}'.format(X.shape, y.shape))
print ('\tX:{:.1f}-{:.1f}\ty:{:.1f}-{:.1f}\n'.format(X.min(), X.max(), y.min(), y.max()))
return X, y
我的培训代码:
X, y = DataGenerator(partition['train'], **params)
model = build_model()
model.compile(optimizer=Adam(lr=1e-4), loss='binary_crossentropy', metrics=['binary_accuracy'])
checkpointer = ModelCheckpoint('model.{epoch:03d}.hdf5', save_freq=5)
model.fit(X, y, batch_size=2, epochs=1, callbacks=[checkpointer], validation_split=0.2)