用matplotlib显示一下MNIST数据集中手写数字的真实面目
生活随笔
收集整理的這篇文章主要介紹了
用matplotlib显示一下MNIST数据集中手写数字的真实面目
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
MNIST 是一個入門級計算機視覺數據集,包含了很多手寫數字圖片。MNIST是一個手寫數字圖像的數據集,每幅圖像都由一個整數標記。它主要用于機器學習算法的性能對標。深度學習算法處理MNIST的效果相當好。
MNIST數據集包含一個有6萬個樣例的訓練集和一個有1萬個樣例的測試集。訓練集用于讓算法學習如何準確地預測出圖像的整數標簽,而測試集則用于檢查已訓練網絡的預測有多準確。
那么MNIST圖片是什么呢?讓我們看看手寫字體什么樣子吧。
#!/usr/bin/env python import os import tensorflow as tf import matplotlib.pyplot as pltos.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' tf.compat.v1.enable_eager_execution()print("TensorFlow Version:\t", tf.__version__)mnist = tf.keras.datasets.mnist(x_train, y_train), (x_test, y_test) = mnist.load_data() x_train, x_test = x_train / 255.0, x_test / 255.0fig, ax = plt.subplots(nrows=10, ncols=10, sharex='all', sharey='all') ax = ax.flatten() for i in range(100):img = x_train[i].reshape(28, 28)ax[i].imshow(img, cmap='Greys', interpolation='nearest') ax[0].set_xticks([]) ax[0].set_yticks([]) plt.tight_layout() plt.show()看看數字,歪歪斜斜的,很不好認啊。下面我們再把標簽加上,來看看真實面目。。
#!/usr/bin/env python import os import tensorflow as tf import matplotlib.pyplot as pltos.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' tf.compat.v1.enable_eager_execution()print("TensorFlow Version:\t", tf.__version__)mnist = tf.keras.datasets.mnist(x_train, y_train), (x_test, y_test) = mnist.load_data() x_train, x_test = x_train / 255.0, x_test / 255.0fig, ax = plt.subplots(nrows=5, ncols=5, sharex='all', sharey='all') ax = ax.flatten() for i in range(25):img = x_train[i].reshape(28, 28)ax[i].set_title(y_train[i])ax[i].imshow(img, cmap='Greys', interpolation='nearest') ax[0].set_xticks([]) ax[0].set_yticks([]) plt.tight_layout() plt.show()不管你是否認識,這就是標簽,說了算數的~~~
上面紅框里面的數字“5”,誰認識?別忘記告訴我啊。。。
總結
以上是生活随笔為你收集整理的用matplotlib显示一下MNIST数据集中手写数字的真实面目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python深度学习之分类模型示例,MN
- 下一篇: Python语言pip升级python-