# 0. 사용할 패키지 불러오기
from keras.utils import np_utils
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Activation
import numpy as np
from numpy import argmax
import loader3
# 1. 실무에 사용할 데이터 준비하기
test_image = 'c:/data/leafs/images/test_resize/'
test_label = 'c:/data/leafs/images/test_label.csv'
x_test = loader3.image_load(test_image)
y_test = loader3.label_load(test_label)
print ( loader3.image_load(test_image).shape )
print ( loader3.label_load(test_label).shape )
case = 10
x_test = x_test / 255.0
xhat_idx = np.random.choice(x_test.shape[0], case)
print(xhat_idx)
xhat = x_test[xhat_idx]
# 2. 모델 불러오기
from keras.models import load_model
model = load_model("c:/data/leafs/leaf.h5")
# 3. 모델 사용하기
yhat = model.predict_classes(xhat)
for i in range(case):
print('True : ' + str(argmax(y_test[xhat_idx[i]])) + ', Predict : ' + str(yhat[i]))
##################################################################
#전체 데이터 넣고 정확도 확인하는 코드
# 0. 사용할 패키지 불러오기
from keras.utils import np_utils
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Activation
import numpy as np
from numpy import argmax
import loader3
from sklearn.metrics import accuracy_score
# 1. 실무에 사용할 데이터 준비하기
test_image = 'c:/data/leafs/images/test_resize/'
test_label = 'c:/data/leafs/images/test_label.csv'
x_test = loader3.image_load(test_image)
y_test = loader3.label_load(test_label)
print ( loader3.image_load(test_image).shape )
print ( loader3.label_load(test_label).shape )
x_test = x_test / 255.0
xhat_idx = np.random.choice(x_test.shape[0], x_test.shape[0])
xhat = x_test[xhat_idx]
# 2. 모델 불러오기
from keras.models import load_model
model = load_model("c:/data/leafs/leaf.h5")
# 3. 모델 사용하기
yhat = model.predict_classes(xhat)
y_pred = []
for i in range(x_test.shape[0]):
y_pred.append(argmax(y_test[xhat_idx[i]]))
accuracy_score(y_pred, yhat)
# 일부로 섞었는데.... 원치 않으면 코드 변경하세요...
첫댓글 https://goodtogreate.tistory.com/entry/Saving-and-Restoring
https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/models/load_model