File size: 2,945 Bytes
79acef0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from PIL import Image

def build_video_to_camvideo(CAM_METHODS, ALL_CLASSES, gradcam_video):
    with gr.Row():
        with gr.Column():
            gr.Markdown("### Video to GradCAM-Video")
            gr.Markdown("Here you can upload a video and visualize the GradCAM.")
            gr.Markdown("Please note that this can take a while. Also currently only a maximum of 60 frames can be processed. The video will be cut to 60 frames if it is longer. Furthermore, the video can only consist of a maximum of 1000.")
            gr.Markdown("The more frames and fps the video has, the longer it takes to process and the result will be more choppy.")
            video_cam_method = gr.Radio(
                    ["GradCAM", "GradCAM++"],
                    label="GradCAM Method",
                    value="GradCAM",
                    interactive=True,
                    scale=2,
                )
            video_cam_method.description = "Here you can choose the GradCAM method."
            video_cam_method.description_place = "left"
                
            video_alpha = gr.Slider(
                    minimum=.1,
                    maximum=.9,
                    value=0.5,
                    interactive=True,
                    step=.1,
                    label="Alpha",
                    scale=1,
                )
            video_alpha.description = "Here you can choose the alpha value."
            video_alpha.description_place = "left"
                
            video_layer = gr.Radio(
                    ["layer1", "layer2", "layer3", "layer4", "all"],
                    label="Layer",
                    value="layer4",
                    interactive=True,
                    scale=2,
                )
            video_layer.description = "Here you can choose the layer to visualize."
            video_layer.description_place = "left"
                
            video_animal_to_explain = gr.Dropdown(
                    choices=["Predicted Class"] + ALL_CLASSES,
                    label="Animal",
                    value="Predicted Class",
                    interactive=True,
                    scale=2,
                )
            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."
            video_animal_to_explain.description_place = "center"
                
        with gr.Column():
            with gr.Column():
                video_in = gr.Video(autoplay=True, include_audio=False)
                video_out = gr.Video(autoplay=True, include_audio=False)
                
            gif_cam_mode_button = gr.Button(value="Show GradCAM-Video", label="GradCAM", scale=1)
            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)