【问题标题】:Found 60000 input samples and 10000 target samples.How to solve this error?找到 60000 个输入样本和 10000 个目标样本。如何解决此错误?
【发布时间】:2020-02-25 15:20:36
【问题描述】:

这是我从 tensorflow 网站上的 tensorflow 教程中获得的代码。中途我得到了这个错误。 ii 成功训练了模型。但是当测试图像通过时我得到错误。

from tensorflow import keras
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
fashion_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.0
test_images=train_images/255.0
model=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.



【问题讨论】:

  • 请分享整个错误信息。
  • 这个错误是不言自明的,但你仍然应该发布整个堆栈跟踪。

标签: python tensorflow machine-learning keras tensorflow2.0


【解决方案1】:

因为你在规范化时打错了:

test_images=train_images/255.0

代替:

test_images = test_images / 255.0

【讨论】:

    【解决方案2】:
    test_images=train_images/255.0
    

    应该是:

    test_images=test_images/255.0
    

    否则,您将 train_images 除以 255,然后再将其除以 255

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-26
      • 2019-05-22
      • 2019-07-15
      • 2020-08-31
      • 2023-03-10
      • 2019-05-30
      • 2018-10-15
      • 1970-01-01
      相关资源
      最近更新 更多