|
|
import torch
|
|
|
import streamlit as st
|
|
|
from PIL import Image
|
|
|
import io
|
|
|
|
|
|
|
|
|
model = torch.hub.load('ultralytics/yolov5', 'custom', path='fire.pt')
|
|
|
|
|
|
|
|
|
st.title("YOLOv5 Image Detection")
|
|
|
st.write("Upload an image to detect objects using YOLOv5")
|
|
|
|
|
|
|
|
|
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
|
|
|
|
|
if uploaded_file is not None:
|
|
|
|
|
|
image = Image.open(uploaded_file)
|
|
|
|
|
|
|
|
|
results = model(image)
|
|
|
|
|
|
|
|
|
results_image = results.render()[0]
|
|
|
|
|
|
|
|
|
results_image = Image.fromarray(results_image)
|
|
|
|
|
|
|
|
|
buf = io.BytesIO()
|
|
|
results_image.save(buf, format='JPEG')
|
|
|
byte_im = buf.getvalue()
|
|
|
|
|
|
|
|
|
st.image(image, caption='Uploaded Image', use_column_width=True)
|
|
|
st.image(results_image, caption='Detected Image', use_column_width=True)
|
|
|
|
|
|
|
|
|
st.download_button(
|
|
|
label="Download Output Image",
|
|
|
data=byte_im,
|
|
|
file_name="output.jpg",
|
|
|
mime="image/jpeg"
|
|
|
)
|
|
|
|