본문 바로가기
Python Library/Keras

[Keras] 학습

by goatlab 2021. 12. 20.
728x90
반응형
SMALL

학습

 

keras model들은 입력 데이터와 label로 구성된 Numpy 배열 위에서 이루어진다. model을 학습기키기 위해서는 일반적으로 fit함수를 사용한다. (https://keras.io/api/models/sequential/)

 

 

여기서 리턴 값으로 학습 이력 (History) 정보를 return한다. 여기에는 loss, acc, val_loss, val_acc 값과 매 epoch 마다 각기 다른 값들이 저장되어 있다. 

 

◦ loss : 훈련 손실값
◦ acc : 훈련 정확도
◦ val_loss : 검증 손실값
◦ val_acc : 검증 정확도
# For a single-input model with 2 classes (binary classification):

model = Sequential()
model.add(Dense(32, activation='relu', input_dim=100))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop',
              loss='binary_crossentropy',
              metrics=['accuracy'])

# Generate dummy data
import numpy as np
data = np.random.random((1000, 100))
labels = np.random.randint(2, size=(1000, 1))

# Train the model, iterating on the data in batches of 32 samples
model.fit(data, labels, epochs=10, batch_size=32)
# For a single-input model with 10 classes (categorical classification):

model = Sequential()
model.add(Dense(32, activation='relu', input_dim=100))
model.add(Dense(10, activation='softmax'))
model.compile(optimizer='rmsprop',
              loss='categorical_crossentropy',
              metrics=['accuracy'])

# Generate dummy data
import numpy as np
data = np.random.random((1000, 100))
labels = np.random.randint(10, size=(1000, 1))

# Convert labels to categorical one-hot encoding
one_hot_labels = keras.utils.to_categorical(labels, num_classes=10)

# Train the model, iterating on the data in batches of 32 samples
model.fit(data, one_hot_labels, epochs=10, batch_size=32)

 

https://keras.io/ko/getting-started/sequential-model-guide/

 

Guide to the Sequential model - Keras Documentation

케라스 Sequential 모델 시작하기 Sequential 모델은 레이어를 선형으로 연결하여 구성합니다. 레이어 인스턴스를 생성자에게 넘겨줌으로써 Sequential 모델을 구성할 수 있습니다. from keras.models import Seq

keras.io

 

728x90
반응형
LIST

'Python Library > Keras' 카테고리의 다른 글

[Keras] model / weight 저장 및 불러오기  (0) 2021.12.21
[Keras] 손실 함수 (Loss Function)  (0) 2021.12.20
[Keras] 컴파일 (Compile)  (0) 2021.12.20
[Keras] Sequential 모델  (0) 2021.12.20
케라스 (Keras)  (0) 2021.12.20