전체 글 (17)
생성된 모델로 테스트하기

#생성된 모델로 테스트하기
import os, re, glob 
import cv2  #openCV 라이브러리 import하기
import numpy as np 
import shutil 
from numpy import argmax 
from keras.models import load_model 
 

#분류할 카테고리 지정
categories = ["road", "water", "building", "green"] 
  
def Dataization(img_path): 
    image_w = 28 
    image_h = 28 
    img = cv2.imread(img_path) 
    img = cv2.resize(img, None, fx=image_w/img.shape[1], fy=image_h/img.shape[0]) 
    return (img/256) 
  
src = [] 
name = [] 
test = [] 
image_dir = "./testData/test/building/" #테스트할 이미지 폴더 경로

for file in os.listdir(image_dir): 
    if (file.find('.jpg') is not -1):       
        src.append(image_dir + file) 
        name.append(file) 
        test.append(Dataization(image_dir + file)) 
  
  
test = np.array(test) 
model = load_model('cnnModel_100.h5'#사용할 모델 불러오기
predict = model.predict_classes(test) 
  
for i in range(len(test)): 
    print(name[i] + " : "+ str(categories[predict[i]]))

  Comments,     Trackbacks
최근 작성 글
최근 작성 댓글
최근 작성 트랙백
프로필
공지사항
글 보관함
캘린더
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
TODAY TOTAL