【发布时间】:2020-10-11 15:01:26
【问题描述】:
所以我正在尝试显示已经增强的图像。但得到Invalid shape (64, 125, 125, 3) for image data 错误。这是我的代码:
from tensorflow.keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale=1./255,
zoom_range=0.1,
rotation_range=25,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.1, horizontal_flip=True,
fill_mode='nearest')
val_datagen = ImageDataGenerator(rescale=1./255)
# build image augmentation generators
train_generator = train_datagen.flow(train_data, train_labels_enc, batch_size=64, shuffle=True)
val_generator = val_datagen.flow(val_data, val_labels_enc, batch_size=64, shuffle=False)
from matplotlib import pyplot
for i in range(9):
# define subplot
pyplot.subplot(330 + 1 + i)
# generate batch of images
batch = train_generator.next()
# convert to unsigned integers for viewing
image = batch[0].astype('uint8')
# plot raw pixel data
pyplot.imshow(image)
pyplot.show()
错误指向pyplot.imshow(image)。任何帮助将不胜感激
【问题讨论】:
-
试试
image[0,:,:,:],它将显示64张图片中的第一张图片。您不能一次显示 64 张图像
标签: python tensorflow opencv matplotlib keras