라벨이 keras인 게시물 표시

[keras] model save & load 하는 방법

이미지
모델 저장하기 Weights + Model Architecture 각각 저장하는 방법 # Save the weights model.save_weights( "mnist_weights.h5" ) # Save the model architecture as json with open ( "mnist_architecture.json" , "w" ) as fp:   fp.write(model.to_json( indent = " \t " )) model.save_weights(filepath) Notes 모델의 가중치 값을 HDF5 파일 형식으로 저장합니다. model.to_json() Notes model architecture만 json 형태로 저장합니다. 가중치는 저장하지 않습니다. json에서 indent="\t"가 궁금하신 분은 https://daewoonginfo.blogspot.com/2019/04/python-json.html 참조해주시기 바랍니다. Weights + Model Architecture + Optimizer State 한번에 저장하는 방법 # Creates a single HDF5 file model.save( "mnist_model.h5" ) model.save(filepath) Notes 모델의 Weights, Architecture, Optimizer State를 모두 포함하는 HDF5 파일 형식으로 저장합니다. 모델 불러오기 Weights + Model Architecture 각각 불러오는 방법 from keras.models import model_from_json # Reconfigure model in json file with open ( "mnist_architecture...

[keras] ANN mnist 만들기

이미지
mnist같은 경우 여러 신경망 모델을 구성할 수 있습니다. (ANN, CNN 등) 모든 경우를 다룰 수 없어 이번 예제에서는 keras model의 Sequential을 이용하여 ANN을 구성하겠습니다. 손글씨 분류 학습하기 데이터 로드 import keras from keras import datasets import  numpy  as  np (x_train_raw , y_train_raw) , (x_test_raw , y_test_raw) = datasets.mnist.load_data()  print ( "x_train_raw.shape = {0}" .format(x_train_raw.shape)) print ( "x_test_raw.shape = {0}" .format(x_test_raw.shape)) print ( "y_train_raw.shape = {0}" .format(y_train_raw.shape)) print ( "y_test_raw.shape = {0}" .format(y_test_raw.shape)) # 출력 # x_train_raw.shape = (60000, 28, 28) # x_test_raw.shape = (10000, 28, 28) # y_train_raw.shape = (60000,) # y_test_raw.shape = (10000,) datasets.mnist.load_data() keras에서 제공하는 datasets중 mnist라는 데이터 셋을 불러옵니다. x_train_raw, x_test_raw로 28x28 사이즈의 grayscale 이미지를 불러옵니다. y_train_raw, y_test_raw로 0-9 사이의 수를 불러옵니다. x, y train은 각 6만개(num_samples), x, y test는 각 만개(num_sa...