Senasu commited on
Commit
53fac79
·
verified ·
1 Parent(s): 400384f

Upload main files

Browse files
Files changed (3) hide show
  1. app.py +43 -0
  2. cnn_model.h5 +3 -0
  3. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from tensorflow.keras.models import load_model
3
+ from PIL import Image
4
+ import numpy as np
5
+ import matplotlib.pyplot as plt
6
+ import seaborn as sns
7
+
8
+ model = load_model('cnn_model.h5')
9
+
10
+ def process_image(img):
11
+ img = img.convert('RGB')
12
+ img = img.resize((32, 32))
13
+ img = np.array(img)
14
+ img = img / 255.0
15
+ img = np.expand_dims(img, axis=0)
16
+ return img
17
+
18
+ st.title('German Traffic Signs Detection :vertical_traffic_light:')
19
+ st.write('Upload a traffic sign image and the model will detect it.')
20
+
21
+ file = st.file_uploader('Select an image', type=['jpg', 'jpeg', 'png'])
22
+
23
+ if file is not None:
24
+ # Display the uploaded image
25
+ img = Image.open(file)
26
+ st.image(img, caption='Uploaded Image')
27
+
28
+ # Preprocess the image
29
+ image = process_image(img)
30
+
31
+ # Model prediction
32
+ with st.spinner('Classifying the image...'):
33
+ predictions = model.predict(image)
34
+ predicted_class = np.argmax(predictions)
35
+ predicted_prob = predictions[0][predicted_class]
36
+
37
+ # Class names for prediction
38
+ class_names = ['Speed Limit 20', 'Speed Limit 30', 'Speed Limit 50', 'Speed Limit 60', 'Speed Limit 70', 'Speed Limit 80', 'End of a Speed Limit 80', 'Speed Limit 100', 'Speed Limit 120', 'Speed Limit 100', 'No overtaking by trucks', 'Crossroads', 'Priority Road', 'Give way', 'Stop', 'All vehicles prohibited in both directions', 'No trucks', 'No Entry', 'Other Hazards', 'Curve to left', 'Curve to right', 'Double curve, first to the left', 'Uneven Road', 'Slippery Road', 'Road Narrows Near Side', 'Roadworks', 'Traffic lights', 'No pedestrians', 'Children', 'Cycle Route', 'Be careful in winter', 'Wild animals', 'No parking', 'Turn right ahead', 'Turn left ahead', 'Ahead Only', 'Proceed straight or turn right', 'Proceed straight or turn left', 'Pass onto right', 'Pass onto left', 'Roundabout', 'No overtaking', 'End of Truck Overtaking Prohibition']
39
+
40
+ # Display the prediction
41
+ st.subheader(f"Prediction: {class_names[predicted_class]}")
42
+ st.write(f"Confidence: {predicted_prob * 100:.2f}%")
43
+
cnn_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b90c9953e8c250475b22f7734bb6c8b538d89e30dcec9191a0a19ccbff007788
3
+ size 96373128
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ tensorflow