-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.py
110 lines (102 loc) · 3.73 KB
/
App.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
106
107
108
109
110
from flask import *
import os
from werkzeug.utils import secure_filename
from keras.models import load_model
import numpy as np
from PIL import Image
app = Flask(__name__)
# Classes of trafic signs
classes = { 0:'Speed limit (20km/h)',
1:'Speed limit (30km/h)',
2:'Speed limit (50km/h)',
3:'Speed limit (60km/h)',
4:'Speed limit (70km/h)',
5:'Speed limit (80km/h)',
6:'End of speed limit (80km/h)',
7:'Speed limit (100km/h)',
8:'Speed limit (120km/h)',
9:'No passing',
10:'No passing veh over 3.5 tons',
11:'Right-of-way at intersection',
12:'Priority road',
13:'Yield',
14:'Stop',
15:'No vehicles',
16:'Vehicle > 3.5 tons prohibited',
17:'No entry',
18:'General caution',
19:'Dangerous curve left',
20:'Dangerous curve right',
21:'Double curve',
22:'Bumpy road',
23:'Slippery road',
24:'Road narrows on the right',
25:'Road work',
26:'Traffic signals',
27:'Pedestrians',
28:'Children crossing',
29:'Bicycles crossing',
30:'Beware of ice/snow',
31:'Wild animals crossing',
32:'End speed + passing limits',
33:'Turn right ahead',
34:'Turn left ahead',
35:'Ahead only',
36:'Go straight or right',
37:'Go straight or left',
38:'Keep right',
39:'Keep left',
40:'Roundabout mandatory',
41:'End of no passing',
42:'End no passing vehicle > 3.5 tons' }
def image_processing(img):
model = load_model('./model/TSR.h5')
data=[]
image = Image.open(img)
image = image.resize((30,30))
data.append(np.array(image))
X_test=np.array(data)
predict_x=model.predict(X_test)
classes_x=np.argmax(predict_x,axis=1)
#Y_pred = model.predict_classes(X_test)
#return Y_pred
return classes_x
@app.route('/')
def index():
return render_template('index.html')
@app.route('/predict', methods=['GET', 'POST'])
def upload():
if request.method == 'POST':
# Get the file from post request
f = request.files['file']
file_path = secure_filename(f.filename)
f.save(file_path)
#Get the car speed from user
# speed =request.text('text')
# Make prediction
result = image_processing(file_path)
s = [str(i) for i in result]
a = int("".join(s))
if classes[a] == "Speed limit (20km/h)":
result = "Maintain or lower the speed"
elif classes[a] == "Speed limit (30km/h)":
result = "you can maintain or increase the speed up to 30km/h"
elif classes[a] == "Speed limit (50km/h)":
result = "You can maintain the speed or increase up to 50km/h"
elif classes[a] == "Speed limit (60km/h)":
result = "You can maintain the speed or increase up to 60km/h"
elif classes[a] == "Speed limit (70km/h)":
result = "You can maintain the speed or increase up to 70km/h"
elif classes[a] == "Speed limit (80km/h)":
result = "You can maintain the speed or increase up to 80km/h"
elif classes[a] == "Speed limit (100km/h)":
result = "You can maintain the speed or increase up to 100km/h"
elif classes[a] == "Speed limit (120km/h)":
result = "You can maintain the speed or increase up to 120km/h"
else:
result = "Your Traffic🚦Sign is: " +classes[a]
print(result)
return result
return None
if __name__ == '__main__':
app.run(debug=True)