import numpy as np import cv2 import keras import os import matplotlib.pyplot as plt import time # bald_path = "/home/julien/Downloads/archive (1)/Dataset/Test/Bald" # notbald_path = "/home/julien/Downloads/archive (1)/Dataset/Test/NotBald" def predict(im): # im_names = os.listdirpath) im_names= [im] ims = np.zeros((len(im_names), 64, 64, 3)) for i, f in enumerate(im_names): # img = cv2.imread(os.path.join(path, f)) # img = im img = cv2.imread(f) data = cv2.resize(img, (64, 64)) data = cv2.cvtColor(data, cv2.COLOR_BGR2RGB) ims[i] = np.reshape(data, (1, 64, 64, 3)) / 255.0 print(ims.shape) res = model.predict(ims) """ for i in range(len(im_names)): print('[没秃]' if res[i][0] <0.3 else '[秃了]', 'Bald:',res[i][0]) """ return res model = keras.models.load_model('models/bald_classifity.h5') """ bald_res = predict(bald_path) notbald_res = predict(notbald_path) print(notbald_res.shape) print(notbald_res[:,0]) print(f"Bald mean : {np.mean(bald_res[:, 0])}") print(f"Not Bald mean : {np.mean(notbald_res[:, 0])}") print(bald_res[:, 0]>0.3) print(f"Accuracy : {(np.sum(bald_res[:, 0]>0.3) + np.sum(notbald_res[:, 0]<0.3))/(len(bald_res)+len(notbald_res))}") """