Spaces:
Build error
Build error
PRASHANTH REDDY
commited on
Commit
·
d0be1a5
1
Parent(s):
f5277a5
Add application file and requirements
Browse files- app.py +75 -0
- requirements.txt +6 -0
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
from keras.models import load_model
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import tensorflow as tf
|
| 6 |
+
import cv2
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
classes = { 0:'Speed limit (20km/h)',
|
| 10 |
+
1:'Speed limit (30km/h)',
|
| 11 |
+
2:'Speed limit (50km/h)',
|
| 12 |
+
3:'Speed limit (60km/h)',
|
| 13 |
+
4:'Speed limit (70km/h)',
|
| 14 |
+
5:'Speed limit (80km/h)',
|
| 15 |
+
6:'End of speed limit (80km/h)',
|
| 16 |
+
7:'Speed limit (100km/h)',
|
| 17 |
+
8:'Speed limit (120km/h)',
|
| 18 |
+
9:'No passing',
|
| 19 |
+
10:'No passing veh over 3.5 tons',
|
| 20 |
+
11:'Right-of-way at intersection',
|
| 21 |
+
12:'Priority road',
|
| 22 |
+
13:'Yield',
|
| 23 |
+
14:'Stop',
|
| 24 |
+
15:'No vehicles',
|
| 25 |
+
16:'Vehicle > 3.5 tons prohibited',
|
| 26 |
+
17:'No entry',
|
| 27 |
+
18:'General caution',
|
| 28 |
+
19:'Dangerous curve left',
|
| 29 |
+
20:'Dangerous curve right',
|
| 30 |
+
21:'Double curve',
|
| 31 |
+
22:'Bumpy road',
|
| 32 |
+
23:'Slippery road',
|
| 33 |
+
24:'Road narrows on the right',
|
| 34 |
+
25:'Road work',
|
| 35 |
+
26:'Traffic signals',
|
| 36 |
+
27:'Pedestrians',
|
| 37 |
+
28:'Children crossing',
|
| 38 |
+
29:'Bicycles crossing',
|
| 39 |
+
30:'Beware of ice/snow',
|
| 40 |
+
31:'Wild animals crossing',
|
| 41 |
+
32:'End speed + passing limits',
|
| 42 |
+
33:'Turn right ahead',
|
| 43 |
+
34:'Turn left ahead',
|
| 44 |
+
35:'Ahead only',
|
| 45 |
+
36:'Go straight or right',
|
| 46 |
+
37:'Go straight or left',
|
| 47 |
+
38:'Keep right',
|
| 48 |
+
39:'Keep left',
|
| 49 |
+
40:'Roundabout mandatory',
|
| 50 |
+
41:'End of no passing',
|
| 51 |
+
42:'End no passing vehicle > 3.5 tons' }
|
| 52 |
+
def image_processing(img):
|
| 53 |
+
model = load_model('TSR.h5')
|
| 54 |
+
image = Image.open(img)
|
| 55 |
+
image = image.resize((30,30))
|
| 56 |
+
image = np.expand_dims(image, axis=0)
|
| 57 |
+
image = np.array(image)
|
| 58 |
+
predict_x=model.predict(image)
|
| 59 |
+
classes_x=np.argmax(predict_x,axis=1)
|
| 60 |
+
sign = classes[int(classes_x)]
|
| 61 |
+
return sign
|
| 62 |
+
|
| 63 |
+
st.title('Traffic Sign Recognition')
|
| 64 |
+
st.write('This is a simple image classification web app to predict traffic signs.')
|
| 65 |
+
st.write('Please upload an image file to classify.')
|
| 66 |
+
file = st.file_uploader("Please upload an image file", type=["jpg", "png"])
|
| 67 |
+
if file is None:
|
| 68 |
+
st.text("You haven't uploaded an image file")
|
| 69 |
+
else:
|
| 70 |
+
image = Image.open(file)
|
| 71 |
+
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 72 |
+
st.write("")
|
| 73 |
+
label = image_processing(file)
|
| 74 |
+
st.success('This image most likely belongs to {} with a {:.2f} percent confidence.'.format(label, 100))
|
| 75 |
+
st.write('Done!')
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
numpy
|
| 3 |
+
keras
|
| 4 |
+
tensorflow
|
| 5 |
+
opencv-python
|
| 6 |
+
|