Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -369,11 +369,11 @@ def process_image(img_rgb, model_name, text_prompt="", morph_cleanup=False):
|
|
| 369 |
run_color = random.choice(PASTEL_COLORS)
|
| 370 |
|
| 371 |
try:
|
| 372 |
-
if model_name == "YOLOv8x-seg (Custom
|
| 373 |
return run_yolo_generic(img_rgb, "best.pt", target_classes=[0, 1], color=run_color, morph_cleanup=morph_cleanup)
|
| 374 |
-
elif model_name == "YOLOv8x-seg (Fine-tuned)":
|
| 375 |
return run_yolo_generic(img_rgb, "best.pt", target_classes=[0, 1], color=(255, 215, 0), morph_cleanup=morph_cleanup)
|
| 376 |
-
elif model_name == "SAM + YOLO (Custom
|
| 377 |
return run_sam_generic(img_rgb, "best.pt", target_classes=[0, 1], color=run_color, morph_cleanup=morph_cleanup)
|
| 378 |
elif model_name == "Grounding DINO (Zero-Shot Detection)":
|
| 379 |
return run_grounding_dino(img_rgb, text_prompt)
|
|
@@ -391,30 +391,30 @@ def process_image(img_rgb, model_name, text_prompt="", morph_cleanup=False):
|
|
| 391 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 392 |
theme = gr.themes.Soft(primary_hue="blue", secondary_hue="indigo")
|
| 393 |
|
| 394 |
-
with gr.Blocks(theme=theme, title="Car
|
| 395 |
gr.Markdown("""
|
| 396 |
-
# Car
|
| 397 |
Compare your custom trained YOLOv8 model against state-of-the-art Zero-Shot models!
|
| 398 |
""")
|
| 399 |
|
| 400 |
# ββ TAB 1: Custom Models ββ
|
| 401 |
-
with gr.Tab("
|
| 402 |
with gr.Row():
|
| 403 |
with gr.Column(scale=1):
|
| 404 |
-
input_image_custom = gr.Image(type="numpy", label="Upload
|
| 405 |
model_dropdown_custom = gr.Dropdown(
|
| 406 |
choices=[
|
| 407 |
-
"YOLOv8x-seg (Custom
|
| 408 |
-
"YOLOv8x-seg (Fine-tuned)",
|
| 409 |
-
"SAM + YOLO (Custom
|
| 410 |
],
|
| 411 |
-
value="YOLOv8x-seg (Fine-tuned)",
|
| 412 |
label="Select Custom Model",
|
| 413 |
-
info="Fine-tuned model achieves"
|
| 414 |
)
|
| 415 |
morph_checkbox = gr.Checkbox(
|
| 416 |
value=False,
|
| 417 |
-
label="
|
| 418 |
info="Fills holes inside mask (Closing) and removes tiny noise blobs (Opening). Visual only β does not affect mAP metrics."
|
| 419 |
)
|
| 420 |
submit_btn_custom = gr.Button("Run Segmentation", variant="primary", size="lg")
|
|
@@ -424,7 +424,7 @@ with gr.Blocks(theme=theme, title="Car Windows Segmentation") as demo:
|
|
| 424 |
output_stats_custom = gr.Textbox(label="Detection Statistics", interactive=False)
|
| 425 |
|
| 426 |
if mirror_examples:
|
| 427 |
-
gr.Markdown("### Click any image below to load it")
|
| 428 |
custom_gallery = gr.Gallery(value=mirror_examples, columns=10, height=120, object_fit="cover", allow_preview=False, show_label=False)
|
| 429 |
|
| 430 |
def load_mirror_img_custom(evt: gr.SelectData):
|
|
@@ -439,10 +439,10 @@ with gr.Blocks(theme=theme, title="Car Windows Segmentation") as demo:
|
|
| 439 |
)
|
| 440 |
|
| 441 |
# ββ TAB 2: Pretrained Zero-Shot Models ββ
|
| 442 |
-
with gr.Tab("
|
| 443 |
with gr.Row():
|
| 444 |
with gr.Column(scale=1):
|
| 445 |
-
input_image_pretrained = gr.Image(type="numpy", label="Upload
|
| 446 |
model_dropdown_pretrained = gr.Dropdown(
|
| 447 |
choices=[
|
| 448 |
"Grounding DINO (Zero-Shot Detection)",
|
|
@@ -451,21 +451,21 @@ with gr.Blocks(theme=theme, title="Car Windows Segmentation") as demo:
|
|
| 451 |
],
|
| 452 |
value="Grounded SAM (Zero-Shot Segmentation)",
|
| 453 |
label="Select Pretrained Model",
|
| 454 |
-
info="Finds
|
| 455 |
)
|
| 456 |
text_prompt = gr.Textbox(
|
| 457 |
-
value="
|
| 458 |
label="What to search for? (Text Prompt)",
|
| 459 |
info="Be sure to separate terms with a period."
|
| 460 |
)
|
| 461 |
-
submit_btn_pretrained = gr.Button("
|
| 462 |
with gr.Column(scale=1):
|
| 463 |
output_image_pretrained = gr.Image(label="Segmentation Result", interactive=False)
|
| 464 |
output_mask_pretrained = gr.Image(label="Binary Mask", interactive=False)
|
| 465 |
output_stats_pretrained = gr.Textbox(label="Detection Statistics", interactive=False)
|
| 466 |
|
| 467 |
if mirror_examples:
|
| 468 |
-
gr.Markdown("###
|
| 469 |
pretrained_gallery = gr.Gallery(value=mirror_examples, columns=10, height=120, object_fit="cover", allow_preview=False, show_label=False)
|
| 470 |
|
| 471 |
def load_mirror_img_pretrained(evt: gr.SelectData):
|
|
|
|
| 369 |
run_color = random.choice(PASTEL_COLORS)
|
| 370 |
|
| 371 |
try:
|
| 372 |
+
if model_name == "YOLOv8x-seg (Custom Window)":
|
| 373 |
return run_yolo_generic(img_rgb, "best.pt", target_classes=[0, 1], color=run_color, morph_cleanup=morph_cleanup)
|
| 374 |
+
elif model_name == "YOLOv8x-seg (Fine-tuned Β· 86.77% mAP50)":
|
| 375 |
return run_yolo_generic(img_rgb, "best.pt", target_classes=[0, 1], color=(255, 215, 0), morph_cleanup=morph_cleanup)
|
| 376 |
+
elif model_name == "SAM + YOLO (Custom Window)":
|
| 377 |
return run_sam_generic(img_rgb, "best.pt", target_classes=[0, 1], color=run_color, morph_cleanup=morph_cleanup)
|
| 378 |
elif model_name == "Grounding DINO (Zero-Shot Detection)":
|
| 379 |
return run_grounding_dino(img_rgb, text_prompt)
|
|
|
|
| 391 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 392 |
theme = gr.themes.Soft(primary_hue="blue", secondary_hue="indigo")
|
| 393 |
|
| 394 |
+
with gr.Blocks(theme=theme, title="Car Window Segmentation") as demo:
|
| 395 |
gr.Markdown("""
|
| 396 |
+
# Car Window Segmentation
|
| 397 |
Compare your custom trained YOLOv8 model against state-of-the-art Zero-Shot models!
|
| 398 |
""")
|
| 399 |
|
| 400 |
# ββ TAB 1: Custom Models ββ
|
| 401 |
+
with gr.Tab("Test Custom Models"):
|
| 402 |
with gr.Row():
|
| 403 |
with gr.Column(scale=1):
|
| 404 |
+
input_image_custom = gr.Image(type="numpy", label="Upload Window Image")
|
| 405 |
model_dropdown_custom = gr.Dropdown(
|
| 406 |
choices=[
|
| 407 |
+
"YOLOv8x-seg (Custom Window)",
|
| 408 |
+
"YOLOv8x-seg (Fine-tuned Β· 86.77% mAP50)",
|
| 409 |
+
"SAM + YOLO (Custom Window)",
|
| 410 |
],
|
| 411 |
+
value="YOLOv8x-seg (Fine-tuned Β· 86.77% mAP50)",
|
| 412 |
label="Select Custom Model",
|
| 413 |
+
info="Fine-tuned model achieves 86.77% Mask mAP50 on the test set"
|
| 414 |
)
|
| 415 |
morph_checkbox = gr.Checkbox(
|
| 416 |
value=False,
|
| 417 |
+
label="Apply Morphological Cleanup",
|
| 418 |
info="Fills holes inside mask (Closing) and removes tiny noise blobs (Opening). Visual only β does not affect mAP metrics."
|
| 419 |
)
|
| 420 |
submit_btn_custom = gr.Button("Run Segmentation", variant="primary", size="lg")
|
|
|
|
| 424 |
output_stats_custom = gr.Textbox(label="Detection Statistics", interactive=False)
|
| 425 |
|
| 426 |
if mirror_examples:
|
| 427 |
+
gr.Markdown("### Click any window image below to load it")
|
| 428 |
custom_gallery = gr.Gallery(value=mirror_examples, columns=10, height=120, object_fit="cover", allow_preview=False, show_label=False)
|
| 429 |
|
| 430 |
def load_mirror_img_custom(evt: gr.SelectData):
|
|
|
|
| 439 |
)
|
| 440 |
|
| 441 |
# ββ TAB 2: Pretrained Zero-Shot Models ββ
|
| 442 |
+
with gr.Tab("Pretrained Zero-Shot Models"):
|
| 443 |
with gr.Row():
|
| 444 |
with gr.Column(scale=1):
|
| 445 |
+
input_image_pretrained = gr.Image(type="numpy", label="Upload Window Image")
|
| 446 |
model_dropdown_pretrained = gr.Dropdown(
|
| 447 |
choices=[
|
| 448 |
"Grounding DINO (Zero-Shot Detection)",
|
|
|
|
| 451 |
],
|
| 452 |
value="Grounded SAM (Zero-Shot Segmentation)",
|
| 453 |
label="Select Pretrained Model",
|
| 454 |
+
info="Finds windows purely based on the text prompt you provide below!"
|
| 455 |
)
|
| 456 |
text_prompt = gr.Textbox(
|
| 457 |
+
value="car window. car glass. windshield.",
|
| 458 |
label="What to search for? (Text Prompt)",
|
| 459 |
info="Be sure to separate terms with a period."
|
| 460 |
)
|
| 461 |
+
submit_btn_pretrained = gr.Button("Run Zero-Shot Detection", variant="primary", size="lg")
|
| 462 |
with gr.Column(scale=1):
|
| 463 |
output_image_pretrained = gr.Image(label="Segmentation Result", interactive=False)
|
| 464 |
output_mask_pretrained = gr.Image(label="Binary Mask", interactive=False)
|
| 465 |
output_stats_pretrained = gr.Textbox(label="Detection Statistics", interactive=False)
|
| 466 |
|
| 467 |
if mirror_examples:
|
| 468 |
+
gr.Markdown("### Click any window image below to load it")
|
| 469 |
pretrained_gallery = gr.Gallery(value=mirror_examples, columns=10, height=120, object_fit="cover", allow_preview=False, show_label=False)
|
| 470 |
|
| 471 |
def load_mirror_img_pretrained(evt: gr.SelectData):
|