### 模型拟合未使用所有提供的数据 [重复]

我在尝试Tensorflow 2.0 Keras的介绍教程时遇到了一个问题(https://www.tensorflow.org/tutorials/keras/classification)。

问题:

应该有(并且确实有)60,000张图像用于模型拟合。我通过打印train_imagestrain_labels的长度来确认这一点。

然而,在拟合模型时,输出显示为1875/1875,这让我认为并非所有数据都被使用了。测试数据也是如此。

我禁用了GPU检测,这似乎对这个问题没有影响。

我使用的是:

  • Python 3.8.3
  • Tensorflow 2.2.0

我的代码:

import tensorflow as tffrom tensorflow import kerasimport numpy as npimport matplotlib.pyplot as pltdata = keras.datasets.fashion_mnist(train_images, train_labels), (test_images, test_labels) = data.load_data()class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']# 预处理图像数据,使像素值在0和1之间train_images = train_images / 255.0test_images = test_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=10)test_loss, test_acc = model.evaluate(test_images,  test_labels, verbose=2)print('\nTest accuracy:', test_acc)

输出:

2020-05-17 17:48:07.147033: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll2020-05-17 17:48:10.075816: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll2020-05-17 17:48:10.098581: E tensorflow/stream_executor/cuda/cuda_driver.cc:313] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected2020-05-17 17:48:10.105898: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-UU9P1OG2020-05-17 17:48:10.109837: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-UU9P1OG2020-05-17 17:48:10.113879: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX22020-05-17 17:48:10.127711: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x14dc97288a0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:2020-05-17 17:48:10.132743: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default VersionEpoch 1/101875/1875 [==============================] - 2s 1ms/step - loss: 0.4943 - accuracy: 0.8264Epoch 2/101875/1875 [==============================] - 2s 938us/step - loss: 0.3747 - accuracy: 0.8649Epoch 3/101875/1875 [==============================] - 2s 929us/step - loss: 0.3403 - accuracy: 0.8762Epoch 4/101875/1875 [==============================] - 2s 914us/step - loss: 0.3146 - accuracy: 0.8844Epoch 5/101875/1875 [==============================] - 2s 937us/step - loss: 0.2985 - accuracy: 0.8900Epoch 6/101875/1875 [==============================] - 2s 923us/step - loss: 0.2808 - accuracy: 0.8964Epoch 7/101875/1875 [==============================] - 2s 939us/step - loss: 0.2702 - accuracy: 0.8998Epoch 8/101875/1875 [==============================] - 2s 911us/step - loss: 0.2585 - accuracy: 0.9032Epoch 9/101875/1875 [==============================] - 2s 918us/step - loss: 0.2482 - accuracy: 0.9073Epoch 10/101875/1875 [==============================] - 2s 931us/step - loss: 0.2412 - accuracy: 0.9106313/313 - 0s - loss: 0.3484 - accuracy: 0.8729Test accuracy: 0.8729000091552734

回答:

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

发表回复

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