| | import streamlit as st
|
| | from ultralytics import YOLO
|
| | import numpy as np
|
| | import cv2
|
| | from PIL import Image
|
| |
|
| | st.title("๐ Suspicious Activity Detection with YOLOv11")
|
| |
|
| |
|
| | @st.cache_resource
|
| | def load_model():
|
| | return YOLO("yolo11l.pt")
|
| |
|
| | model = load_model()
|
| |
|
| | uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| |
|
| | if uploaded_file:
|
| | image = Image.open(uploaded_file)
|
| | st.image(image, caption="Uploaded Image", use_column_width=True)
|
| |
|
| | if st.button("Detect Activity"):
|
| | img_array = np.array(image.convert("RGB"))[..., ::-1]
|
| | results = model.predict(img_array)
|
| |
|
| | for r in results:
|
| | plotted = r.plot()
|
| | st.image(plotted, caption="Detections", use_column_width=True)
|
| |
|
| | st.subheader("Detected Objects:")
|
| | for box in r.boxes:
|
| | conf = float(box.conf[0])
|
| | cls = int(box.cls[0])
|
| | cls_name = model.names[cls]
|
| | st.write(f"- {cls_name} (Confidence: {conf:.2f})")
|
| |
|