5-2.mnist_digit_pixel_by_pixel.ipynb 노트북을 재사용하여 패션 MNIST 이미지를 출력합니다.
from matplotlib import pyplot as plt
from tensorflow.keras.datasets import fashion_mnist
import numpy as np
(X_train, y_train), (X_valid, y_valid) = fashion_mnist.load_data()
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz 29515/29515 [==============================] - 0s 0us/step Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz 26421880/26421880 [==============================] - 0s 0us/step Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz 5148/5148 [==============================] - 0s 0us/step Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz 4422102/4422102 [==============================] - 0s 0us/step
# sample = np.random.randint(0, X_train.shape[0])
sample = 39235
plt.figure(figsize = (10,10))
mnist_img = X_train[sample]
plt.imshow(mnist_img,cmap="Greys")
ax = plt.gca()
# First turn off the major labels, but not the major ticks
plt.tick_params(
axis='both', # changes apply to the both x and y axes
which='major', # Change the major ticks only
bottom=True, # ticks along the bottom edge are on
left=True, # ticks along the top edge are on
labelbottom=False, # labels along the bottom edge are off
labelleft=False) # labels along the left edge are off
# Next turn off the minor ticks, but not the minor labels
plt.tick_params(
axis='both', # changes apply to both x and y axes
which='minor', # Change the minor ticks only
bottom=False, # ticks along the bottom edge are off
left=False, # ticks along the left edge are off
labelbottom=True, # labels along the bottom edge are on
labelleft=True) # labels along the left edge are on
# Set the major ticks, starting at 1 (the -0.5 tick gets hidden off the canvas)
ax.set_xticks(np.arange(-.5, 28, 1))
ax.set_yticks(np.arange(-.5, 28, 1))
# Set the minor ticks and labels
ax.set_xticks(np.arange(0, 28, 1), minor=True);
ax.set_xticklabels([str(i) for i in np.arange(0, 28, 1)], minor=True);
ax.set_yticks(np.arange(0, 28, 1), minor=True);
ax.set_yticklabels([str(i) for i in np.arange(0, 28, 1)], minor=True);
ax.grid(color='black', linestyle='-', linewidth=1.5)
_ = plt.colorbar(fraction=0.046, pad=0.04, ticks=[0,32,64,96,128,160,192,224,255])
y_train[sample]
9