PostIT

[AI/Deep Learing] Deep Learning 준비하기 - MNIST DataSet - 5 본문

Deep Learning

[AI/Deep Learing] Deep Learning 준비하기 - MNIST DataSet - 5

shun10114 2017. 6. 23. 15:55

# [AI/Deep Learing] Deep Learning 준비하기 - MNIST DataSet - 5

import sys, os

sys.path.append(os.pardir)

import numpy as np

import pickle

from dataset.mnist import load_mnist

from common.functions import sigmoid, softmax

from PIL import Image


# MNIST 간단히 이미지 출력해보기.

#파일 다운로드

# normalize : 0.0 ~ 1.0 사이로 정규화 할지 여부, Fasle = 0 ~ 255

# flatten : 1차원 배열로 만들지 여부

# one_hot_lable : 정답을 뜻하는 원소만 1, 나머지는 0으로 설정할지 여부



(x_train, t_train), (x_test, t_test) = load_mnist(flatten=True, normalize=False)


#각 데이터 형상 출력


print(x_train.shape) # (60000, 784)

print(t_train.shape) # (60000,)

print(x_test.shape) # (10000, 784)

print(t_test.shape) # (10000,)

    (60000, 784)

    (60000,)

    (10000, 784)

    (10000,)


def img_show(img):

    pil_img = Image.fromarray(np.uint8(img))

    pil_img.show()


img = x_train[0]

label = t_train[0]

print(label)

print(img.shape)

    5

    (784,)



# flatten = True로 1차원 배열로 정렬되어 다시 원래의 형상으로 reshape해주는 것


img = img.reshape(28, 28)

print(img.shape)

    (28, 28)


# 이미지 보기


img_show(img)


Comments