#!/usr/bin/env python # coding: utf-8 # # 패션 MNIST # [5-2.mnist_digit_pixel_by_pixel.ipynb](5-2.mnist_digit_pixel_by_pixel.ipynb) 노트북을 재사용하여 패션 MNIST 이미지를 출력합니다. # [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/rickiepark/dl-illustrated/blob/master/notebooks/14-1.fashion_mnist_pixel_by_pixel.ipynb) # #### 라이브러리 적재 # In[1]: from matplotlib import pyplot as plt from tensorflow.keras.datasets import fashion_mnist import numpy as np # #### 데이터 적재 # In[2]: (X_train, y_train), (X_valid, y_valid) = fashion_mnist.load_data() # #### 이미지 샘플 # In[3]: # sample = np.random.randint(0, X_train.shape[0]) sample = 39235 # #### 이미지 출력 # In[4]: 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]) # #### 이미지 레이블 확인 # In[5]: y_train[sample]