-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincorrectCount2.py
50 lines (40 loc) · 1.39 KB
/
incorrectCount2.py
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
44
45
46
47
48
49
50
import pickle
import os
import numpy as np
import json
from keras.models import load_model
from tqdm import tqdm
def confidence(item):
return item['confidence']
def countIncorrect(model, lb, image_list, label_list):
result = model.predict(image_list)
count = {}
for clss in lb.classes_:
count[clss] = 0
for i in tqdm(range(len(result))):
proba = result[i]
proba = list(proba)
for j in range(len(proba)):
proba[j] = {
'label': j,
'confidence': proba[j]
}
proba.sort(key=confidence, reverse=True)
correctClass = lb.inverse_transform(np.expand_dims(label_list[i], axis=0))[0]
if lb.classes_[proba[0]['label']] != correctClass:
count[correctClass] += 1
return count
def main():
labelbin_path = './labelbin/labelbin'
model_path = './model/model'
lb = pickle.loads(open(labelbin_path, 'rb').read())
model = load_model(model_path)
data = np.load('train_data.npy', allow_pickle=True)
image_list = np.array(list(data[:,0])) # .reshape(-1, IMG_DIMS[0], IMG_DIMS[1], IMG_DIMS[2])
class_list = np.array(list(data[:,1]))
label_list = lb.transform(class_list)
count = countIncorrect(model, lb, image_list, label_list)
with open('./incorrectCount.json', 'w') as f:
json.dump(count, f, indent=2)
if __name__ == "__main__":
main()