File size: 1,201 Bytes
62844d7
 
 
 
 
 
 
d99c180
 
62844d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1eb9f1
62844d7
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
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))}")
"""