■ 학습 모델 로드하기

----------------------------------------------------------------------------------------------------


model.data


import keras.datasets.mnist as mnist

import keras.models as models

import keras.utils as utils

import numpy as np

 

# 데이터를 로드한다.

(trainInputNDArray, trainCorrectOutputNDArray), (testInputNDArray, testCorrectOutputNDArray) = mnist.load_data()

 

testInputNDArray         = testInputNDArray.reshape(10000, 784).astype("float32") / 255.0

testCorrectOutputNDArray = utils.np_utils.to_categorical(testCorrectOutputNDArray)

 

testRandomIndexNDArray = np.random.choice(testInputNDArray.shape[0], 5)

testInputNDArray       = testInputNDArray[testRandomIndexNDArray]

 

# 모델 데이터를 로드한다.

model = models.load_model("model.data")

 

# 모델을 사용한다.

testOutputNDArray = model.predict_classes(testInputNDArray)

 

for i in range(5):

    print("정답 : " + str(np.argmax(testCorrectOutputNDArray[testRandomIndexNDArray[i]])) + ", 예측 : " +\

        str(testOutputNDArray[i]))

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker