yourusername commited on
Commit
648f835
1 Parent(s): 178400a

:construction: wip

Browse files
Files changed (2) hide show
  1. dino/app.py +17 -19
  2. packages.txt +1 -0
dino/app.py CHANGED
@@ -1,6 +1,3 @@
1
- import pip
2
- print(pip.main(['list']))
3
-
4
  from video_generation import VideoGenerator
5
 
6
  import gradio as gr
@@ -13,11 +10,12 @@ os.environ['KMP_DUPLICATE_LIB_OK']='True'
13
 
14
 
15
  def func(resize, video):
16
- # return video
17
- if os.path.exists('/tmp/outputs'):
18
- shutil.rmtree('/tmp/outputs')
 
19
 
20
- os.makedirs('/tmp/outputs/')
21
 
22
  args = Namespace(
23
  arch="vit_small",
@@ -25,7 +23,7 @@ def func(resize, video):
25
  pretrained_weights="dino_deitsmall8_pretrain.pth",
26
  checkpoint_key="teacher",
27
  input_path=video,
28
- output_path="/tmp/outputs/",
29
  threshold=0.6,
30
  resize=resize,
31
  video_only=False,
@@ -36,23 +34,23 @@ def func(resize, video):
36
  vid_generator = VideoGenerator(args)
37
  vid_generator.run()
38
 
39
- # # Make a video that puts the resized input video + the attn output video together as one
40
- # ffmpeg_cmd = """
41
- # ffmpeg
42
- # -i /tmp/outputs/original-reshaped.mp4
43
- # -i /tmp/outputs/video.mp4
44
- # -filter_complex hstack
45
- # /tmp/outputs/stacked.mp4
46
- # """
47
- # subprocess.call(ffmpeg_cmd.split())
48
- return '/tmp/outputs/video.mp4', '/tmp/outputs/original-reshaped.mp4'
49
 
50
  title = "Interactive demo: DINO"
51
  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."
52
  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>"
53
  iface = gr.Interface(fn=func,
54
  inputs=[gr.inputs.Slider(120, 480, 20, label="resize"), gr.inputs.Video(type=None)],
55
- outputs=[gr.outputs.Video(label='attn'), gr.outputs.Video(label='orig-reshaped')],
56
  title=title,
57
  description=description,
58
  article=article)
 
 
 
 
1
  from video_generation import VideoGenerator
2
 
3
  import gradio as gr
 
10
 
11
 
12
  def func(resize, video):
13
+ output_dir = '/tmp/outputs'
14
+
15
+ if os.path.exists(output_dir):
16
+ shutil.rmtree(output_dir)
17
 
18
+ os.makedirs(output_dir)
19
 
20
  args = Namespace(
21
  arch="vit_small",
 
23
  pretrained_weights="dino_deitsmall8_pretrain.pth",
24
  checkpoint_key="teacher",
25
  input_path=video,
26
+ output_path=output_dir,
27
  threshold=0.6,
28
  resize=resize,
29
  video_only=False,
 
34
  vid_generator = VideoGenerator(args)
35
  vid_generator.run()
36
 
37
+ # Make a video that puts the resized input video + the attn output video together as one
38
+ ffmpeg_cmd = f"""
39
+ ffmpeg
40
+ -i {output_dir}/original-reshaped.mp4
41
+ -i {output_dir}/video.mp4
42
+ -filter_complex hstack
43
+ {output_dir}/stacked.mp4
44
+ """
45
+ subprocess.call(ffmpeg_cmd.split())
46
+ return f'{output_dir}/stacked.mp4'
47
 
48
  title = "Interactive demo: DINO"
49
  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."
50
  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>"
51
  iface = gr.Interface(fn=func,
52
  inputs=[gr.inputs.Slider(120, 480, 20, label="resize"), gr.inputs.Video(type=None)],
53
+ outputs='video',
54
  title=title,
55
  description=description,
56
  article=article)
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg