새로 주피터 노트북 만들고 이름은 cnn_test
from PIL import Image
import os, glob, numpy as np
from keras.models import load_model
import tensorflow as tf
seed = 5
# tf.set_random_seed(seed)
tf.random.set_seed(seed) # tensorflow2.2 이상
np.random.seed(seed)
caltech_dir = './dogscats/dogscats/valid' # 사진있는 경로
image_w = 64
image_h = 64
pixels = image_h * image_w * 3
X = []
filenames = []
files = glob.glob(caltech_dir+"/*/*.*")
for i, f in enumerate(files):
img = Image.open(f)
img = img.convert("RGB")
img = img.resize((image_w, image_h))
data = np.asarray(img)
filenames.append(f)
X.append(data)
X = np.array(X)
X = X.astype(float) / 255 # 문제만 있음, y가 존재하지 않음
model = load_model('./model/dog_cat_classify.model') # 학습 끝난 model 불러오기
prediction = model.predict(X) # 예측하기
np.set_printoptions(formatter={'float': lambda x: "{0:0.3f}".format(x)})
cnt = 0
for i in prediction: # 예측값을 봤는데 0.5 이상이면 개, 0.5 미만이면 고양이
if i >= 0.5: print("해당 " + filenames[cnt].split("\\\\")[1] + filenames[cnt].split("\\\\")[2] + " 이미지는 개 로 추정됩니다.")
else : print("해당 " + filenames[cnt].split("\\\\")[1] + filenames[cnt].split("\\\\")[2] + " 이미지는 고양이 으로 추정됩니다.")
cnt += 1
face → 사람얼굴 사진
mask → 마스크 쓴 사진
→ 지금 이 모델을 가지고 활용하면 마스크를 슨 것인지 안쓴 것인지 판별 가능