Spaces:
Running
on
Zero
Running
on
Zero
JianyuanWang
commited on
Commit
•
5a03db1
1
Parent(s):
11e8a80
Add env file
Browse files- app.py +67 -9
- pre-requirements.txt +2 -0
- requirements.txt +10 -0
app.py
CHANGED
@@ -1,14 +1,72 @@
|
|
1 |
-
import
|
2 |
-
import
|
|
|
3 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
zero = torch.Tensor([0]).cuda()
|
6 |
-
print(zero.device) # <-- 'cpu' 🤔
|
7 |
|
8 |
@spaces.GPU
|
9 |
-
def
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
|
14 |
-
demo.launch()
|
|
|
1 |
+
import os
|
2 |
+
import cv2
|
3 |
+
import imutils
|
4 |
import torch
|
5 |
+
import numpy as np
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
def parse_video(video_file):
|
11 |
+
vs = cv2.VideoCapture(video_file)
|
12 |
+
|
13 |
+
frames = []
|
14 |
+
while True:
|
15 |
+
(gotit, frame) = vs.read()
|
16 |
+
if frame is not None:
|
17 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
18 |
+
frames.append(frame)
|
19 |
+
if not gotit:
|
20 |
+
break
|
21 |
+
|
22 |
+
return np.stack(frames)
|
23 |
+
|
24 |
|
|
|
|
|
25 |
|
26 |
@spaces.GPU
|
27 |
+
def cotracker_demo(
|
28 |
+
input_video,
|
29 |
+
grid_size: int = 10,
|
30 |
+
tracks_leave_trace: bool = False,
|
31 |
+
):
|
32 |
+
load_video = parse_video(input_video)
|
33 |
+
load_video = torch.from_numpy(load_video).permute(0, 3, 1, 2)[None].float()
|
34 |
+
|
35 |
+
import time
|
36 |
+
|
37 |
+
def current_milli_time():
|
38 |
+
return round(time.time() * 1000)
|
39 |
+
|
40 |
+
filename = str(current_milli_time())
|
41 |
+
|
42 |
+
return os.path.join(
|
43 |
+
os.path.dirname(__file__), "results", f"{filename}.mp4"
|
44 |
+
)
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
app = gr.Interface(
|
51 |
+
title="🎨 CoTracker: It is Better to Track Together",
|
52 |
+
description="<div style='text-align: left;'> \
|
53 |
+
<p>Welcome to <a href='http://co-tracker.github.io' target='_blank'>CoTracker</a>! This space demonstrates point (pixel) tracking in videos. \
|
54 |
+
Points are sampled on a regular grid and are tracked jointly. </p> \
|
55 |
+
<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> \
|
56 |
+
<ul style='display: inline-block; text-align: left;'> \
|
57 |
+
<li>The total number of grid points is the square of <b>Grid Size</b>.</li> \
|
58 |
+
<li>Check <b>Visualize Track Traces</b> to visualize traces of all the tracked points. </li> \
|
59 |
+
</ul> \
|
60 |
+
<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> \
|
61 |
+
</div>",
|
62 |
+
fn=cotracker_demo,
|
63 |
+
inputs=[
|
64 |
+
gr.Video(type="file", label="Input video", interactive=True),
|
65 |
+
gr.Slider(minimum=10, maximum=80, step=1, value=10, label="Number of tracks"),
|
66 |
+
],
|
67 |
+
outputs=gr.Video(label="Video with predicted tracks"),
|
68 |
+
cache_examples=True,
|
69 |
+
allow_flagging=False,
|
70 |
+
)
|
71 |
+
app.queue(max_size=20, concurrency_count=1).launch(debug=True)
|
72 |
|
|
|
|
pre-requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
torch==2.1.0
|
2 |
+
torchvision==0.16.0
|
requirements.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
hydra-core==1.3.2
|
2 |
+
accelerate==0.24.0
|
3 |
+
omegaconf
|
4 |
+
opencv-python
|
5 |
+
einops
|
6 |
+
git+https://github.com/cvg/LightGlue.git#egg=LightGlue
|
7 |
+
numpy==1.26.3
|
8 |
+
pycolmap==0.6.1
|
9 |
+
https://huggingface.co/facebook/VGGSfM/resolve/main/poselib-2.0.2-cp310-cp310-linux_x86_64.whl
|
10 |
+
|