CIFAR-10 データセットを紹介する. 利用条件は利用者で確認すること.
【目次】
■ CIFAR-10 データセット
CIFAR-10 データセット(Canadian Institute for Advanced Research, 10 classes)は,公開されているデータセット(オープンデータ)である.
CIFAR-10 データセット(Canadian Institute for Advanced Research, 10 classes) は,クラス数 10 の カラー画像と,各画像に付いたのラベルから構成されるデータセットである. 機械学習での画像分類の学習や検証に利用できる.
(内訳)60000枚の内訳は次の通りである
50000枚:教師データ
10000枚:検証データ
【文献】
Alex Krizhevsky, Vinod Nair, and Geoffrey Hinton. 'Learning multiple layers of features from tiny images', Alex Krizhevsky, 2009.
【サイト内の関連ページ】
【関連する外部ページ】
【サイト内の関連ページ】
【関連する外部ページ】
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」を指定して,一括読み込みを行っている.
cifar10, cifar10_metadata = tfds.load('cifar10', with_info = True, shuffle_files=True, as_supervised=True, batch_size = -1) x_train, y_train, x_test, y_test = cifar10['train'][0], cifar10['train'][1], cifar10['test'][0], cifar10['test'][1] print(cifar10_metadata)
MatplotLib を用いて,0 番目の画像を表示する
NUM = 0 plt.figure() plt.imshow(x_train[NUM,:,:,0], cmap='gray') plt.colorbar() plt.gca().grid(False) plt.show()
print(cifar10_metadata) print(cifar10_metadata.features["label"].num_classes) print(cifar10_metadata.features["label"].names)
MatplotLib を用いて,複数の画像を並べて表示する.
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'] 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 = cifar10['train'] test = cifar10['test'] print(train) print(test)