[英]Keras ImageDataGenerator: problem with data and label shape
我想用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()
输入应该具有等级4。得到形状为(.fit()
数组
cats['images']
和cats['labels']
很可能是Python列表。 首先使用np.array
将它们转换为数组,然后将它们传递给flow
方法:
cats['images'] = np.array(cats['images'])
cats['labels'] = np.array(cats['labels'])
您需要更改标签的形状
labels = np.asarray(cats["label"]).reshape(( -1 , 1 ))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.