Spaces:
Sleeping
Sleeping
Add example videos
Browse files- app.py +4 -4
- src/example_videos/179212 (360p).mp4 +3 -0
- src/example_videos/butterfly_-_38947 (360p).mp4 +3 -0
- src/example_videos/dog_-_84757 (720p).mp4 +3 -0
- src/example_videos/flamingo_-_49459 (720p).mp4 +3 -0
- src/example_videos/jellyfish_-_110877 (360p).mp4 +3 -0
- src/example_videos/monarch_-_327 (360p).mp4 +3 -0
- src/example_videos/pexels-taryn-elliott-9116112 (360p).mp4 +3 -0
- src/example_videos/pexels-zlatin-georgiev-5607745 (240p).mp4 +3 -0
- src/example_videos/pexels-zlatin-georgiev-7173031 (240p).mp4 +3 -0
- src/example_videos/pexels_videos_2556839 (240p).mp4 +3 -0
- src/example_videos/squirrel_on_a_wood (360p).mp4 +3 -0
- src/gradio_blocks.py +34 -6
- src/results/gradcam_video.mp4 +2 -2
app.py
CHANGED
@@ -27,12 +27,12 @@ ffmpeg_path = shutil.which('ffmpeg')
|
|
27 |
mediapy.set_ffmpeg(ffmpeg_path)
|
28 |
|
29 |
IMAGE_PATH = os.path.join(os.getcwd(), 'src/examples')
|
30 |
-
IMAGES_PER_ROW =
|
31 |
|
32 |
MAXIMAL_FRAMES = 1000
|
33 |
-
BATCHES_TO_PROCESS =
|
34 |
OUTPUT_FPS = 10
|
35 |
-
MAX_OUT_FRAMES =
|
36 |
|
37 |
CAM_METHODS = {
|
38 |
"GradCAM": GradCAM,
|
@@ -319,7 +319,7 @@ with gr.Blocks(theme='freddyaboulton/dracula_revamped', css=css) as demo:
|
|
319 |
gradcam_mode_button.click(fn=gradcam, inputs=[user_image, user_image_sketched, alpha, cam_method, layer, animal_to_explain], outputs=output_cam, queue=True)
|
320 |
|
321 |
# -------------------------------------------
|
322 |
-
#
|
323 |
# -------------------------------------------
|
324 |
with gr.Tab("Explain Video"):
|
325 |
build_video_to_camvideo(CAM_METHODS, ALL_CLASSES, gradcam_video)
|
|
|
27 |
mediapy.set_ffmpeg(ffmpeg_path)
|
28 |
|
29 |
IMAGE_PATH = os.path.join(os.getcwd(), 'src/examples')
|
30 |
+
IMAGES_PER_ROW = 10
|
31 |
|
32 |
MAXIMAL_FRAMES = 1000
|
33 |
+
BATCHES_TO_PROCESS = 15
|
34 |
OUTPUT_FPS = 10
|
35 |
+
MAX_OUT_FRAMES = 70
|
36 |
|
37 |
CAM_METHODS = {
|
38 |
"GradCAM": GradCAM,
|
|
|
319 |
gradcam_mode_button.click(fn=gradcam, inputs=[user_image, user_image_sketched, alpha, cam_method, layer, animal_to_explain], outputs=output_cam, queue=True)
|
320 |
|
321 |
# -------------------------------------------
|
322 |
+
# Video CAM
|
323 |
# -------------------------------------------
|
324 |
with gr.Tab("Explain Video"):
|
325 |
build_video_to_camvideo(CAM_METHODS, ALL_CLASSES, gradcam_video)
|
src/example_videos/179212 (360p).mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b2f570914bf8706d21874649bc3aec17324769a960fd8884efd2d93e7afe3551
|
3 |
+
size 1952253
|
src/example_videos/butterfly_-_38947 (360p).mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:82e11c26a4c8682cb5a1af4ea6ec5318292e55320bc71d8b6afc582054d3ea12
|
3 |
+
size 858838
|
src/example_videos/dog_-_84757 (720p).mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0404b94192170d23a763c302aeb42e9a66a2b8cb6b2e90b3e216f987c5dabefe
|
3 |
+
size 4021250
|
src/example_videos/flamingo_-_49459 (720p).mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e54b9778d69f330539ebfc7e507ead42a2c55820e4d80a55677f682608673bfd
|
3 |
+
size 8658989
|
src/example_videos/jellyfish_-_110877 (360p).mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:53e45f6bd34aaeefdabfeddc9d70a4d7670a183137f2469db42f4f90e73ea296
|
3 |
+
size 797977
|
src/example_videos/monarch_-_327 (360p).mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d0c163fd1ca2ec280c13430f8606d14e8c490980d66b63610ccf3e5af581138e
|
3 |
+
size 428449
|
src/example_videos/pexels-taryn-elliott-9116112 (360p).mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a619493ffecf460bc70f1908cedd89b5624cb0dbcb73239c739c8a210070af23
|
3 |
+
size 1690600
|
src/example_videos/pexels-zlatin-georgiev-5607745 (240p).mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:02d82cff5c3c4eb51edd6f07e64e33116cd6889ad45dfb9521aa89406022c539
|
3 |
+
size 470993
|
src/example_videos/pexels-zlatin-georgiev-7173031 (240p).mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6931230df61b43d063905f96e313ea47ac3b3ca16fd5d749bcd167b07d83ee69
|
3 |
+
size 268559
|
src/example_videos/pexels_videos_2556839 (240p).mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:065667e0d791af82df46c2b7667f17d5a0687fce606fc7e5c216a0e9c3045f76
|
3 |
+
size 402447
|
src/example_videos/squirrel_on_a_wood (360p).mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9af343138b0a589ccee2c9469f97ce55cbee720ffec9084429f33ae1e37e4f12
|
3 |
+
size 2006082
|
src/gradio_blocks.py
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
|
|
|
|
|
4 |
def build_video_to_camvideo(CAM_METHODS, ALL_CLASSES, gradcam_video):
|
5 |
with gr.Row():
|
6 |
-
with gr.Column():
|
7 |
gr.Markdown("### Video to GradCAM-Video")
|
8 |
gr.Markdown("Here you can upload a video and visualize the GradCAM.")
|
9 |
-
gr.Markdown("Please note that this can take a while. Also currently only a maximum of
|
10 |
gr.Markdown("The more frames and fps the video has, the longer it takes to process and the result will be more choppy.")
|
11 |
video_cam_method = gr.Radio(
|
12 |
["GradCAM", "GradCAM++"],
|
@@ -49,11 +51,37 @@ def build_video_to_camvideo(CAM_METHODS, ALL_CLASSES, gradcam_video):
|
|
49 |
)
|
50 |
video_animal_to_explain.description = "Here you can choose the animal to explain. If you choose 'Predicted Class' the method will explain the predicted class."
|
51 |
video_animal_to_explain.description_place = "center"
|
52 |
-
|
53 |
-
with gr.Column():
|
54 |
with gr.Column():
|
55 |
video_in = gr.Video(autoplay=False, include_audio=False)
|
56 |
video_out = gr.Video(autoplay=False, include_audio=False)
|
57 |
|
58 |
gif_cam_mode_button = gr.Button(value="Show GradCAM-Video", label="GradCAM", scale=1)
|
59 |
-
gif_cam_mode_button.click(fn=gradcam_video, inputs=[video_in, video_alpha, video_cam_method, video_layer, video_animal_to_explain], outputs=[video_out], queue=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
|
4 |
+
VIDEOS_PER_ROW = 3
|
5 |
+
VIDEO_EXAMPLES_PATH = "src/example_videos"
|
6 |
def build_video_to_camvideo(CAM_METHODS, ALL_CLASSES, gradcam_video):
|
7 |
with gr.Row():
|
8 |
+
with gr.Column(scale=2):
|
9 |
gr.Markdown("### Video to GradCAM-Video")
|
10 |
gr.Markdown("Here you can upload a video and visualize the GradCAM.")
|
11 |
+
gr.Markdown("Please note that this can take a while. Also currently only a maximum of 70 frames can be processed. The video will be cut to 70 frames if it is longer. Furthermore, the video can only consist of a maximum of 1000.")
|
12 |
gr.Markdown("The more frames and fps the video has, the longer it takes to process and the result will be more choppy.")
|
13 |
video_cam_method = gr.Radio(
|
14 |
["GradCAM", "GradCAM++"],
|
|
|
51 |
)
|
52 |
video_animal_to_explain.description = "Here you can choose the animal to explain. If you choose 'Predicted Class' the method will explain the predicted class."
|
53 |
video_animal_to_explain.description_place = "center"
|
54 |
+
with gr.Column(scale=1):
|
|
|
55 |
with gr.Column():
|
56 |
video_in = gr.Video(autoplay=False, include_audio=False)
|
57 |
video_out = gr.Video(autoplay=False, include_audio=False)
|
58 |
|
59 |
gif_cam_mode_button = gr.Button(value="Show GradCAM-Video", label="GradCAM", scale=1)
|
60 |
+
gif_cam_mode_button.click(fn=gradcam_video, inputs=[video_in, video_alpha, video_cam_method, video_layer, video_animal_to_explain], outputs=[video_out], queue=True)
|
61 |
+
|
62 |
+
with gr.Row():
|
63 |
+
with gr.Column():
|
64 |
+
gr.Markdown("## Examples", elem_id="video-examples-header")
|
65 |
+
gr.Markdown("Here you can choose an example video to visualize the GradCAM. Just click play and the video will be loaded as input above. Then you can click the button above to visualize the GradCAM.")
|
66 |
+
|
67 |
+
videos = os.listdir(VIDEO_EXAMPLES_PATH)
|
68 |
+
videos = [os.path.join(VIDEO_EXAMPLES_PATH, video) for video in videos]
|
69 |
+
videos = [video for video in videos if video.endswith(".mp4")]
|
70 |
+
rows = (len(videos) // VIDEOS_PER_ROW) + 1
|
71 |
+
loaded_videos = []
|
72 |
+
for i in range(rows):
|
73 |
+
with gr.Row(elem_classes=["row-example-videos"], equal_height=False):
|
74 |
+
for j in range(VIDEOS_PER_ROW):
|
75 |
+
if i * VIDEOS_PER_ROW + j >= len(videos): break
|
76 |
+
video = videos[i * VIDEOS_PER_ROW + j]
|
77 |
+
loaded_videos.append(
|
78 |
+
gr.Video(
|
79 |
+
value=video,
|
80 |
+
label=f"video {i * VIDEOS_PER_ROW + j + 1}",
|
81 |
+
include_audio=False,
|
82 |
+
autoplay=True,
|
83 |
+
elem_classes=["selectable_videos"],
|
84 |
+
)
|
85 |
+
)
|
86 |
+
for video in loaded_videos:
|
87 |
+
video.play(fn=lambda x: x, inputs=[video], outputs=[video_in])
|
src/results/gradcam_video.mp4
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:935c594a0ecbc14565723ad3896989aaaa6021232d368bf1cda5f8e9c0bf9e74
|
3 |
+
size 922461
|