Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,10 +48,10 @@ def load_model2():
|
|
48 |
threshold = 0.50
|
49 |
|
50 |
def predict(pilimg,video_in_filepath,threshold):
|
51 |
-
if pilimg:
|
52 |
image_np = pil_image_as_numpy_array(pilimg)
|
53 |
-
|
54 |
-
else:
|
55 |
video_reader = cv2.VideoCapture(video_in_filepath)
|
56 |
|
57 |
nb_frames = int(video_reader.get(cv2.CAP_PROP_FRAME_COUNT))
|
@@ -59,8 +59,10 @@ def predict(pilimg,video_in_filepath,threshold):
|
|
59 |
frame_w = int(video_reader.get(cv2.CAP_PROP_FRAME_WIDTH))
|
60 |
fps = video_reader.get(cv2.CAP_PROP_FPS)
|
61 |
|
62 |
-
|
63 |
-
|
|
|
|
|
64 |
video_writer = cv2.VideoWriter(video_out_filepath,
|
65 |
cv2.VideoWriter_fourcc(*'mp4v'),
|
66 |
fps,
|
@@ -89,7 +91,8 @@ def predict(pilimg,video_in_filepath,threshold):
|
|
89 |
video_writer.release()
|
90 |
cv2.destroyAllWindows()
|
91 |
cv2.waitKey(1)
|
92 |
-
|
|
|
93 |
|
94 |
|
95 |
def predict2(image_np,threshold):
|
@@ -177,7 +180,7 @@ gr.Interface(fn=predict,
|
|
177 |
description="Model: ssd_mobilenet_v2_320x320",
|
178 |
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
179 |
cache_examples = True,
|
180 |
-
|
181 |
).launch(share=True)
|
182 |
|
183 |
# gr.Interface(fn=video_fn,
|
|
|
48 |
threshold = 0.50
|
49 |
|
50 |
def predict(pilimg,video_in_filepath,threshold):
|
51 |
+
#if pilimg:
|
52 |
image_np = pil_image_as_numpy_array(pilimg)
|
53 |
+
# return predict2(image_np,threshold),None
|
54 |
+
#else:
|
55 |
video_reader = cv2.VideoCapture(video_in_filepath)
|
56 |
|
57 |
nb_frames = int(video_reader.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
|
59 |
frame_w = int(video_reader.get(cv2.CAP_PROP_FRAME_WIDTH))
|
60 |
fps = video_reader.get(cv2.CAP_PROP_FPS)
|
61 |
|
62 |
+
if video_in_filepath:
|
63 |
+
video_out_filepath = 'detected.mp4'
|
64 |
+
else:
|
65 |
+
video_out_filepath = None
|
66 |
video_writer = cv2.VideoWriter(video_out_filepath,
|
67 |
cv2.VideoWriter_fourcc(*'mp4v'),
|
68 |
fps,
|
|
|
91 |
video_writer.release()
|
92 |
cv2.destroyAllWindows()
|
93 |
cv2.waitKey(1)
|
94 |
+
# return None,video_out_filepath
|
95 |
+
return predict2(image_np,threshold), video_out_filepath
|
96 |
|
97 |
|
98 |
def predict2(image_np,threshold):
|
|
|
180 |
description="Model: ssd_mobilenet_v2_320x320",
|
181 |
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
182 |
cache_examples = True,
|
183 |
+
examples=[["test_samples/image489.png",None,0.55], ["test_samples/image825.png",None,0.55], ["test_samples/image833.png",None,0.55], ["test_samples/image846.png",None,0.55], [None,"test_samples/test_video.mp4",0.55]]
|
184 |
).launch(share=True)
|
185 |
|
186 |
# gr.Interface(fn=video_fn,
|