|
import cv2 |
|
import numpy as np |
|
import gradio as gr |
|
from keras.models import load_model |
|
|
|
names = [ |
|
'Speed limit (20km/h)', |
|
'Speed limit (30km/h)', |
|
'Speed limit (50km/h)', |
|
'Speed limit (60km/h)', |
|
'Speed limit (70km/h)', |
|
'Speed limit (80km/h)', |
|
'End of speed limit (80km/h)', |
|
'Speed limit (100km/h)', |
|
'Speed limit (120km/h)', |
|
'No passing', |
|
'No passing for vechiles over 3.5 metric tons', |
|
'Road Block', |
|
'Priority road', |
|
'Yield', |
|
'Stop', |
|
'No vehicles', |
|
'Vechiles over 3.5 metric tons prohibited', |
|
'No entry', |
|
'General caution', |
|
'Double curve', |
|
'Bumpy Road', |
|
'Slippery road', |
|
'Road narrows on the right', |
|
'Road Work', |
|
'Traffic Signals', |
|
'Pedestrians', |
|
'Children crossing', |
|
'Bicycles crossing', |
|
'Beware of ice/snow', |
|
'Wild animals crossing', |
|
'End of all speed and passing limits', |
|
'Turn right ahead', |
|
'Turn left ahead', |
|
'Ahead only', |
|
'Go straight or right', |
|
'Go straight or left', |
|
'Keep right', |
|
'Keep left', |
|
'Roundabout mandatory', |
|
'End of no passing', |
|
'End of no passing by vechiles over 3.5 metric tons' |
|
] |
|
|
|
|
|
model = load_model('model.h5') |
|
|
|
|
|
|
|
def preprocess_image(img): |
|
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) |
|
img = cv2.equalizeHist(img) |
|
img = img / 255 |
|
img = cv2.resize(img, (32, 32)) |
|
img = img.reshape(1, 32, 32, 1) |
|
return img |
|
|
|
|
|
|
|
def predict_image(image): |
|
preprocessed_image = preprocess_image(image) |
|
predictions = model.predict(preprocessed_image) |
|
class_index = np.argmax(predictions) |
|
class_label = names[class_index] |
|
accuracy = predictions[0][class_index] |
|
return f"Prediction: {class_label}, Accuracy: {accuracy:.2%}" |
|
|
|
|
|
|
|
iface = gr.Interface(fn=predict_image, inputs="image", outputs="text") |
|
|
|
|
|
iface.launch() |
|
|