alperugurcan commited on
Commit
f6ef3ed
·
verified ·
1 Parent(s): c01b9d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -20
app.py CHANGED
@@ -10,23 +10,52 @@ def load_model():
10
 
11
  model = load_model()
12
 
13
- # Class labels
14
- class_names = [
15
- 'Speed limit (20km/h)', 'Speed limit (30km/h)', 'Speed limit (50km/h)',
16
- 'Speed limit (60km/h)', 'Speed limit (70km/h)', 'Speed limit (80km/h)',
17
- 'End of speed limit (80km/h)', 'Speed limit (100km/h)', 'Speed limit (120km/h)',
18
- 'No passing', 'No passing for vehicles over 3.5 metric tons',
19
- 'Right-of-way at the next intersection', 'Priority road', 'Yield', 'Stop',
20
- 'No vehicles', 'Vehicles over 3.5 metric tons prohibited', 'No entry',
21
- 'General caution', 'Dangerous curve to the left', 'Dangerous curve to the right',
22
- 'Double curve', 'Bumpy road', 'Slippery road', 'Road narrows on the right',
23
- 'Road work', 'Traffic signals', 'Pedestrians', 'Children crossing',
24
- 'Bicycles crossing', 'Beware of ice/snow', 'Wild animals crossing',
25
- 'End of all speed and passing limits', 'Turn right ahead', 'Turn left ahead',
26
- 'Ahead only', 'Go straight or right', 'Go straight or left', 'Keep right',
27
- 'Keep left', 'Roundabout mandatory', 'End of no passing',
28
- 'End of no passing by vehicles over 3.5 metric tons'
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 = np.expand_dims(image, axis=0)
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: {class_names[predicted_class]}")
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 30x30 pixels and similar to those used in the training dataset.")
 
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.")