[英]Keras gives error when using ImageDataGenerator
I have a large dataset, that I have added to a Keras ImageDataGenerator. 我有一个大型数据集,我已添加到Keras ImageDataGenerator中。
Everything seems to work fine, until it throws this error: 一切似乎工作正常,直到它抛出此错误:
ValueError: Output of generator should be a tuple `(x, y, sample_weight)` or `(x, y)`. Found: [[[[ 91. 91. 93.]
[ 96. 96. 98.]
[ 98. 98. 100.]
...
[115. 116. 118.]
[108. 109. 111.]
[107. 108. 110.]]
[[ 93. 93. 95.]
[ 97. 97. 99.]
[ 98. 98. 100.]
...
I have created the generators as such: 我已经创建了这样的生成器:
train_datagen = ImageDataGenerator()
train_generator = train_datagen.flow_from_dataframe(
dataframe=img_celebs[img_celebs['SmallTrain'] == 1].reset_index(),
directory='data',
target_size=(img_width, img_height),
x_col='file',
class_mode=None)
It seems to work. 它似乎工作。 For example
例如
train_generator.image_shape gives
(218, 178, 3)
My model is: 我的模型是:
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(218, 178, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten()) # this converts our 3D feature maps to 1D feature vectors
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
And I run it with: 我运行它:
model.fit_generator(
train_generator,
steps_per_epoch=2000 // batch_size,
epochs=50,
validation_data=validation_generator,
validation_steps=800 // batch_size)
I changed the class_mode in this part to 'input' 我将此部分中的class_mode更改为“input”
train_generator = train_datagen.flow_from_dataframe(
dataframe=img_celebs[img_celebs['SmallTrain'] == 1].reset_index(),
directory='data',
target_size=(img_width, img_height),
x_col='file',
class_mode='input')
and it seems to work fine :-) 它似乎工作正常:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.