Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,61 @@
|
|
1 |
---
|
2 |
license: cc-by-nc-4.0
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: cc-by-nc-4.0
|
3 |
+
tags:
|
4 |
+
- vision
|
5 |
+
- cotracker
|
6 |
---
|
7 |
+
# Point tracking with CoTracker
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
**CoTracker** is a fast transformer-based model that was introduced in [CoTracker: It is Better to Track Together](https://arxiv.org/abs/2307.07635).
|
12 |
+
It can track any point in a video and brings to tracking some of the benefits of Optical Flow.
|
13 |
+
|
14 |
+
CoTracker can track:
|
15 |
+
|
16 |
+
- **Any pixel** in a video
|
17 |
+
- A **quasi-dense** set of pixels together
|
18 |
+
- Points can be manually selected or sampled on a grid in any video frame
|
19 |
+
|
20 |
+
|
21 |
+
## How to use
|
22 |
+
Here is how to use this model in the **offline mode**:
|
23 |
+
```python
|
24 |
+
import torch
|
25 |
+
# Download the video
|
26 |
+
url = 'https://github.com/facebookresearch/co-tracker/blob/main/assets/apple.mp4'
|
27 |
+
# pip install imageio[ffmpeg]
|
28 |
+
import imageio.v3 as iio
|
29 |
+
frames = iio.imread(url, plugin="FFMPEG") # plugin="pyav"
|
30 |
+
video = torch.tensor(frames).permute(0, 3, 1, 2)[None].float().to(device) # B T C H W
|
31 |
+
|
32 |
+
grid_size = 10
|
33 |
+
device = 'cuda'
|
34 |
+
# Run Offline CoTracker:
|
35 |
+
cotracker = torch.hub.load("facebookresearch/co-tracker", "cotracker2").to(device)
|
36 |
+
pred_tracks, pred_visibility = cotracker(video, grid_size=grid_size) # B T N 2, B T N 1
|
37 |
+
```
|
38 |
+
and in the **online mode**:
|
39 |
+
```python
|
40 |
+
cotracker = torch.hub.load("facebookresearch/co-tracker", "cotracker2_online").to(device)
|
41 |
+
# Run Online CoTracker, the same model with a different API:
|
42 |
+
for ind in range(0, video.shape[1] - cotracker.step, cotracker.step):
|
43 |
+
pred_tracks, pred_visibility = cotracker(
|
44 |
+
video_chunk=video[:, ind : ind + cotracker.step * 2],
|
45 |
+
is_first_step=(ind == 0),
|
46 |
+
grid_size=grid_size
|
47 |
+
) # B T N 2, B T N 1
|
48 |
+
|
49 |
+
```
|
50 |
+
Online processing is more memory-efficient and allows for the processing of longer videos or videos in real-time.
|
51 |
+
|
52 |
+
## BibTeX entry and citation info
|
53 |
+
|
54 |
+
```bibtex
|
55 |
+
@article{karaev2023cotracker,
|
56 |
+
title={CoTracker: It is Better to Track Together},
|
57 |
+
author={Nikita Karaev and Ignacio Rocco and Benjamin Graham and Natalia Neverova and Andrea Vedaldi and Christian Rupprecht},
|
58 |
+
journal={arXiv:2307.07635},
|
59 |
+
year={2023}
|
60 |
+
}
|
61 |
+
```
|