Spaces:
Running
Running
File size: 899 Bytes
4290d05 |
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 |
import streamlit as st
from PIL import Image
from ultralytics import YOLO
st.title("Object Detection with YOLO")
model = YOLO('best.pt')
def detect_objects(image):
result = model(image)
return result
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image.', use_column_width=True)
if st.button('Detect Objects'):
image.save('uploaded_image.jpg')
result = detect_objects('uploaded_image.jpg')
boxes = result[0].boxes
masks = result[0].masks
keypoints = result[0].keypoints
probs = result[0].probs
st.write("Number of objects detected:", len(boxes))
result[0].save(filename='result.jpg')
st.image('result.jpg', use_column_width=True) |