Spaces:
Sleeping
Sleeping
Daniel Cerda Escobar
commited on
Commit
·
b7fab1c
1
Parent(s):
c1439f5
Show data
Browse files
app.py
CHANGED
@@ -123,8 +123,8 @@ with col3:
|
|
123 |
label = 'Confidence Threshold',
|
124 |
min_value = 0.0,
|
125 |
max_value = 1.0,
|
126 |
-
value = 0.
|
127 |
-
step = 0.
|
128 |
)
|
129 |
|
130 |
st.write('##')
|
@@ -142,7 +142,7 @@ if submit:
|
|
142 |
image_size = 4960
|
143 |
|
144 |
with st.spinner(text="Performing prediction ... "):
|
145 |
-
|
146 |
image,
|
147 |
detection_model,
|
148 |
image_size=image_size,
|
@@ -153,7 +153,7 @@ if submit:
|
|
153 |
)
|
154 |
|
155 |
st.session_state["output_1"] = image
|
156 |
-
st.session_state["output_2"] =
|
157 |
|
158 |
st.write('##')
|
159 |
|
@@ -161,19 +161,12 @@ col1, col2, col3 = st.columns([1, 5, 1], gap='small')
|
|
161 |
with col2:
|
162 |
st.markdown(f"#### Object Detection Result")
|
163 |
with st.container(border = True):
|
164 |
-
tab1, tab2 = st.tabs(['Original Image','Inference Prediction'])
|
165 |
with tab1:
|
166 |
st.image(st.session_state["output_1"])
|
167 |
with tab2:
|
168 |
st.image(st.session_state["output_2"])
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
# label2='Inference Prediction',
|
174 |
-
# width=col2.width,
|
175 |
-
# starting_position=50,
|
176 |
-
# show_labels=True,
|
177 |
-
# make_responsive=True,
|
178 |
-
# in_memory=True,
|
179 |
-
# )
|
|
|
123 |
label = 'Confidence Threshold',
|
124 |
min_value = 0.0,
|
125 |
max_value = 1.0,
|
126 |
+
value = 0.85,
|
127 |
+
step = 0.05
|
128 |
)
|
129 |
|
130 |
st.write('##')
|
|
|
142 |
image_size = 4960
|
143 |
|
144 |
with st.spinner(text="Performing prediction ... "):
|
145 |
+
output_visual,coco_df,output_df = sahi_yolov8m_inference(
|
146 |
image,
|
147 |
detection_model,
|
148 |
image_size=image_size,
|
|
|
153 |
)
|
154 |
|
155 |
st.session_state["output_1"] = image
|
156 |
+
st.session_state["output_2"] = output_visual
|
157 |
|
158 |
st.write('##')
|
159 |
|
|
|
161 |
with col2:
|
162 |
st.markdown(f"#### Object Detection Result")
|
163 |
with st.container(border = True):
|
164 |
+
tab1, tab2, tab3 = st.tabs(['Original Image','Inference Prediction','Data 📊'])
|
165 |
with tab1:
|
166 |
st.image(st.session_state["output_1"])
|
167 |
with tab2:
|
168 |
st.image(st.session_state["output_2"])
|
169 |
+
with tab3:
|
170 |
+
st.dataframe(coco_df)
|
171 |
+
|
172 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import numpy
|
|
|
2 |
import sahi.predict
|
3 |
import sahi.utils
|
4 |
from PIL import Image
|
@@ -31,7 +32,27 @@ def sahi_yolov8m_inference(
|
|
31 |
rect_th=3,
|
32 |
text_size=2
|
33 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
return output
|
|
|
1 |
import numpy
|
2 |
+
import pandas as pd
|
3 |
import sahi.predict
|
4 |
import sahi.utils
|
5 |
from PIL import Image
|
|
|
32 |
rect_th=3,
|
33 |
text_size=2
|
34 |
)
|
35 |
+
output_visual = Image.fromarray(visual_result["image"])
|
36 |
+
|
37 |
+
# object prediction annotation
|
38 |
+
coco_annotations = prediction_result.to_coco_annotations()
|
39 |
+
# base DataFrame with predefined categories
|
40 |
+
output_df = pd.DataFrame(
|
41 |
+
{'category': ['ball-valve', 'butterfly-valve', 'centrifugal-pump', 'check-valve', 'gate-valve'],
|
42 |
+
'count': [0, 0, 0, 0, 0]
|
43 |
+
}
|
44 |
+
)
|
45 |
+
# extract relevant data into a new DataFrame
|
46 |
+
coco_df = pd.DataFrame(
|
47 |
+
[(item['category_name'], round(item['score'], 2)) for item in coco_annotations],
|
48 |
+
columns=['category', 'score']
|
49 |
+
)
|
50 |
+
# count occurrences of each category
|
51 |
+
category_counts = coco_df['category'].value_counts().reset_index()
|
52 |
+
category_counts.columns = ['category', 'count']
|
53 |
+
# update the `count` column in the base DataFrame
|
54 |
+
output_df['count'] = output_df['category'].map(category_counts.set_index('category')['count']).fillna(0).astype(int)
|
55 |
+
# calculate percentages
|
56 |
+
output_df['percentage'] = round((output_df['count'] / output_df['count'].sum()) * 100, 1)
|
57 |
|
58 |
+
return output_visual,coco_df,output_df
|
|
|
|