ValueError: Error when checking input: expected input_1 to have shape (None, 299, 299, 3) but got array with shape (32, 229, 229, 3)
以下是代码的核心部分:
train_datagen = ImageDataGenerator()
train_batches = train_datagen.flow_from_directory('../train/',
target_size=(229, 229))
test_datagen = ImageDataGenerator()
test_batches = test_datagen.flow_from_directory('../test/',
target_size=(229, 229))
#
model = keras.applications.InceptionV3(weights="imagenet")
#
clf_model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
train_history = clf_model.fit_generator(train_batches,
steps_per_epoch=train_batches.samples/train_batches.batch_size,
epochs=1,
validation_data = test_batches,
validation_steps=test_batches.samples/test_batches.batch_size )
看起来很奇怪。我看到其他人的错误就像是
Error when checking input: expected input_1 to have shape (None, 10, 3) but got array with shape (1, 3, 10)
或
Error when checking input: expected input_1 to have shape (None, 10, 3) but got array with shape (1, 4, 16)
然而,在我的错误中,形状看起来很好。 Keras抱怨形状不是没有...... 请帮忙。谢谢
答案 0 :(得分:0)
您的输入形状不是数学:
train_datagen = ImageDataGenerator()
train_batches = train_datagen.flow_from_directory('../train/',
target_size=(229, 229))
test_datagen = ImageDataGenerator()
test_batches = test_datagen.flow_from_directory('../test/',
target_size=(229, 229))
将train_satches和test_batches的target_size =(229,229)更改为target_size =(299,299)。