Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,7 @@ detector50 = pipeline(model="facebook/detr-resnet-50")
|
|
32 |
detector101 = pipeline(model="facebook/detr-resnet-101")
|
33 |
|
34 |
if torch.cuda.is_available():
|
35 |
-
print("##############------------use cuda!------------#################")
|
36 |
detector50.model.to('cuda')
|
37 |
detector101.model.to('cuda')
|
38 |
|
@@ -59,7 +59,7 @@ def query_data(model, in_pil_img: Image.Image):
|
|
59 |
results = detector101(in_pil_img)
|
60 |
else:
|
61 |
results = detector50(in_pil_img)
|
62 |
-
print(f"检测结果:{results}")
|
63 |
return results
|
64 |
|
65 |
|
@@ -69,7 +69,7 @@ def get_figure(in_pil_img):
|
|
69 |
plt.imshow(in_pil_img)
|
70 |
|
71 |
ax = plt.gca()
|
72 |
-
print(f"图像尺寸:{in_pil_img.size}")
|
73 |
in_results = query_data(model, in_pil_img)
|
74 |
|
75 |
for prediction in in_results:
|
@@ -80,7 +80,7 @@ def get_figure(in_pil_img):
|
|
80 |
|
81 |
ax.add_patch(plt.Rectangle((x, y), w, h, fill=False, color=selected_color, linewidth=3))
|
82 |
ax.text(x, y, f"{prediction['label']}: {round(prediction['score']*100, 1)}%", fontdict=fdic)
|
83 |
-
print(f"x: {x}, y: {y}, w: {w}, h: {h}, label: {prediction['label']}, score: {prediction['score']}")
|
84 |
|
85 |
plt.axis("off")
|
86 |
|
@@ -88,7 +88,7 @@ def get_figure(in_pil_img):
|
|
88 |
|
89 |
|
90 |
def process_single_frame(frame):
|
91 |
-
print(f"开始处理单帧")
|
92 |
# 将 BGR 转换为 RGB
|
93 |
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
94 |
|
@@ -107,7 +107,7 @@ def process_single_frame(frame):
|
|
107 |
|
108 |
|
109 |
def infer_video(input_video_path):
|
110 |
-
print(f"开始处理视频 {input_video_path}")
|
111 |
with tempfile.TemporaryDirectory() as tmp_dir:
|
112 |
# output_video_path = Path(tmp_dir) / "output.mp4"
|
113 |
cap = cv2.VideoCapture(input_video_path)
|
|
|
32 |
detector101 = pipeline(model="facebook/detr-resnet-101")
|
33 |
|
34 |
if torch.cuda.is_available():
|
35 |
+
# print("##############------------use cuda!------------#################")
|
36 |
detector50.model.to('cuda')
|
37 |
detector101.model.to('cuda')
|
38 |
|
|
|
59 |
results = detector101(in_pil_img)
|
60 |
else:
|
61 |
results = detector50(in_pil_img)
|
62 |
+
# print(f"检测结果:{results}")
|
63 |
return results
|
64 |
|
65 |
|
|
|
69 |
plt.imshow(in_pil_img)
|
70 |
|
71 |
ax = plt.gca()
|
72 |
+
# print(f"图像尺寸:{in_pil_img.size}")
|
73 |
in_results = query_data(model, in_pil_img)
|
74 |
|
75 |
for prediction in in_results:
|
|
|
80 |
|
81 |
ax.add_patch(plt.Rectangle((x, y), w, h, fill=False, color=selected_color, linewidth=3))
|
82 |
ax.text(x, y, f"{prediction['label']}: {round(prediction['score']*100, 1)}%", fontdict=fdic)
|
83 |
+
# print(f"x: {x}, y: {y}, w: {w}, h: {h}, label: {prediction['label']}, score: {prediction['score']}")
|
84 |
|
85 |
plt.axis("off")
|
86 |
|
|
|
88 |
|
89 |
|
90 |
def process_single_frame(frame):
|
91 |
+
# print(f"开始处理单帧")
|
92 |
# 将 BGR 转换为 RGB
|
93 |
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
94 |
|
|
|
107 |
|
108 |
|
109 |
def infer_video(input_video_path):
|
110 |
+
# print(f"开始处理视频 {input_video_path}")
|
111 |
with tempfile.TemporaryDirectory() as tmp_dir:
|
112 |
# output_video_path = Path(tmp_dir) / "output.mp4"
|
113 |
cap = cv2.VideoCapture(input_video_path)
|