Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from ultralytics import YOLO
|
3 |
import tempfile
|
4 |
-
import pandas as pd
|
5 |
|
6 |
|
7 |
model = YOLO('best.pt')
|
@@ -17,14 +16,13 @@ elif input_method == "Take a Picture":
|
|
17 |
image_data = st.camera_input("Take a picture")
|
18 |
|
19 |
if image_data is not None:
|
20 |
-
# Create a temporary file to store the input image
|
21 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as tmp_file:
|
22 |
tmp_file.write(image_data.getvalue())
|
23 |
image_path = tmp_file.name
|
24 |
|
25 |
results = model(image_path)
|
26 |
|
27 |
-
category_names = results[0].names
|
28 |
|
29 |
predictions = {}
|
30 |
for cls_id, conf in zip(results[0].boxes.cls, results[0].boxes.conf):
|
@@ -36,14 +34,12 @@ if image_data is not None:
|
|
36 |
else:
|
37 |
predictions[class_name] = [conf]
|
38 |
|
39 |
-
num_masks = len(results[0].masks.
|
40 |
|
41 |
st.write(f"Total {num_masks} objects found.")
|
42 |
for category, confidences in predictions.items():
|
43 |
st.write(f"{len(confidences)} {category}: {['{:.2f}'.format(c) for c in confidences]}")
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
st.image(output_tmp.name, caption='Segmented Image', use_column_width=True)
|
49 |
-
|
|
|
1 |
import streamlit as st
|
2 |
from ultralytics import YOLO
|
3 |
import tempfile
|
|
|
4 |
|
5 |
|
6 |
model = YOLO('best.pt')
|
|
|
16 |
image_data = st.camera_input("Take a picture")
|
17 |
|
18 |
if image_data is not None:
|
|
|
19 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as tmp_file:
|
20 |
tmp_file.write(image_data.getvalue())
|
21 |
image_path = tmp_file.name
|
22 |
|
23 |
results = model(image_path)
|
24 |
|
25 |
+
category_names = results[0].names
|
26 |
|
27 |
predictions = {}
|
28 |
for cls_id, conf in zip(results[0].boxes.cls, results[0].boxes.conf):
|
|
|
34 |
else:
|
35 |
predictions[class_name] = [conf]
|
36 |
|
37 |
+
num_masks = len(results[0].masks.data)
|
38 |
|
39 |
st.write(f"Total {num_masks} objects found.")
|
40 |
for category, confidences in predictions.items():
|
41 |
st.write(f"{len(confidences)} {category}: {['{:.2f}'.format(c) for c in confidences]}")
|
42 |
|
43 |
+
for result in results:
|
44 |
+
plotted_img = result.plot()
|
45 |
+
st.image(plotted_img, caption='Segmented Image', use_column_width=True)
|
|
|
|