-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestWithImages.py
More file actions
52 lines (39 loc) · 1.08 KB
/
TestWithImages.py
File metadata and controls
52 lines (39 loc) · 1.08 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
from keras.models import load_model
import numpy as np
import cv2
import os
#model loaded
model = load_model('fire_detection_model.h5')
print("Model Loaded Successfully")
#preprocess the camera image
def preProcessing(img):
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.equalizeHist(img)
img = img / 255
return img
def classify(img_file):
print(img_file)
img_name = img_file
test_image=cv2.imread(img_name)
img = np.asarray(test_image)
img = cv2.resize(img, (32, 32))
img = preProcessing(img)
# cv2.imshow("Processsed Image", img)
img = img.reshape(1, 32, 32, 1)
# predicting
classIndex = int(model.predict_classes(img))
predictions = model.predict(img)
probVal = np.amax(predictions)
if classIndex==0:
print("Fire + Probability : "+str(probVal))
else:
print("No Fire + Probability : "+str(probVal))
path = 'Testing'
files = []
# r=root, d=directories, f = files
for r, d, f in os.walk(path):
for file in f:
files.append(os.path.join(r, file))
for f in files:
classify(f)
print('\n')