|
import streamlit as st |
|
import kagglehub |
|
import tensorflow as tf |
|
from PIL import Image |
|
import numpy as np |
|
|
|
|
|
model_path = kagglehub.model_download("sohiebalwedyan/seatbelt-detection/tensorFlow2/seatbelt-detection") |
|
print("Path to model files:", model_path) |
|
|
|
|
|
model = tf.saved_model.load(model_path) |
|
|
|
def predict(image): |
|
|
|
img = image.resize((224, 224)) |
|
img_array = np.array(img) / 255.0 |
|
img_array = np.expand_dims(img_array, axis=0) |
|
|
|
|
|
predictions = model(tf.convert_to_tensor(img_array, dtype=tf.float32)) |
|
|
|
|
|
|
|
st.write("Raw predictions:", predictions) |
|
|
|
return image |
|
|
|
|
|
st.title("Seatbelt Detection") |
|
st.markdown("Upload an image for seatbelt detection.") |
|
|
|
uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) |
|
|
|
if uploaded_image is not None: |
|
image = Image.open(uploaded_image) |
|
st.image(image, caption="Uploaded Image", use_column_width=True) |
|
|
|
st.subheader("Prediction Results:") |
|
result = predict(image) |
|
|