Spaces:
Running
on
Zero
Running
on
Zero
remove grid_query_frame
Browse files
app.py
CHANGED
@@ -26,11 +26,9 @@ def parse_video(video_file):
|
|
26 |
def cotracker_demo(
|
27 |
input_video,
|
28 |
grid_size: int = 10,
|
29 |
-
grid_query_frame: int = 0,
|
30 |
tracks_leave_trace: bool = False,
|
31 |
):
|
32 |
load_video = parse_video(input_video)
|
33 |
-
grid_query_frame = min(len(load_video) - 1, grid_query_frame)
|
34 |
load_video = torch.from_numpy(load_video).permute(0, 3, 1, 2)[None].float()
|
35 |
|
36 |
model = torch.hub.load("facebookresearch/co-tracker", "cotracker2_online")
|
@@ -39,7 +37,7 @@ def cotracker_demo(
|
|
39 |
model = model.cuda()
|
40 |
load_video = load_video.cuda()
|
41 |
|
42 |
-
model(video_chunk=load_video, is_first_step=True, grid_size=grid_size
|
43 |
for ind in range(0, load_video.shape[1] - model.step, model.step):
|
44 |
pred_tracks, pred_visibility = model(
|
45 |
video_chunk=load_video[:, ind : ind + model.step * 2]
|
@@ -71,7 +69,6 @@ def cotracker_demo(
|
|
71 |
tracks=pred_tracks.cpu(),
|
72 |
visibility=pred_visibility.cpu(),
|
73 |
filename=f"{filename}_pred_track",
|
74 |
-
query_frame=grid_query_frame,
|
75 |
)
|
76 |
return os.path.join(
|
77 |
os.path.dirname(__file__), "results", f"{filename}_pred_track.mp4"
|
@@ -93,7 +90,6 @@ app = gr.Interface(
|
|
93 |
<p> To get started, simply upload your <b>.mp4</b> video in landscape orientation or click on one of the example videos to load them. The shorter the video, the faster the processing. We recommend submitting short videos of length <b>2-7 seconds</b>.</p> \
|
94 |
<ul style='display: inline-block; text-align: left;'> \
|
95 |
<li>The total number of grid points is the square of <b>Grid Size</b>.</li> \
|
96 |
-
<li>To specify the starting frame for tracking, adjust <b>Grid Query Frame</b>. Tracks will be visualized only after the selected frame.</li> \
|
97 |
<li>Check <b>Visualize Track Traces</b> to visualize traces of all the tracked points. </li> \
|
98 |
</ul> \
|
99 |
<p style='text-align: left'>For more details, check out our <a href='https://github.com/facebookresearch/co-tracker' target='_blank'>GitHub Repo</a> ⭐</p> \
|
@@ -102,16 +98,15 @@ app = gr.Interface(
|
|
102 |
inputs=[
|
103 |
gr.Video(type="file", label="Input video", interactive=True),
|
104 |
gr.Slider(minimum=1, maximum=70, step=1, value=10, label="Grid Size"),
|
105 |
-
gr.Slider(minimum=0, maximum=30, step=1, default=0, label="Grid Query Frame"),
|
106 |
gr.Checkbox(label="Visualize Track Traces"),
|
107 |
],
|
108 |
outputs=gr.Video(label="Video with predicted tracks"),
|
109 |
examples=[
|
110 |
-
[apple,
|
111 |
-
[apple,
|
112 |
-
[bear, 10,
|
113 |
-
[paragliding, 10,
|
114 |
-
[paragliding_launch, 10,
|
115 |
],
|
116 |
cache_examples=True,
|
117 |
allow_flagging=False,
|
|
|
26 |
def cotracker_demo(
|
27 |
input_video,
|
28 |
grid_size: int = 10,
|
|
|
29 |
tracks_leave_trace: bool = False,
|
30 |
):
|
31 |
load_video = parse_video(input_video)
|
|
|
32 |
load_video = torch.from_numpy(load_video).permute(0, 3, 1, 2)[None].float()
|
33 |
|
34 |
model = torch.hub.load("facebookresearch/co-tracker", "cotracker2_online")
|
|
|
37 |
model = model.cuda()
|
38 |
load_video = load_video.cuda()
|
39 |
|
40 |
+
model(video_chunk=load_video, is_first_step=True, grid_size=grid_size)
|
41 |
for ind in range(0, load_video.shape[1] - model.step, model.step):
|
42 |
pred_tracks, pred_visibility = model(
|
43 |
video_chunk=load_video[:, ind : ind + model.step * 2]
|
|
|
69 |
tracks=pred_tracks.cpu(),
|
70 |
visibility=pred_visibility.cpu(),
|
71 |
filename=f"{filename}_pred_track",
|
|
|
72 |
)
|
73 |
return os.path.join(
|
74 |
os.path.dirname(__file__), "results", f"{filename}_pred_track.mp4"
|
|
|
90 |
<p> To get started, simply upload your <b>.mp4</b> video in landscape orientation or click on one of the example videos to load them. The shorter the video, the faster the processing. We recommend submitting short videos of length <b>2-7 seconds</b>.</p> \
|
91 |
<ul style='display: inline-block; text-align: left;'> \
|
92 |
<li>The total number of grid points is the square of <b>Grid Size</b>.</li> \
|
|
|
93 |
<li>Check <b>Visualize Track Traces</b> to visualize traces of all the tracked points. </li> \
|
94 |
</ul> \
|
95 |
<p style='text-align: left'>For more details, check out our <a href='https://github.com/facebookresearch/co-tracker' target='_blank'>GitHub Repo</a> ⭐</p> \
|
|
|
98 |
inputs=[
|
99 |
gr.Video(type="file", label="Input video", interactive=True),
|
100 |
gr.Slider(minimum=1, maximum=70, step=1, value=10, label="Grid Size"),
|
|
|
101 |
gr.Checkbox(label="Visualize Track Traces"),
|
102 |
],
|
103 |
outputs=gr.Video(label="Video with predicted tracks"),
|
104 |
examples=[
|
105 |
+
[apple, 30, False],
|
106 |
+
[apple, 10, True],
|
107 |
+
[bear, 10, False],
|
108 |
+
[paragliding, 10, False],
|
109 |
+
[paragliding_launch, 10, False],
|
110 |
],
|
111 |
cache_examples=True,
|
112 |
allow_flagging=False,
|