File size: 1,825 Bytes
b3f7adb
 
 
4dbad61
b3f7adb
 
 
 
 
4dbad61
 
d5fb077
4dbad61
 
8afc9ad
 
1b3fdfa
3f75174
1b3fdfa
 
 
8afc9ad
 
b3f7adb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d5cbbb
b3f7adb
 
 
 
 
 
 
 
 
 
 
5d5cbbb
b3f7adb
 
 
 
 
5d5cbbb
 
8afc9ad
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
49
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st
from ultralytics import YOLO
import tempfile
import pandas as pd

model = YOLO('best.pt')

st.title('Spare-it Segmentation Model')

# Performance table data
st.header("Best Model Performance")
df = pd.read_csv('performance_table.csv')
st.dataframe(df)

with st.expander("See Example Results"):
    st.write("Here are some example images with detections:")
    st.image('example1.jpg')
    st.image('example2.jpg')
    st.image('example3.jpg')
    st.image('example4.jpg')
    st.image('example5.jpg')


input_method = st.radio("Choose the input method:", ("Upload an Image", "Take a Picture"))

if input_method == "Upload an Image":
    image_data = st.file_uploader("Upload an image", type=['jpg', 'jpeg', 'png'])

elif input_method == "Take a Picture":
    image_data = st.camera_input("Take a picture")

if image_data is not None:
    with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as tmp_file:
        tmp_file.write(image_data.getvalue())
        image_path = tmp_file.name

    results = model(image_path)

    category_names = results[0].names 

    predictions = {}
    for cls_id, conf in zip(results[0].boxes.cls, results[0].boxes.conf):
        cls_id = int(cls_id)
        conf = float(conf)
        class_name = category_names[cls_id]
        if class_name in predictions:
            predictions[class_name].append(conf)
        else:
            predictions[class_name] = [conf]

    num_masks = len(results[0].masks.data)

    st.write(f"Total {num_masks} objects found.")
    for category, confidences in predictions.items():
        st.write(f"{len(confidences)} {category}: {['{:.2f}'.format(c) for c in confidences]}")

    for result in results:
        plotted_img = result.plot()
        st.image(plotted_img, caption='Segmented Image', use_container_width =True)