-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_evaluation.py
105 lines (85 loc) · 2.97 KB
/
test_evaluation.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from keras.models import model_from_json
from keras.preprocessing import image
import numpy as np
import cv2
from main import *
def predict_side_mirror(img_path):
# Loading the model
json_file = open("Models/Mirror_Model.json", "r")
model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(model_json)
# load weights into new model
loaded_model.load_weights("Models/Mirror_Model.h5")
print("Loaded model from disk")
img = image.load_img(img_path, target_size=(224, 224))
img_tensor = image.img_to_array(img)
img_tensor = np.expand_dims(img_tensor, axis=0)
img_tensor /= 255.
pred = loaded_model.predict(img_tensor)
if pred[0][0] > pred[0][1]:
return "Damaged"
else:
return "Undamaged"
print(result)
# def predict_headlights(image_path):
# # Loading the model
# json_file = open("/content/drive/My Drive/GOVT_HACK/Models/Headlights_Model.json", "r")
# model_json = json_file.read()
# json_file.close()
# loaded_model = model_from_json(model_json)
# # load weights into new model
# loaded_model.load_weights("/content/drive/My Drive/GOVT_HACK/Models/Headlights_Model.h5")
# print("Loaded model from disk")
# img = image.load_img(img_path, target_size=(224, 224))
# img_tensor = image.img_to_array(img)
# img_tensor = np.expand_dims(img_tensor, axis=0)
# img_tensor /= 255.
# pred = loaded_model.predict(img_tensor)
# if pred[0][0]>pred[0][1]:
# return "damaged"
# else:
# return "undamaged"
def predict_windscreen(img_path):
# Loading the model
json_file = open("Models/Windscreen_Model.json", "r")
model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(model_json)
# load weights into new model
loaded_model.load_weights("Models/Windscreen_Model.h5")
print("Loaded model from disk")
img = image.load_img(img_path, target_size=(224, 224))
img_tensor = image.img_to_array(img)
img_tensor = np.expand_dims(img_tensor, axis=0)
img_tensor /= 255.
pred = loaded_model.predict(img_tensor)
if pred[0][0] > pred[0][1]:
return "Damaged"
else:
return "Undamaged"
def predict_damage(img_path):
# Loading the model
json_file = open("Models/Damage_or_Undamaged_Model.json", "r")
model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(model_json)
# load weights into new model
loaded_model.load_weights("Models/Damage_or_Undamaged_Model.h5")
print("Loaded model from disk")
img = image.load_img(img_path, target_size=(224, 224))
img_tensor = image.img_to_array(img)
img_tensor = np.expand_dims(img_tensor, axis=0)
img_tensor /= 255.
pred = loaded_model.predict(img_tensor)
print(pred)
if pred[0][0] > pred[0][1]:
return "Damaged"
else:
return "Undamaged"
def generate_result():
return result
#x=predict_windscreen("Testing/k.jpg")
#y=predict_side_mirror("Testing/c.jpg")
#print(x)
#print(y)