SkalskiP commited on
Commit
362e68b
1 Parent(s): 7d3a3bb

allow to set different confidence thresholds per model

Browse files
Files changed (1) hide show
  1. app.py +47 -12
app.py CHANGED
@@ -52,9 +52,9 @@ Powered by Roboflow [Inference](https://github.com/roboflow/inference) and
52
  """
53
 
54
  IMAGE_EXAMPLES = [
55
- ['https://media.roboflow.com/supervision/image-examples/people-walking.png', 0.4],
56
- ['https://media.roboflow.com/supervision/image-examples/vehicles.png', 0.4],
57
- ['https://media.roboflow.com/supervision/image-examples/basketball-1.png', 0.4],
58
  ]
59
 
60
  YOLO_V8_MODEL = get_model(model_id="coco/8")
@@ -102,15 +102,17 @@ def detect_and_annotate(
102
 
103
  def process_image(
104
  input_image: np.ndarray,
105
- confidence_threshold: float,
 
 
106
  iou_threshold: float
107
  ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
108
  yolo_v8_annotated_image = detect_and_annotate(
109
- YOLO_V8_MODEL, input_image, confidence_threshold, iou_threshold)
110
  yolo_v9_annotated_image = detect_and_annotate(
111
- YOLO_V9_MODEL, input_image, confidence_threshold, iou_threshold)
112
  yolo_10_annotated_image = detect_and_annotate(
113
- YOLO_V10_MODEL, input_image, confidence_threshold, iou_threshold)
114
 
115
  return (
116
  yolo_v8_annotated_image,
@@ -119,12 +121,38 @@ def process_image(
119
  )
120
 
121
 
122
- confidence_threshold_component = gr.Slider(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  minimum=0,
124
  maximum=1.0,
125
  value=0.3,
126
  step=0.01,
127
- label="Confidence Threshold",
128
  info=(
129
  "The confidence threshold for the YOLO model. Lower the threshold to "
130
  "reduce false negatives, enhancing the model's sensitivity to detect "
@@ -150,7 +178,10 @@ iou_threshold_component = gr.Slider(
150
  with gr.Blocks() as demo:
151
  gr.Markdown(MARKDOWN)
152
  with gr.Accordion("Configuration", open=False):
153
- confidence_threshold_component.render()
 
 
 
154
  iou_threshold_component.render()
155
  with gr.Row():
156
  input_image_component = gr.Image(
@@ -180,7 +211,9 @@ with gr.Blocks() as demo:
180
  examples=IMAGE_EXAMPLES,
181
  inputs=[
182
  input_image_component,
183
- confidence_threshold_component,
 
 
184
  iou_threshold_component
185
  ],
186
  outputs=[
@@ -194,7 +227,9 @@ with gr.Blocks() as demo:
194
  fn=process_image,
195
  inputs=[
196
  input_image_component,
197
- confidence_threshold_component,
 
 
198
  iou_threshold_component
199
  ],
200
  outputs=[
 
52
  """
53
 
54
  IMAGE_EXAMPLES = [
55
+ ['https://media.roboflow.com/supervision/image-examples/people-walking.png', 0.3, 0.3, 0.1],
56
+ ['https://media.roboflow.com/supervision/image-examples/vehicles.png', 0.3, 0.3, 0.1],
57
+ ['https://media.roboflow.com/supervision/image-examples/basketball-1.png', 0.3, 0.3, 0.1],
58
  ]
59
 
60
  YOLO_V8_MODEL = get_model(model_id="coco/8")
 
102
 
103
  def process_image(
104
  input_image: np.ndarray,
105
+ yolo_v8_confidence_threshold: float,
106
+ yolo_v9_confidence_threshold: float,
107
+ yolo_v10_confidence_threshold: float,
108
  iou_threshold: float
109
  ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
110
  yolo_v8_annotated_image = detect_and_annotate(
111
+ YOLO_V8_MODEL, input_image, yolo_v8_confidence_threshold, iou_threshold)
112
  yolo_v9_annotated_image = detect_and_annotate(
113
+ YOLO_V9_MODEL, input_image, yolo_v9_confidence_threshold, iou_threshold)
114
  yolo_10_annotated_image = detect_and_annotate(
115
+ YOLO_V10_MODEL, input_image, yolo_v10_confidence_threshold, iou_threshold)
116
 
117
  return (
118
  yolo_v8_annotated_image,
 
121
  )
122
 
123
 
124
+ yolo_v8_confidence_threshold_component = gr.Slider(
125
+ minimum=0,
126
+ maximum=1.0,
127
+ value=0.3,
128
+ step=0.01,
129
+ label="YOLOv8 Confidence Threshold",
130
+ info=(
131
+ "The confidence threshold for the YOLO model. Lower the threshold to "
132
+ "reduce false negatives, enhancing the model's sensitivity to detect "
133
+ "sought-after objects. Conversely, increase the threshold to minimize false "
134
+ "positives, preventing the model from identifying objects it shouldn't."
135
+ ))
136
+
137
+ yolo_v9_confidence_threshold_component = gr.Slider(
138
+ minimum=0,
139
+ maximum=1.0,
140
+ value=0.3,
141
+ step=0.01,
142
+ label="YOLOv9 Confidence Threshold",
143
+ info=(
144
+ "The confidence threshold for the YOLO model. Lower the threshold to "
145
+ "reduce false negatives, enhancing the model's sensitivity to detect "
146
+ "sought-after objects. Conversely, increase the threshold to minimize false "
147
+ "positives, preventing the model from identifying objects it shouldn't."
148
+ ))
149
+
150
+ yolo_v10_confidence_threshold_component = gr.Slider(
151
  minimum=0,
152
  maximum=1.0,
153
  value=0.3,
154
  step=0.01,
155
+ label="YOLOv10 Confidence Threshold",
156
  info=(
157
  "The confidence threshold for the YOLO model. Lower the threshold to "
158
  "reduce false negatives, enhancing the model's sensitivity to detect "
 
178
  with gr.Blocks() as demo:
179
  gr.Markdown(MARKDOWN)
180
  with gr.Accordion("Configuration", open=False):
181
+ with gr.Row():
182
+ yolo_v8_confidence_threshold_component.render()
183
+ yolo_v9_confidence_threshold_component.render()
184
+ yolo_v10_confidence_threshold_component.render()
185
  iou_threshold_component.render()
186
  with gr.Row():
187
  input_image_component = gr.Image(
 
211
  examples=IMAGE_EXAMPLES,
212
  inputs=[
213
  input_image_component,
214
+ yolo_v8_confidence_threshold_component,
215
+ yolo_v9_confidence_threshold_component,
216
+ yolo_v10_confidence_threshold_component,
217
  iou_threshold_component
218
  ],
219
  outputs=[
 
227
  fn=process_image,
228
  inputs=[
229
  input_image_component,
230
+ yolo_v8_confidence_threshold_component,
231
+ yolo_v9_confidence_threshold_component,
232
+ yolo_v10_confidence_threshold_component,
233
  iou_threshold_component
234
  ],
235
  outputs=[