Fashion MNIST データセットを紹介する. 利用条件は利用者で確認すること.
【目次】
■ Fashion MNIST データセット
Fashion MNIST データセットは,公開されているデータセット(オープンデータ)である.
Fashion MNIST データセットは,10 種類のモノクロ画像と,各画像に付いた ラベル(10 種類の中の種類を示す)から構成されるデータセットである.
(内訳)70000枚の内訳は次の通りである
60000枚:教師データ
10000枚:検証データ
【文献】
Han Xiao, Kashif Rasul, and Roland Vollgraf, Fashion-MNIST: a Novel Image Dataset for Benchmarking Machine Learning Algorithms, arXiv:1708.07747 [cs.LG], 2017.
【サイト内の関連ページ】
【関連する外部ページ】
【サイト内の関連ページ】
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
Windows では,コマンドプロン プトを管理者として実行し, 次のコマンドを実行する.
python -m pip install -U tensorflow-gpu tensorflow_datasets keras numpy matplotlib
Windows での TensorFlow のインストールの詳細: 別ページ »で説明
(このページで,Build Tools for Visual Studio 2022,NVIDIA ドライバ, NVIDIA CUDA ツールキット, NVIDIA cuDNNのインストールも説明している.)
Ubuntu では,次のコマンドを実行.
sudo apt -y update sudo apt -y install python3-numpy python3-matplotlib sudo pip3 install -U tensorflow-gpu tensorflow_datasets keras
Ubuntu での TensorFlow のインストールの詳細: 別ページ »で説明
(このページで,NVIDIA ドライバ, NVIDIA CUDA ツールキット, NVIDIA cuDNNのインストールも説明している.)
【Python の利用】
Python は,次のコマンドで起動できる.
Python 開発環境(Jupyter Qt Console, Jupyter ノートブック (Jupyter Notebook), Jupyter Lab, Nteract, Spyder, PyCharm, PyScripterなど)も便利である.
Python のまとめ: 別ページ »にまとめ
これ以降の操作は,jupyter qtconsole で行う.
jupyter qtconsole
import tensorflow as tf import numpy as np import tensorflow_datasets as tfds %matplotlib inline import matplotlib.pyplot as plt import warnings warnings.filterwarnings('ignore') # Suppress Matplotlib warnings
結果は,TensorFlow の Tensor である.
type は型,shape はサイズ,np.max と np.mi は最大値と最小値.
tensorflow_datasets の loadで, 「batch_size = -1」を指定して,一括読み込みを行っている.
fashion_mnist, fashion_mnist_metadata = tfds.load('fashion_mnist', with_info = True, shuffle_files=True, as_supervised=True, batch_size = -1) x_train, y_train, x_test, y_test = fashion_mnist['train'][0], fashion_mnist['train'][1], fashion_mnist['test'][0], fashion_mnist['test'][1] print(fashion_mnist_metadata)
MatplotLib を用いて,0 番目の画像を表示する
NUM = 0 plt.figure() plt.imshow(x_train[NUM,:,:,0], cmap='gray') plt.colorbar() plt.gca().grid(False) plt.show()
print(fashion_mnist_metadata) print(fashion_mnist_metadata.features["label"].num_classes) print(fashion_mnist_metadata.features["label"].names)
MatplotLib を用いて,複数の画像を並べて表示する.
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'] plt.style.use('default') plt.figure(figsize=(10,10)) for i in range(25): plt.subplot(5,5,i+1) plt.xticks([]) plt.yticks([]) plt.grid(False) plt.imshow(x_train[i], cmap=plt.cm.binary) plt.xlabel(class_names[y_train[i]]) plt.show()
train = fashion_mnist['train'] test = fashion_mnist['test'] print(train) print(test)