본문 바로가기

DS/fast campus daily report

7.29 (딥러닝 인공지능) tensorflow 2.0 예제 dataset 소개(MNIST) 및 불러오기

 tensorflow 2.0 예제 dataset 소개(MNIST) 및 불러오기 (19:12)

# tensorflow data loading

import numpy as np
import matplotlib.pyplot as plt

import tensorflow as tf

%matplotlib inline

from tensorflow.keras import datasets
mnist = datasets.mnist
(train_x, train_y), (test_x, test_y) = mnist.load_data()

# 데이터 들여다보기
train_x.shape
# >> (60000, 28, 28)

# 데이터 하나만 뽑기
image = train_x[0]
image.shape
# >> (28,28)

# 시각화해서 확인
plt.imshow(image, 'gray')
plt.show()

# >> 숫자 5 image

# channel 관련
# 데이터 차원수 늘리기(numpy)
expanded_data = np.expand_dims(train_x, -1)
expanded_data.shape
# >> (1,60000,28,28)

# tensorflow 차원수 늘리기
new_train_x = tf.expaned_dims(train_x, -1)
new_train_x.shape