Created
July 26, 2017 20:58
-
-
Save johntips/909e482a2ef3db77efa00d368e1d3f90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from scipy.misc import toimage | |
from keras.datasets import cifar10 | |
if __name__ == '__main__': | |
# CIFAR-10データセットをロード | |
(X_train, y_train), (X_test, y_test) = cifar10.load_data() | |
print(X_train.shape, y_train.shape) | |
print(X_test.shape, y_test.shape) | |
# 画像を描画 | |
nclasses = 10 | |
pos = 1 | |
for targetClass in range(nclasses): | |
targetIdx = [] | |
# クラスclassIDの画像のインデックスリストを取得 | |
for i in range(len(y_train)): | |
if y_train[i][0] == targetClass: | |
targetIdx.append(i) | |
# 各クラスからランダムに選んだ最初の10個の画像を描画 | |
np.random.shuffle(targetIdx) | |
for idx in targetIdx[:10]: | |
img = toimage(X_train[idx]) | |
plt.subplot(10, 10, pos) | |
plt.imshow(img) | |
plt.axis('off') | |
pos += 1 | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment