Spaces:
Running
on
Zero
Running
on
Zero
2025-07-31 19:44 π
Browse filesFixed bugs in app.py
app.py
CHANGED
@@ -23,13 +23,13 @@ EPS = 1e-8
|
|
23 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
24 |
loaded_model = None
|
25 |
|
26 |
-
|
27 |
-
"ZIP-B
|
28 |
-
"ZIP-S
|
29 |
-
"ZIP-T
|
30 |
-
"ZIP-N
|
31 |
-
"ZIP-P
|
32 |
-
|
33 |
|
34 |
# -----------------------------
|
35 |
# Define the model architecture
|
@@ -386,17 +386,10 @@ with gr.Blocks() as demo:
|
|
386 |
with gr.Row():
|
387 |
with gr.Column():
|
388 |
# Dropdown for model variant
|
389 |
-
|
390 |
-
choices=
|
391 |
-
value="ZIP-B",
|
392 |
-
label="Select
|
393 |
-
)
|
394 |
-
|
395 |
-
# Dropdown for pretrained dataset, dynamically updated based on variant
|
396 |
-
dataset_dropdown = gr.Dropdown(
|
397 |
-
choices=pretrained_datasets["ZIP-B"],
|
398 |
-
value=pretrained_datasets["ZIP-B"][0],
|
399 |
-
label="Select Pretrained Dataset"
|
400 |
)
|
401 |
|
402 |
# Dropdown for metric, always the same choices
|
@@ -406,19 +399,6 @@ with gr.Blocks() as demo:
|
|
406 |
label="Select Best Metric"
|
407 |
)
|
408 |
|
409 |
-
# Update dataset choices when variant changes
|
410 |
-
def update_dataset(variant):
|
411 |
-
choices = pretrained_datasets[variant]
|
412 |
-
return gr.Dropdown.update(
|
413 |
-
choices=choices,
|
414 |
-
value=choices[0]
|
415 |
-
)
|
416 |
-
|
417 |
-
variant_dropdown.change(
|
418 |
-
fn=update_dataset,
|
419 |
-
inputs=variant_dropdown,
|
420 |
-
outputs=dataset_dropdown
|
421 |
-
)
|
422 |
input_img = gr.Image(label="Input Image", sources=["upload", "clipboard"], type="pil")
|
423 |
submit_btn = gr.Button("Predict")
|
424 |
|
@@ -431,9 +411,10 @@ with gr.Blocks() as demo:
|
|
431 |
|
432 |
output_text = gr.Textbox(label="Total Count")
|
433 |
|
|
|
434 |
submit_btn.click(
|
435 |
fn=predict,
|
436 |
-
inputs=[input_img,
|
437 |
outputs=[input_img, output_structural_zero_map, output_sampling_zero_map, output_complete_zero_map, output_lambda_map, output_den_map, output_text]
|
438 |
)
|
439 |
|
|
|
23 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
24 |
loaded_model = None
|
25 |
|
26 |
+
pretrained_models = [
|
27 |
+
"ZIP-B @ ShanghaiTech A", "ZIP-B @ ShanghaiTech B", "ZIP-B @ UCF-QNRF", "ZIP-B @ NWPU-Crowd",
|
28 |
+
"ZIP-S @ ShanghaiTech A", "ZIP-S @ ShanghaiTech B", "ZIP-S @ UCF-QNRF",
|
29 |
+
"ZIP-T @ ShanghaiTech A", "ZIP-T @ ShanghaiTech B", "ZIP-T @ UCF-QNRF",
|
30 |
+
"ZIP-N @ ShanghaiTech A", "ZIP-N @ ShanghaiTech B", "ZIP-N @ UCF-QNRF",
|
31 |
+
"ZIP-P @ ShanghaiTech A", "ZIP-P @ ShanghaiTech B", "ZIP-P @ UCF-QNRF"
|
32 |
+
]
|
33 |
|
34 |
# -----------------------------
|
35 |
# Define the model architecture
|
|
|
386 |
with gr.Row():
|
387 |
with gr.Column():
|
388 |
# Dropdown for model variant
|
389 |
+
model_dropdown = gr.Dropdown(
|
390 |
+
choices=pretrained_models,
|
391 |
+
value="ZIP-B @ NWPU-Crowd",
|
392 |
+
label="Select a pretrained model"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
393 |
)
|
394 |
|
395 |
# Dropdown for metric, always the same choices
|
|
|
399 |
label="Select Best Metric"
|
400 |
)
|
401 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
input_img = gr.Image(label="Input Image", sources=["upload", "clipboard"], type="pil")
|
403 |
submit_btn = gr.Button("Predict")
|
404 |
|
|
|
411 |
|
412 |
output_text = gr.Textbox(label="Total Count")
|
413 |
|
414 |
+
variant, dataset = model_dropdown.value.split(" @ ")
|
415 |
submit_btn.click(
|
416 |
fn=predict,
|
417 |
+
inputs=[input_img, variant, dataset, metric_dropdown],
|
418 |
outputs=[input_img, output_structural_zero_map, output_sampling_zero_map, output_complete_zero_map, output_lambda_map, output_den_map, output_text]
|
419 |
)
|
420 |
|