인공지능
[인공지능] 케라스 기초 - 모델 저장과 복원
범범조조
2022. 2. 16. 18:50
참조
모델 저장과 복원
- save()
- load_model()
- Sequential API, Functional API 에서는 모델의 저장 및 로드가 가능하지만 Subclassing 방식으로는 할 수 없음
- Subclassing 방식
save_weights()
load_weights()
- 위 두가지를 통해 모델의 파라미터만 저장 및 로드
- JSON 형식
- model.to_json()
- tf.keras.models.model_from_json(file_path)
- YAML로 직렬화
- model.to_yaml()
- tf.keras.models.model_from_yaml(file_path)
# 모델 저장
model.save('mnist_model.h5')
loaded_model = models.load_model('mnist_model.h5')
loaded_model.summary()
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
flatten (Flatten) (None, 784) 0
dense1 (Dense) (None, 100) 78500
dense2 (Dense) (None, 64) 6464
dense3 (Dense) (None, 32) 2080
output (Dense) (None, 10) 330
=================================================================
Total params: 87,374
Trainable params: 87,374
Non-trainable params: 0
728x90