2

我正在尝试使用Keras的内置图像预处理功能来增加序列中的图像。 我的数据集形状为(13200, 4, 168, 168, 1),包含13200个序列,每个序列由4个168x168px灰度图像组成。是否可以对图像序列使用图像预处理?

当试图在我的数据集,我得到运行datagen.flow()

ValueError: ('Input data in `NumpyArrayIterator` should have rank 4. You passed an array with shape', (13200, 4, 168, 168, 1)) 

我假设ImageDataGenerator不能够正确地处理我的每个样本4个的图像序列。有没有办法做到这一点?

+0

你'y'看起来像什么? –

+0

'y.shape =(13200,250)',因为我有250个班级。 – Hagen

+0

好的 - 所以我的回答应该是正确的。 –

回答

2

尝试通过定义一个新的生成:

def sequence_image_generator(x, y, batch_size, generator, seq_len=4): 
    new_y = numpy.repeat(y, seq_len, axis = 0) 
    helper_flow = generator.flow(x.reshape((x.shape[0] * seq_len, 
              x.shape[2], 
              x.shape[3], 
              x.shape[4])), 
           new_y, 
           batch_size=seq_len * batch_size) 
    for x_temp, y_temp in helper_flow: 
     yield x_temp.reshape((x_temp.shape[0]/seq_len, 
           seq_len, 
           x.shape[2], 
           x.shape[3], 
           x.shape[4])), y_temp[::seq_len,:] 
+0

谢谢你的回答。当我运行它时,我得到:'ValueError:X(图像张量)和y(标签)应该具有相同的长度。“因此我向'numpy.repeat()'添加了'axis = 0'。 现在我得到'ValueError:新数组的总大小必须保持不变'为包含'yield'语句的最后一行。你知道这是什么原因吗? – Hagen

+1

立即尝试。 ('y_temp [:: seq_len,:'') –

+0

同样的错误。在调试过程中,我发现它实际上是导致错误的第一部分(重塑'x_temp')。 – Hagen