File size: 2,161 Bytes
e590c8f
 
 
33d5fe3
 
 
 
 
 
 
 
 
e590c8f
33d5fe3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d90b4c
33d5fe3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pip
print(pip.main(['list']))

from video_generation import VideoGenerator

import gradio as gr
import shutil
import os
from argparse import Namespace
import subprocess

os.environ['KMP_DUPLICATE_LIB_OK']='True'


def func(resize, video):
    # return video
    if os.path.exists('./outputs'):
        shutil.rmtree('./outputs')

    args = Namespace(
        arch="vit_small",
        patch_size=8,
        pretrained_weights="dino_deitsmall8_pretrain.pth",
        checkpoint_key="teacher",
        input_path=video,
        output_path="./outputs/",
        threshold=0.6,
        resize=resize,
        video_only=False,
        fps=30.0,
        video_format="mp4"
    )

    vid_generator = VideoGenerator(args)
    vid_generator.run()

    # Make a video that puts the resized input video + the attn output video together as one
    ffmpeg_cmd = """
        ffmpeg
        -i ./outputs/original-reshaped.mp4
        -i ./outputs/video.mp4
        -filter_complex hstack
        ./outputs/stacked.mp4
    """
    subprocess.call(ffmpeg_cmd.split())
    return './outputs/stacked.mp4'

title = "Interactive demo: DINO"
description = "Demo for Facebook AI's DINO, a new method for self-supervised training of Vision Transformers. Using this method, they are capable of segmenting objects within an image without having ever been trained to do so. This can be observed by displaying the self-attention of the heads from the last layer for the [CLS] token query. This demo uses a ViT-S/8 trained with DINO. To use it, simply upload an image or use the example image below. Results will show up in a few seconds."
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2104.14294'>Emerging Properties in Self-Supervised Vision Transformers</a> | <a href='https://github.com/facebookresearch/dino'>Github Repo</a></p>"
iface = gr.Interface(fn=func, 
                     inputs=[gr.inputs.Slider(120, 480, 20, label="resize"), gr.inputs.Video(type=None)],
                     outputs="video",
                     title=title,
                     description=description,
                     article=article)

iface.launch(debug=True)