LoginSignup
1
1

More than 5 years have passed since last update.

kerasとMatplotlibを使ってデータセットCIFAR-10の画像を表示させて遊んでみた

Last updated at Posted at 2018-11-22

Matplotlibとは?

グラフが描画できるライブラリ
機械学習のデータの可視化などに利用される

CIFAR-10とは?

32×32サイズの画像6万枚が10種類のラベルとセットで含まれている
画像とラベルの種類はairplane,automobile,bird,cat,deer,dog,frog,horse,ship,truckの10種類

実際にmatplotlibで表示させて遊んでみる

1.データをインポート

kerasを使ってCIFAR-10の画像をインポートします
(※kerasはインストール済みの状態とします)

from keras.datasets import cifar10
(x_train,y_train),(x_test,y_test) = cifar10.load_data()

機械学習での学習用とテスト用のデータなので(x_train,y_train),(x_test,y_test)となっています(※詳しい話は割愛)

2. Matplotlibをインポート

from matplotlib import pyplot as plt

3. CIFAAR-10の画像データを表示させる

 例:1枚目の画像を表示させる場合

plt.imshow(x_train[0])
plt.show()

JupyterNotebookで手順1から試していくと

1枚目の画像
スクリーンショット 2018-11-23 1.08.10.png
かえる(frog)・・・?

4枚目
スクリーンショット 2018-11-23 1.09.56.png
これは鹿(deer)っぽい

40枚目
スクリーンショット 2018-11-23 1.12.29.png

ん〜ー。

(※正解のラベルはy_trainに付いてます)

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1