我希望能够使用Keras生成更多的图像,您可以在这里看到, 使用以下代码(与源代码>随机旋转几乎相同):
# Random Rotations
from keras.datasets import mnist
from keras.preprocessing.image import ImageDataGenerator
from matplotlib import pyplot
from keras import backend as K
datagen = ImageDataGenerator(rotation_range=90)
# fit parameters from data
datagen.fit(cats["images"])
print(np.asarray(cats["label"]).shape) #output=(12464,)
print(np.asarray(cats["images"]).shape) #output=(12464, 60, 60, 1)
# configure batch size and retrieve one batch of images
for X_batch, y_batch in datagen.flow(cats["images"], cats["label"], batch_size=9):
# create a grid of 3x3 images
for i in range(0, 9):
pyplot.subplot(330 + 1 + i)
pyplot.imshow(X_batch[i].reshape(28, 28), cmap=pyplot.get_cmap('gray'))
# show the plot
pyplot.show()
break
但是我收到了以下的错误提示:
ValueError: x(图像张量)和y(标签)应该有相同的长度。找到的结果为:x.shape = (60, 60, 1),y.shape = (12464,)
这可能有助于进一步检查:
我想库里应该有什么问题,如果我将我的图像形状改成60x60而不是60x60x1,我会得到以下错误提示:
ValueError: .fit()的输入应该具有rank 4。数组形状(12464,60,60)。