camera impl
Browse files- app.py +57 -14
- predicted_image.jpg +0 -0
app.py
CHANGED
@@ -1,27 +1,70 @@
|
|
1 |
import streamlit as st
|
2 |
from ultralytics import YOLO
|
3 |
import tempfile
|
|
|
4 |
|
5 |
# Load the model
|
6 |
model = YOLO('best.pt')
|
7 |
|
8 |
-
st.title('
|
9 |
|
10 |
-
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as tmp_file:
|
14 |
-
tmp_file.write(
|
15 |
-
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
for result in results:
|
24 |
-
result.save(filename=saved_image_path) # Save the predicted image
|
25 |
|
26 |
-
|
27 |
-
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from ultralytics import YOLO
|
3 |
import tempfile
|
4 |
+
import pandas as pd
|
5 |
|
6 |
# Load the model
|
7 |
model = YOLO('best.pt')
|
8 |
|
9 |
+
st.title('Spare-it Recyclable Detection Model')
|
10 |
|
11 |
+
st.write("""
|
12 |
+
This detection model is designed to identify recyclable items within images, providing high detection capabilities across 20 categories. Below are the performance metrics for specific recyclable materials.
|
13 |
+
""")
|
14 |
|
15 |
+
# Hardcoded table with performance metrics
|
16 |
+
data = {
|
17 |
+
'Category': [
|
18 |
+
'Overall', 'Shredded Paper', 'Metal Can', 'Aluminum Foil', 'Paper Cup',
|
19 |
+
'Office Paper', 'Paper Towel/Napkins/Tissue', 'Glass Bottles', 'Plastic Drink Bottle',
|
20 |
+
'Compostable Fiber Ware', 'Fruits And Veggies', 'Clear Plastic Cup', 'Black Plastic',
|
21 |
+
'Cardboard Coffee Cup Sleeve', 'Snack or Candy Bag or Wrapper', 'Plastic Lid except black',
|
22 |
+
'Filled Bag', 'Empty Plastic Bag', 'Clean Paper Plate', 'Shelf Stable Carton',
|
23 |
+
'Clean Cardboard', 'Empty Paper Bag'
|
24 |
+
],
|
25 |
+
'Total Images': [1667] * 22,
|
26 |
+
'Samples': [12871, 16, 1227, 58, 405, 1588, 4304, 58, 378, 244, 635, 245, 136, 74, 1018, 509, 287, 529, 43, 134, 587, 396],
|
27 |
+
'Precision': [0.527, 0.845, 0.79, 0.674, 0.607, 0.564, 0.562, 0.562, 0.559, 0.52, 0.518, 0.513, 0.469, 0.467, 0.462, 0.459, 0.428, 0.422, 0.416, 0.414, 0.41, 0.402],
|
28 |
+
'Recall': [0.451, 0.5, 0.801, 0.414, 0.568, 0.409, 0.518, 0.5, 0.574, 0.623, 0.378, 0.551, 0.485, 0.343, 0.333, 0.344, 0.37, 0.308, 0.256, 0.396, 0.419, 0.371],
|
29 |
+
'mAP50': [0.448, 0.5, 0.855, 0.434, 0.595, 0.437, 0.533, 0.511, 0.578, 0.593, 0.377, 0.465, 0.479, 0.363, 0.339, 0.321, 0.37, 0.279, 0.275, 0.433, 0.35, 0.328],
|
30 |
+
'mAP50-95': [0.315, 0.429, 0.667, 0.307, 0.44, 0.272, 0.315, 0.298, 0.386, 0.489, 0.23, 0.331, 0.367, 0.244, 0.211, 0.232, 0.248, 0.158, 0.232, 0.296, 0.256, 0.215]
|
31 |
+
}
|
32 |
+
df = pd.DataFrame(data)
|
33 |
+
|
34 |
+
st.dataframe(df, hide_index=True)
|
35 |
+
|
36 |
+
input_method = st.radio("Choose the input method:", ("Upload an Image", "Take a Picture"))
|
37 |
+
|
38 |
+
if input_method == "Upload an Image":
|
39 |
+
image_data = st.file_uploader("Upload an image", type=['jpg', 'jpeg', 'png'])
|
40 |
+
|
41 |
+
elif input_method == "Take a Picture":
|
42 |
+
image_data = st.camera_input("Take a picture")
|
43 |
+
|
44 |
+
if image_data is not None:
|
45 |
+
# make temp image file to run detection
|
46 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as tmp_file:
|
47 |
+
tmp_file.write(image_data.getvalue())
|
48 |
+
image_path = tmp_file.name
|
49 |
+
|
50 |
+
results = model(image_path)
|
51 |
|
52 |
+
category_names = results[0].names
|
53 |
+
predictions = {}
|
54 |
+
for box in results[0].boxes:
|
55 |
+
cls_id = int(box.cls)
|
56 |
+
conf = float(box.conf)
|
57 |
+
if cls_id in category_names:
|
58 |
+
if category_names[cls_id] in predictions:
|
59 |
+
predictions[category_names[cls_id]].append(conf)
|
60 |
+
else:
|
61 |
+
predictions[category_names[cls_id]] = [conf]
|
62 |
|
63 |
+
st.write(f"Total {len(results[0].boxes.cls)} objects found.")
|
64 |
+
for category, confidences in predictions.items():
|
65 |
+
st.write(f"{len(confidences)} {category}: {['{:.2f}'.format(c) for c in confidences]}")
|
|
|
|
|
66 |
|
67 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as output_tmp:
|
68 |
+
for result in results:
|
69 |
+
result.save(filename=output_tmp.name)
|
70 |
+
st.image(output_tmp.name, caption='Predicted Image', use_column_width=True)
|
predicted_image.jpg
DELETED
Binary file (737 kB)
|
|