发现60000个输入样本和10000个目标样本。如何解决这个错误?

这是我在TensorFlow网站上的教程中获取的代码。在进行到一半时,我遇到了这个错误。我成功地训练了模型,但当测试图像被传入时,我得到了错误。

from tensorflow import kerasimport numpy as npimport pandas as pdimport matplotlib.pyplot as pltfashion_mnist= keras.datasets.fashion_mnist(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']train_images=train_images/255.0test_images=train_images/255.0model=keras.Sequential([    keras.layers.Flatten(input_shape=(28,28)),    keras.layers.Dense(128,activation='relu'),    keras.layers.Dense(10)])model.compile(optimizer='adam',              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),              metrics=['accuracy'])model.fit(train_images,train_labels,epochs=5)test_loss, test_acc = model.evaluate(test_images,  test_labels, verbose=2)print('\nTest accuracy:', test_acc)```this code gives the following error:ValueError: Input arrays should have the same number of samples as target arrays. Found 60000 input samples and 10000 target samples.

回答:

test_images=train_images/255.0

应该改为:

test_images=test_images/255.0

否则你是在将train_images除以255,然后再将结果除以255。

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中创建了一个多类分类项目。该项目可以对…

发表回复

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