File size: 1,866 Bytes
e1007af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de81738
e1007af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import tensorflow
from tensorflow.keras.models import load_model
import numpy as np
from PIL import Image
import pandas as pd
import os

# Load the saved TensorFlow model
model = load_model('traffic-sign-detection-model3.h5')


inputBasePath = 'D:\\traffic_Data\\'
path = 'D:\\traffic_Data\\DATA'
testingFolder = 'D:\\traffic_Data\\TEST'
classes = pd.read_csv('labels.csv')


# Function to preprocess the image
def preprocess_image(image):
    # Preprocess the image as required for your model
    # (e.g., resize, normalize pixel values)
    resized_image = image.resize((100,100))
    preprocessed_image = np.array(resized_image) / 255.0  # Normalize pixel values
    return preprocessed_image

# Function to make predictions
def predict(image):
    preprocessed_image = preprocess_image(image)
    prediction = model.predict(np.expand_dims(preprocessed_image, axis=0))
    return prediction

# Streamlit app
def main():
    st.title('Traffic Sign Detection')

    uploaded_image = st.file_uploader("Upload Image", type=['jpg', 'png', 'jpeg'])

    if uploaded_image is not None:
        # Display the uploaded image
        image = Image.open(uploaded_image)
        st.image(image, caption='Uploaded Image', use_column_width=True)

       # Predict button
        if st.button('Predict'):
            # Make prediction
            prediction = predict(image)
            predicted_class = np.argmax(prediction, axis=1)
            #st.write(predicted_class)
            class_mapping = dict(zip(classes['ClassId'], classes['Name']))
            predicted_label = class_mapping.get(predicted_class[0])
            # st.write(predicted_label)
            # st.write(predicted_class)
            
            # Display prediction result
            
            st.write('Prediction:', predicted_label)

if __name__ == '__main__':
    main()