InceptionV3在Keras中的输入错误,期望input_1的形状为None

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抱怨形状不是None… 请帮助我,谢谢


回答:

你的输入形状不匹配:

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_batches和test_batches的target_size=(229,229)更改为target_size=(299,299)。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注