-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWepDetTest.py
More file actions
97 lines (77 loc) · 2.34 KB
/
WepDetTest.py
File metadata and controls
97 lines (77 loc) · 2.34 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Ignore the warnings
import warnings
warnings.filterwarnings('always')
warnings.filterwarnings('ignore')
# data visualisation and manipulation
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import style
import seaborn as sns
import tensorflow as tf
from sklearn.model_selection import train_test_split
import random as rn
from tqdm import tqdm
import os
import cv2
from keras import models
from sklearn.preprocessing import LabelEncoder
from keras.utils import to_categorical
model = models.load_model('/home/mitchell/Desktop/WeaponDetection/WepDet_26_50.h5')
X=[]
Z=[]
IMG_SIZE=150
DATA_GUN_DIR='/home/mitchell/Desktop/WeaponDetection/dataset/test_set/gun'
DATA_NONGUN_DIR='/home/mitchell/Desktop/WeaponDetection/dataset/test_set/nogun'
def assign_label(img,img_type):
return img_type
def make_test_data(img_type,DIR):
for img in tqdm(os.listdir(DIR)):
#print(img)
if not img.startswith('.'):
label=assign_label(img,img_type)
path = os.path.join(DIR,img)
img = cv2.imread(path,cv2.IMREAD_COLOR)
img = cv2.resize(img, (IMG_SIZE,IMG_SIZE))
X.append(np.array(img))
Z.append(str(label))
make_test_data('Gun',DATA_GUN_DIR)
print(len(X))
make_test_data('nogun',DATA_NONGUN_DIR)
print(len(X))
#fig,ax=plt.subplots(5,2)
#fig.set_size_inches(15,15)
#for i in range(5):
# for j in range (2):
# l=rn.randint(0,len(Z))
# # Had index oob error here once
# ax[i,j].imshow(X[l])
# ax[i,j].set_title('Gun: '+Z[l])
plt.tight_layout()
le=LabelEncoder()
Y=le.fit_transform(Z)
Y=to_categorical(Y,2)
X=np.array(X)
X=X/255
evaluation = model.evaluate(X,Y)
print('Loss: ',evaluation[0])
print('Accuracy: ',evaluation[1])
#for layer in model.layers:
# print(layer.input_shape)
#print(model.summary())
#x_train,x_test,y_train,y_test=train_test_split(X,Y,test_size=0.25,random_state=42)
# getting predictions on val set.
#pred=model.predict(x_test)
#pred_digits=np.argmax(pred,axis=1)
# now storing some properly as well as misclassified indexes'.
#i=0
#prop_class=[]
#mis_class=[]
#
#for i in range(len(y_test)):
# if(np.argmax(y_test[i])==pred_digits[i]):
# prop_class.append(i)
# else:
# mis_class.append(i)
# if(len(prop_class)==8 or len(mis_class) == 8):
# break