Spaces:
Runtime error
Runtime error
Shi Tong Yuan
commited on
Commit
·
7b48d55
1
Parent(s):
31357a9
重新排版了下。。。
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ import skvideo.io
|
|
10 |
|
11 |
# 全局设置
|
12 |
DEFAULT_CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair",
|
13 |
-
|
14 |
COLORS = np.random.uniform(0, 255, size=(len(DEFAULT_CLASSES), 3))
|
15 |
DISPLAY_INTERVAL = 30
|
16 |
CONFIDENCE_LEVEL = 0.5
|
@@ -61,9 +61,10 @@ def process_video(input_video_path, selected_classes):
|
|
61 |
originEndY = int(endY*origin_h/h)
|
62 |
|
63 |
if DEFAULT_CLASSES[idx] in selected_classes:
|
64 |
-
label = "{}: {:.2f}%".format(
|
|
|
65 |
cv2.rectangle(origin_frame, (originStartX, originStartY),
|
66 |
-
|
67 |
|
68 |
y = originStartY - 15 if originStartY - 15 > 15 else originStartY + 15
|
69 |
cv2.putText(origin_frame, label, (originStartX, y),
|
@@ -132,18 +133,29 @@ def main():
|
|
132 |
# 定义Gradio界面
|
133 |
with gr.Blocks() as demo:
|
134 |
with gr.Row():
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
with gr.Row():
|
|
|
140 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
input_classes = gr.Dropdown(
|
142 |
DEFAULT_CLASSES, value=DEFAULT_CLASSES, multiselect=True, label="Detection Classes", info="Select the classes that you want to detect."
|
143 |
)
|
144 |
examples = gr.Examples(
|
145 |
[f"test/{file.name}" for file in os.scandir('./test')], inputs=input_video)
|
146 |
-
process_video_btn = gr.Button(
|
|
|
147 |
|
148 |
process_video_btn.click(fn=process_video, inputs=[
|
149 |
input_video, input_classes], outputs=[processed_frames, output_video])
|
|
|
10 |
|
11 |
# 全局设置
|
12 |
DEFAULT_CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair",
|
13 |
+
"cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
|
14 |
COLORS = np.random.uniform(0, 255, size=(len(DEFAULT_CLASSES), 3))
|
15 |
DISPLAY_INTERVAL = 30
|
16 |
CONFIDENCE_LEVEL = 0.5
|
|
|
61 |
originEndY = int(endY*origin_h/h)
|
62 |
|
63 |
if DEFAULT_CLASSES[idx] in selected_classes:
|
64 |
+
label = "{}: {:.2f}%".format(
|
65 |
+
DEFAULT_CLASSES[idx], confidence * 100)
|
66 |
cv2.rectangle(origin_frame, (originStartX, originStartY),
|
67 |
+
(originEndX, originEndY), COLORS[idx], 2)
|
68 |
|
69 |
y = originStartY - 15 if originStartY - 15 > 15 else originStartY + 15
|
70 |
cv2.putText(origin_frame, label, (originStartX, y),
|
|
|
133 |
# 定义Gradio界面
|
134 |
with gr.Blocks() as demo:
|
135 |
with gr.Row():
|
136 |
+
gr.Markdown(
|
137 |
+
"""
|
138 |
+
# Hello! Welcome to the Object-Detection Demo.
|
139 |
+
""")
|
140 |
with gr.Row():
|
141 |
+
input_video = gr.Video(label="Video Input")
|
142 |
with gr.Column():
|
143 |
+
processed_frames = gr.Image(label="Live Preview")
|
144 |
+
gr.Markdown(
|
145 |
+
"""
|
146 |
+
Note: Output video will be visible after previewing the video.
|
147 |
+
""")
|
148 |
+
output_video = gr.Video(label="Video Output")
|
149 |
+
|
150 |
+
with gr.Column():
|
151 |
+
with gr.Row():
|
152 |
input_classes = gr.Dropdown(
|
153 |
DEFAULT_CLASSES, value=DEFAULT_CLASSES, multiselect=True, label="Detection Classes", info="Select the classes that you want to detect."
|
154 |
)
|
155 |
examples = gr.Examples(
|
156 |
[f"test/{file.name}" for file in os.scandir('./test')], inputs=input_video)
|
157 |
+
process_video_btn = gr.Button(
|
158 |
+
"process video", style="width: 100px; height: 30px;")
|
159 |
|
160 |
process_video_btn.click(fn=process_video, inputs=[
|
161 |
input_video, input_classes], outputs=[processed_frames, output_video])
|