-
Notifications
You must be signed in to change notification settings - Fork 30
/
Predictor.py
74 lines (52 loc) · 2.44 KB
/
Predictor.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import numpy as np
import cv2
import glob
from keras.models import Sequential
from keras.models import load_model
from sklearn.preprocessing import LabelBinarizer
from sklearn.model_selection import train_test_split
from keras.utils import np_utils
global size
size = 100
model = Sequential()
model = load_model('C:/Users/anant/Desktop/Pothole Detection using Machine Learning/Pothole Detection using Machine Learning/sample.h5')
# X_test = np.load('./models/trainData/128x72x3x10000/X_test.npy')
# y_test = np.load('./models/trainData/128x72x3x10000/y_test.npy')
## load Testing data : non-pothole
nonPotholeTestImages = glob.glob("C:/Users/anant/Desktop/pothole-and-plain-rode-images/My Dataset/test/Plain/*.jpg")
# nonPotholeTrainImages.extend(glob.glob("C:/Users/anant/Desktop/pothole-and-plain-rode-images/My Dataset/train/Plain/*.jpeg"))
# nonPotholeTrainImages.extend(glob.glob("C:/Users/anant/Desktop/pothole-and-plain-rode-images/My Dataset/train/Plain/*.png"))
test2 = [cv2.imread(img,0) for img in nonPotholeTestImages]
# train2[train2 != np.array(None)]
for i in range(0,len(test2)):
test2[i] = cv2.resize(test2[i],(size,size))
temp4 = np.asarray(test2)
## load Testing data : potholes
potholeTestImages = glob.glob("C:/Users/anant/Desktop/pothole-and-plain-rode-images/My Dataset/test/Pothole/*.jpg")
# nonPotholeTrainImages.extend(glob.glob("C:/Users/anant/Desktop/pothole-and-plain-rode-images/My Dataset/train/Plain/*.jpeg"))
# nonPotholeTrainImages.extend(glob.glob("C:/Users/anant/Desktop/pothole-and-plain-rode-images/My Dataset/train/Plain/*.png"))
test1 = [cv2.imread(img,0) for img in potholeTestImages]
# train2[train2 != np.array(None)]
for i in range(0,len(test1)):
test1[i] = cv2.resize(test1[i],(size,size))
temp3 = np.asarray(test1)
X_test = []
X_test.extend(temp3)
X_test.extend(temp4)
X_test = np.asarray(X_test)
X_test = X_test.reshape(X_test.shape[0], size, size, 1)
y_test1 = np.ones([temp3.shape[0]],dtype = int)
y_test2 = np.zeros([temp4.shape[0]],dtype = int)
y_test = []
y_test.extend(y_test1)
y_test.extend(y_test2)
y_test = np.asarray(y_test)
y_test = np_utils.to_categorical(y_test)
tests = model.predict_classes(X_test)
for i in range(len(X_test)):
print(">>> Predicted=%s" % (tests[i]))
# metrics = model.evaluate(X_test, y_test)
# for metric_i in range(len(model.metrics_names)):
# metric_name = model.metrics_names[metric_i]
# metric_value = metrics[metric_i]
# print('{}: {}'.format(metric_name, metric_value))