Spaces:
Runtime error
Runtime error
File size: 1,701 Bytes
bb3e610 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import gradio as gr
from custom.clip_ebc_onnx import ClipEBCOnnx
import numpy as np
import matplotlib.pyplot as plt
# ONNX ๋ชจ๋ธ ์ด๊ธฐํ
model = ClipEBCOnnx()
def predict_crowd(image):
"""
์ด๋ฏธ์ง๋ฅผ ๋ฐ์์ ๊ตฐ์ค ์๋ฅผ ์์ธกํ๊ณ ์๊ฐํ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํฉ๋๋ค.
Args:
image: Gradio์์ ๋ฐ์ ์ด๋ฏธ์ง (numpy array)
Returns:
tuple: (์์ธก๋ ๊ตฐ์ค ์, ๋ฐ๋ ๋งต ์๊ฐํ, ์ ์๊ฐํ)
"""
count = model.predict(image)
# ๋ฐ๋ ๋งต ์๊ฐํ
fig_density, density_map = model.visualize_density_map()
plt.close(fig_density) # ๋ฉ๋ชจ๋ฆฌ ๋์ ๋ฐฉ์ง
# ์ ์๊ฐํ
canvas, dot_map = model.visualize_dots()
plt.close(canvas.figure)
return (
f"์์ธก๋ ๊ตฐ์ค ์: {count:.1f}๋ช
",
density_map,
dot_map
)
with gr.Blocks(title="CLIP-EBC Crowd Counter") as app:
gr.Markdown("# CLIP-EBC Crowd Counter")
gr.Markdown("์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ฌ ๊ตฐ์ค ์๋ฅผ ์์ธกํ๊ณ ์๊ฐํํฉ๋๋ค.")
with gr.Row():
input_image = gr.Image(type="numpy", label="์
๋ ฅ ์ด๋ฏธ์ง")
with gr.Row():
predict_btn = gr.Button("์์ธก", variant="primary")
with gr.Row():
count_text = gr.Textbox(label="์์ธก ๊ฒฐ๊ณผ")
with gr.Row():
with gr.Column():
density_output = gr.Image(label="๋ฐ๋ ๋งต")
with gr.Column():
dots_output = gr.Image(label="์ ์๊ฐํ")
predict_btn.click(
fn=predict_crowd,
inputs=input_image,
outputs=[count_text, density_output, dots_output]
)
if __name__ == "__main__":
app.launch(share=False) |