File size: 1,481 Bytes
4d237f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import streamlit as st
from ultralyticsplus import YOLO, render_result
import PIL.Image as Image
import numpy as np
import requests
from io import BytesIO

# Initialize Streamlit app
st.title("Blood Cell Detection with YOLOv8")

# Load YOLO model
model = YOLO('keremberke/yolov8m-blood-cell-detection')

# Set model parameters
model.overrides['conf'] = 0.25  # NMS confidence threshold
model.overrides['iou'] = 0.45   # NMS IoU threshold
model.overrides['agnostic_nms'] = False  # NMS class-agnostic
model.overrides['max_det'] = 1000  # Maximum number of detections per image

# File uploader for image input
uploaded_file = st.file_uploader("Upload an image for detection", type=["jpg", "png"])

if uploaded_file:
    # Open the uploaded image
    image = Image.open(uploaded_file)
    
    # Perform inference
    results = model.predict(np.array(image))
    
    # Display results
    st.image(image, caption="Uploaded Image", use_column_width=True)
    
    # Render detection results
    rendered_image = render_result(model=model, image=image, result=results[0])
    
    # Show the rendered result
    st.image(rendered_image, caption="Detection Results", use_column_width=True)

    # Display details of detected boxes
    st.write("Detection Results:")
    for box in results[0].boxes:
        st.write(f"Bounding box: {box.xyxy}")
        st.write(f"Confidence: {box.conf}")
        st.write(f"Class: {box.cls}")

else:
    st.write("Upload an image to start detection")