Date: September 11, 2022

Topic : Neural Network

Recall

  1. 분류 문제에서 클래스와 레이블이란?

Notes

<케라스에서 MNIST 데이터셋 적재하기>

from tensorflow.keras.datasets import mnist
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
<신경망 구조>

from tensorflow import keras
from tensorflow.keras import layers

model = keras.Sequential([
		layers.Dense(512, activation="relu")
		layers.Dense(10, activation="softmax")
])

Recall

  1. 신경망의 층

  2. 신경망 훈련을 위해 컴파일 단계에 포함될 추가 세 가지

Notes

<컴파일 단계>

model.compile(optimizer = "rmsprop",
							loss = "sparse_categorical_crosentropy",
							metrics = ["accuracy"])
<이미지 데이터 준비하기>

train_images = train_images.reshape((60000, 28 * 28))
train_images = train_images.astype("float32") / 255
test_images = test_images.reshape((10000, 28 * 28))
test_images = test_images.astype("float32") / 255

//[0, 255]사이의 값인 uint8타입에서 [0,1]의 값을 가지는 float32 크기인 배열로 전환

⇒ fit() 메서드 호출하면 훈련 데이터에 모델을 학습시킴

<모델 훈련하기>

model.fit(train_images, train_labels, epochs=5, batch_size=128)
x - 입력 데이터
y - 라벨값
batch_size - 몇 개의 샘플로 가중치를 갱신 할 것인지 지정
epoch - 학습 반복 횟수
(100개의 문제를 batch_size = 10, epochs = 5로 학습하면 10개씩 끊어서 정답을 맞추어 보고 
가중치 갱신을 하며 100개의 문제를 5번 반복 학습 하는 것을 의미한다)
=> epochs가 너무 크면 과대적합(overfitting)이 발생할 수 있음
<모델을 사용하여 예측 만들기>

test_digits = test_images[0:10]
predictions = model.predict(test_digits)
predictions[0]

=>출력된 배열의 인덱스 i에 있는 숫자는 숫자 이미지 test_digits[0]이 클래스 i에 속할 확률에 해당함
<새로운 데이터에서 모델 평가하기>
test_loss, test_acc = model.evaluate(test_images, test_labels)
print(f"테스트 정확도 : {test_acc}")

Date: September 12, 2022

Topic : Data expression for neural network

Recall

  1. 텐서

  2. 랭크 - 0 텐서

  3. 랭크 - 1 텐서

  4. 랭크 - 2 텐서

  5. 랭크 - 3 텐서

  6. 3개의 핵심 속성

  7. 배치 데이터

  8. 텐서의 실제 사례

Notes

<aside> 📌 SUMMARY:

</aside>