컨볼루션 층

Soyoung Park·2022년 10월 4일
0

TIL deep learning

목록 보기
21/22

"공간 정보를 유지한다."


^ 가장 큰 값만 가져와 max pooling 특징 추출해주기.

01_Fashion_MNIST_CNN


^ 런타임 > 런타임 유형 변경 > GPU

from tensorflow.keras.datasets.fashion_mnist import load_data

# Fashion-MNIST 데이터를 다운받습니다.
(X_train, y_train), (X_test, y_test) = load_data()
print(X_train.shape, X_test.shape)

^ 라이브러리

import matplotlib.pyplot as plt
import numpy as np
# np.random.seed(777)

# Fashion-MNIST의 레이블에 해당하는 품목입니다.
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']

sample_size = 9
# 0 ~ 59999의 범위에서 무작위로 3개의 정수를 뽑습니다.
random_idx = np.random.randint(60000, size=sample_size) 

plt.figure(figsize = (5, 5))
for i, idx in enumerate(random_idx):
    plt.subplot(3, 3, i+1)
    plt.xticks([])
    plt.yticks([])
    plt.imshow(X_train[idx], cmap = 'gray')
    plt.xlabel(class_names[y_train[idx]])
plt.show()

^ 데이터 그려보기

# 2) Conv2 신경망 사용하기 위한 데이터 형태로 변환  -> 3차원 배열 ( w, h, c) 1: 흑백, 3: 컬러 -> (28,28,1)

^ 1이라는 색깔 들어감.

^ 정규화 되었음을 확인 가능


^ 원핫 인코딩

^ 검증 데이터셋 분리

^ 모델 구성


^ 모델 확인하기 1

^ 모델 확인하기 2

^ 모델 설정하기

^ 모델 학습하기

import matplotlib.pyplot as plt

his_dict = history.history
loss = his_dict['loss']
val_loss = his_dict['val_loss'] # 검증 데이터가 있는 경우 ‘val_’ 수식어가 붙습니다.

epochs = range(1, len(loss) + 1)
fig = plt.figure(figsize = (10, 5))

# 훈련 및 검증 손실 그리기
ax1 = fig.add_subplot(1, 2, 1)
ax1.plot(epochs, loss, color = 'blue', label = 'train_loss')
ax1.plot(epochs, val_loss, color = 'orange', label = 'val_loss')
ax1.set_title('train and val loss')
ax1.set_xlabel('epochs')
ax1.set_ylabel('loss')
ax1.legend()

acc = his_dict['acc']
val_acc = his_dict['val_acc']

# 훈련 및 검증 정확도 그리기
ax2 = fig.add_subplot(1, 2, 2)
ax2.plot(epochs, acc, color = 'blue', label = 'train_acc')
ax2.plot(epochs, val_acc, color = 'orange', label = 'val_acc')
ax2.set_title('train and val acc')
ax2.set_xlabel('epochs')
ax2.set_ylabel('loss')
ax2.legend()

plt.show()

^ 학습결과그리기

-평가하기

0개의 댓글