본문 바로가기
인공지능

7.5 CNN 구현하기 (코드 짜기)

by Falto 2021. 8. 14.

먼저 데이타를 읽어보자. 앞에서도 말했지만, 우리가 인공지능 학습용으로 선택한 데이타는 아래의 손글씨 집합이다.

from deep.dataset.mnist import load_mnist
# deep/dataset/ 디렉토리 아래, mnist.py 화일이 있고, 그 화일안에 load_mnist 함수가 있으며, 그 디렉토리에 위 손글씨 집합 데이타가 있다.

# 데이터 읽기
(x_train, t_train), (x_test, t_test) = load_mnist(flatten=False)

x_train은 훈련용으로 선택한 손글씨 데이타
t_train은 손글씨에 대한 정답 데이타
x_test은 인공지능 시험용으로 선택한 손글씨 데이타
x_test은 인공지능 시험용에 사용할 정답 데이타

각 x_train, t_train, x_test, x_test 이 어떤 모습인지 print로 마구마구 찍어보자.


from deep.dataset.mnist import load_mnist

# 데이터 읽기
(x_train, t_train), (x_test, t_test) = load_mnist(flatten=False)
print(f"type of x_train is {type(x_train)}")
print(f"type of x_test is {type(x_test)}")
print(f"type of t_train is {type(t_train)}")
print(f"type of t_test is {type(t_test)}")
print("---------------------------------")
print(f"shape of x_train is {x_train.shape}")
print(f"shape of t_train is {t_train.shape}")
print(f"shape of x_test is {x_test.shape}")
print(f"shape of t_test is {t_test.shape}")
print("---------------------------------")

결과는?

x_train은 4차원 배열, t_train은 1차원 배열. 'numpy.ndarray' 데이타 형식은 배열이다.

t_train은 [5 0 4 5 3 7 0 2 5 .....................................................................................................] 이런 모양이고, 숫자 갯수는 60,000개이다. 각 숫자는 손글씨의 정답을 말한다. 즉, 첫번째 손글씨는 5를 의미하고, 두번째 손글씨는 0이고, 세번째는 4라는 의미이다. 손글씨 갯수가 60,000개이기 때문에 정답도 60,000개이어야 된다.

'인공지능' 카테고리의 다른 글

인공지능 '층' 용어정리  (0) 2021.08.20
CNN 코드 분석 1  (0) 2021.08.17
7.5 CNN 구현하기  (0) 2021.08.13
7.4.4 풀링 계층 구현하기  (0) 2021.08.12
인공지능 개념 파악하기 - 2/2  (0) 2021.08.07

댓글