본문 바로가기

하루 30분 컴퓨터 비전 공부하기

이미지 모델 다루기

MNIST데이터셋의 손글씨 데이터

from sklearn.datasets import load_digits

digits = load_digits()
digits.keys()

# 출력
dict_keys(['data', 'target', 'frame', 'feature_names', 'target_names', 'images', 'DESCR'])

load_digits() : Dictionary 자료형과 유사한 sklearn.utils.Bunch 자료형

digits_data = digits.data
# 데이터늬 shape 확인
digits_data.shape

# 출력
(1797, 64)

digits_data[0]

# 출력
224.625

손글씨 데이터는 이미지 데이터입니다. 그래서 각 숙자는 픽셀값을 의미합니다. 길이 64의 숫자 배열은 (8x8)크기의 이미지를 일렬로 펴놓은 것입니다.
이미지를 한번 확인해 보겠습니다.

import matplotlib.pyplot as plt
%matplotlib inline

plt.imshow(digits.data[1].reshape(8,8), cmap = 'gray')
plt.axis('off')
plt.show()

여러개의 이미지를 한번에 확인해보겠습니다.

for i in ragne(10):
    plt.subplot(2, 5,  i+1)
    plt.imshow(digits.data[i].reshape(8,8), cmap = 'gray')
    plt.axis('off')

plt.show()