从平面像素列表生成秩4 numpy数组,用于Keras中的ImageDataGenerator,然后用于matplotlib

2024-04-27 03:21:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数据帧,它由尺寸为137*236的greascale(c=1)图像组成,总共有32332个像素。我想使用ImageDataGenerator()来扩充每个图像,但是当我使用下面的代码时,会出现一个错误Invalid dimensions for image data

samples = np.expand_dims(df.iloc[[65],1:].values.reshape(137,236,1), 0)
# create image data augmentation generator
datagen = ImageDataGenerator(width_shift_range=[-200,200])
# prepare iterator
it = datagen.flow(samples, batch_size=1)
# generate samples and plot
for i in range(9):
    # define subplot
    pyplot.subplot(330 + 1 + i)
    # generate batch of images
    batch = it.next()
    # convert to unsigned integers for viewing
    image = batch[0].astype('uint8')
    print(image.shape)
    pyplot.imshow(image)
    # show the figure
    pyplot.show()

当我使用samples = np.expand_dims(df.iloc[[65],1:].values.reshape(137,236), 0)时,将错误显示为'Input data in `NumpyArrayIterator` should have rank 4. You passed an array with shape', (1, 137, 236)

这里出了什么问题


Tags: 图像imagedffordata错误npbatch