Update app.py
Browse files
app.py
CHANGED
|
@@ -10,23 +10,52 @@ def load_model():
|
|
| 10 |
|
| 11 |
model = load_model()
|
| 12 |
|
| 13 |
-
# Class
|
| 14 |
-
|
| 15 |
-
'Speed limit (20km/h)',
|
| 16 |
-
'Speed limit (
|
| 17 |
-
'
|
| 18 |
-
'
|
| 19 |
-
'
|
| 20 |
-
|
| 21 |
-
'
|
| 22 |
-
'
|
| 23 |
-
'
|
| 24 |
-
'
|
| 25 |
-
'
|
| 26 |
-
'
|
| 27 |
-
'
|
| 28 |
-
'
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
st.title('Traffic Sign Classifier')
|
| 32 |
|
|
@@ -38,14 +67,16 @@ if uploaded_file is not None:
|
|
| 38 |
|
| 39 |
# Preprocess the image
|
| 40 |
image = image.resize((30, 30))
|
| 41 |
-
image =
|
| 42 |
image = np.array(image)
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Make prediction
|
| 45 |
pred = model.predict(image)
|
| 46 |
predicted_class = np.argmax(pred, axis=-1)[0]
|
| 47 |
|
| 48 |
-
st.write(f"Predicted traffic sign: {
|
| 49 |
st.write(f"Confidence: {pred[0][predicted_class]*100:.2f}%")
|
| 50 |
|
| 51 |
-
st.write("Note: This application uses a pre-trained model. For best results, upload images that are
|
|
|
|
| 10 |
|
| 11 |
model = load_model()
|
| 12 |
|
| 13 |
+
# Class names
|
| 14 |
+
classes = {
|
| 15 |
+
0:'Speed limit (20km/h)',
|
| 16 |
+
1:'Speed limit (30km/h)',
|
| 17 |
+
2:'Speed limit (50km/h)',
|
| 18 |
+
3:'Speed limit (60km/h)',
|
| 19 |
+
4:'Speed limit (70km/h)',
|
| 20 |
+
5:'Speed limit (80km/h)',
|
| 21 |
+
6:'End of speed limit (80km/h)',
|
| 22 |
+
7:'Speed limit (100km/h)',
|
| 23 |
+
8:'Speed limit (120km/h)',
|
| 24 |
+
9:'No passing',
|
| 25 |
+
10:'No passing veh over 3.5 tons',
|
| 26 |
+
11:'Right-of-way at intersection',
|
| 27 |
+
12:'Priority road',
|
| 28 |
+
13:'Yield',
|
| 29 |
+
14:'Stop',
|
| 30 |
+
15:'No vehicles',
|
| 31 |
+
16:'Vehicle > 3.5 tons prohibited',
|
| 32 |
+
17:'No entry',
|
| 33 |
+
18:'General caution',
|
| 34 |
+
19:'Dangerous curve left',
|
| 35 |
+
20:'Dangerous curve right',
|
| 36 |
+
21:'Double curve',
|
| 37 |
+
22:'Bumpy road',
|
| 38 |
+
23:'Slippery road',
|
| 39 |
+
24:'Road narrows on the right',
|
| 40 |
+
25:'Road work',
|
| 41 |
+
26:'Traffic signals',
|
| 42 |
+
27:'Pedestrians',
|
| 43 |
+
28:'Children crossing',
|
| 44 |
+
29:'Bicycles crossing',
|
| 45 |
+
30:'Beware of ice/snow',
|
| 46 |
+
31:'Wild animals crossing',
|
| 47 |
+
32:'End speed + passing limits',
|
| 48 |
+
33:'Turn right ahead',
|
| 49 |
+
34:'Turn left ahead',
|
| 50 |
+
35:'Ahead only',
|
| 51 |
+
36:'Go straight or right',
|
| 52 |
+
37:'Go straight or left',
|
| 53 |
+
38:'Keep right',
|
| 54 |
+
39:'Keep left',
|
| 55 |
+
40:'Roundabout mandatory',
|
| 56 |
+
41:'End of no passing',
|
| 57 |
+
42:'End no passing vehicle > 3.5 tons'
|
| 58 |
+
}
|
| 59 |
|
| 60 |
st.title('Traffic Sign Classifier')
|
| 61 |
|
|
|
|
| 67 |
|
| 68 |
# Preprocess the image
|
| 69 |
image = image.resize((30, 30))
|
| 70 |
+
image = image.convert('RGB') # Convert to RGB
|
| 71 |
image = np.array(image)
|
| 72 |
+
image = image / 255.0 # Normalize pixel values
|
| 73 |
+
image = np.expand_dims(image, axis=0)
|
| 74 |
|
| 75 |
# Make prediction
|
| 76 |
pred = model.predict(image)
|
| 77 |
predicted_class = np.argmax(pred, axis=-1)[0]
|
| 78 |
|
| 79 |
+
st.write(f"Predicted traffic sign: {classes[predicted_class]}")
|
| 80 |
st.write(f"Confidence: {pred[0][predicted_class]*100:.2f}%")
|
| 81 |
|
| 82 |
+
st.write("Note: This application uses a pre-trained model. For best results, upload images that are similar to those used in the training dataset.")
|