ATTENTION!
Hello there! I have to admit this is my first "research" project. You might find a lot of gaps here, or things the writer still has doubts about.
I put "research" in quotes on purpose. Yet not a "researcher", ran the experiment myself, hands-on, and I wrote a technical report about what I did and what came out. If something looks wrong, it probably is, and I'd be glad to hear about it (contact me here).
Reconstructed from a phone video walking around the statue. Frames go into VGGT, single forward pass, no optimization loop. Drag to rotate, scroll to zoom.
VGGT (Visual Geometry Grounded Transformer) is a neural network from Oxford's Visual Geometry Group and Meta AI, published at CVPR 2025. It has about 1.2 billion parameters.
Give it photos of one scene. For every photo it returns the camera, the depth of every pixel, and the 3D position of every pixel.
A photo is flat. It loses depth. But if the camera moves, a point close to the camera shifts a lot in the image, and a far point shifts little. [Recall: Parallax]
For two cameras side by side, this becomes one formula:
\(d\) is in the denominator: large shift means close, small shift means far. If the camera only rotates without moving, \(B = 0\) and depth cannot be recovered.
Structure from Motion (SfM, used by tools like COLMAP) works with a camera model. A 3D point \(\mathbf{X}\) lands in photo \(i\) at pixel:
SfM finds distinctive points in every photo, matches them across photos, and makes a first guess of all cameras and 3D points. Then bundle adjustment refines that guess by solving:
The result is cameras plus a sparse set of 3D points (only at matched points). Dense depth for every pixel needs a second stage, Multi-View Stereo (MVS).
VGGT replaces both stages with a single network. The photos pass through it once (feed-forward). No optimization loop is needed, although bundle adjustment can still be added afterwards.
flowchart LR
subgraph S["Classic pipeline"]
direction TB
S1["Find distinctive points
in each photo"] --> S2["Match them
between photos"]
S2 --> S3["First guess:
cameras + 3D points"]
S3 --> S4["Bundle adjustment
(refine the guess)"]
S4 -.-> S4
S4 --> S5["Sparse points + cameras"]
S5 --> S6["Multi-View Stereo"]
S6 --> S7["Dense depth + point cloud"]
end
subgraph V["VGGT"]
direction TB
V1["All photos"] --> V2["One pass through
the network"]
V2 --> V3["Cameras + dense depth
+ point cloud"]
end
S ~~~ V
VGGT is one function \(f\) that maps all photos to four outputs per photo:
| Output | Shape | Meaning |
|---|---|---|
| \(\mathbf{g}_i\) | \(\mathbb{R}^{9}\) | camera of photo \(i\) |
| \(D_i\) | \(\mathbb{R}^{H \times W}\) | depth map: how far in front of the camera each pixel is, along the viewing axis (z) |
| \(P_i\) | \(\mathbb{R}^{3 \times H \times W}\) | point map: 3D position per pixel, in photo 1's coordinates |
| \(T_i\) | \(\mathbb{R}^{C \times H \times W}\) | tracking features, used by the track head |
Inside, three stages: tokenize, mix with attention, read out with heads.
flowchart TB
A["N photos"] --> B["Tokenize
DINO patch tokens
+ 1 camera token + 4 register tokens"]
B --> C["Backbone
24 × (frame attention → global attention)"]
C --> D["Camera head
reads camera tokens"]
C --> E["Dense head (DPT)
reads patch tokens"]
D --> F["g: rotation, translation,
field of view"]
E --> G["D, P + confidence
per pixel"]
E --> H["Track head
reads T"]
H --> I["2D position of a point
in every photo"]
A transformer reads tokens: vectors of \(C\) numbers, each describing one small piece of the input.
Each photo is resized to a longest side of 518 px and cut into small square patches. A pretrained image model, DINO, turns every patch into a token:
\(m\) is the number of patches; it depends on image size. Then two kinds of learned tokens are added in front:
Photo 1 gets its own learned camera and register tokens. Photos 2 to \(N\) share a second set. This tells the model which photo is the reference: all 3D output is in photo 1's frame. Photos 2 to \(N\) start with identical extra tokens and only become distinct through attention, so their order does not matter.
Attention lets each token pull information from other tokens. Given tokens \(\mathbf{X}\), three learned matrices make three views of them:
Example: the token for the statue's nose in photo 2 gives a high score to the nose token in photo 5, and a low score to a sky token. It then absorbs mostly the nose information.
All tokens together form a tensor of shape \(N \times n \times C\). VGGT applies the same attention operation to two different groupings of it:
| Frame attention | Global attention | |
|---|---|---|
| Grouping | \(N\) separate sequences of shape \(n \times C\) | 1 sequence of shape \(Nn \times C\) |
| A token sees | tokens of its own photo | tokens of all photos |
| Learns | each image alone: edges, shapes, what is in front of what | the same spot across photos, which is what parallax needs |
| Score pairs | \(N \cdot n^2\) | \((Nn)^2 = N^2 n^2\) |
The backbone has \(L = 24\) layers. Each layer runs one of each, in order:
Global attention costs \(N\) times more than frame attention, because it compares every token with every token in every photo. This is why memory grows quickly with more photos.
There are no cross-attention layers and no hand-written 3D rules. All geometry is learned from data.
flowchart LR
subgraph FA["Frame attention: N × (n × C)"]
direction TB
F1["Photo 1 ↔ Photo 1"]
F2["Photo 2 ↔ Photo 2"]
F3["Photo 3 ↔ Photo 3"]
end
subgraph GA["Global attention: (Nn) × C"]
direction TB
G1["Photo 1 ↔ Photo 2 ↔ Photo 3
every token sees every token"]
end
FA --> GA
GA -- "repeat × 24" --> FA
A head is a small network that turns tokens into one kind of answer. The camera head reads each photo's camera token after the backbone, passes it through 4 more self-attention layers and one linear layer:
Rotation \(\mathbf{q} = (x, y, z, w)\). A quaternion: four numbers that encode a 3D rotation. It converts to a rotation matrix:
Quaternions are used instead of 9 matrix entries because 4 numbers are enough and they avoid invalid rotations.
Translation \(\mathbf{t}\). Together with \(R\), it maps a world point into this camera's view: \(\mathbf{X}_{\text{cam}} = R\,\mathbf{X} + \mathbf{t}\).
Field of view \(\mathbf{f} = (\theta_w, \theta_h)\). How wide the lens sees, horizontally and vertically. It gives the lens matrix:
Patch tokens are coarse: one token covers a whole patch of pixels. DPT (Dense Prediction Transformer) rearranges the patch tokens back into an image-shaped grid and upsamples it step by step to full resolution, producing a feature map \(F_i\). A final 3×3 convolution turns \(F_i\) into:
Follows one point across all photos. Built on the CoTracker2 design.
It does not assume the photos are in time order, so it works on unordered photos, not just video.
The point map \(\hat{P}\) already holds 3D points. But the paper reports a more accurate route: build the points from depth and camera instead (unprojection). For pixel \((u, v)\) of photo \(i\):
Then keep only confident pixels:
flowchart TB
A["Pixel (u, v)"] --> C
B["Depth D(u, v)"] --> C
C["Point relative to camera
X_cam = D · K⁻¹ · [u, v, 1]"] --> D
D["Point in shared frame
X_world = Rᵀ · (X_cam − t)"] --> E
E{"Confidence ≥ τ ?"} -- yes --> F["Keep → point cloud"]
E -- no --> G["Drop"]
Repeat for every pixel of every photo. The result is a point cloud: colored dots in 3D, not a solid surface. In this experiment the point cloud is turned into a mesh afterwards (see Experiment).
The threshold \(\tau\) is a trade-off: higher gives a cleaner but emptier cloud, lower gives a fuller but noisier one.
Training shows the network scenes where the true cameras, depths, points, and tracks are known. A loss measures how wrong the predictions are. Training lowers it.
The first three are on similar scales, so they get equal weight. Tracking gets a low weight.
Camera loss.
\(\|\cdot\|_{\epsilon}\) is the Huber loss. For an error \(r\):
Squared for small errors (smooth), linear for large ones (a few bad samples cannot dominate).
Depth loss.
Point-map loss. Same form as depth, with \(\hat{P}_i, P_i, \Sigma^{P}_i\).
Track loss.
For \(M\) query points and \(N\) photos: distance between true and predicted 2D position. A visibility term (binary cross-entropy) is added, following CoTracker2.
Normalization. Ground truth is expressed in photo 1's frame, then scaled by:
\(\mathcal{X}\) is the set of all true 3D points of the scene. After scaling, the average point is at distance 1 from the origin. Predictions are not rescaled; the network learns this convention. This is why VGGT output has no real-world units.
Three subjects in Jakarta, each filmed as a walk-around video on a phone: Bundaran HI (the Selamat Datang Monument), Monumen Nasional (the Monas obelisk), and the Pangeran Diponegoro statue at Monas. The videos, sampled frames, external photos, and all notebooks are in the experiment repository.
flowchart TB
A["Walk-around video"] --> B["Frame sampling
sharpest frame per interval"]
B --> C["Color normalization
(optional)"]
C --> D["Sky removal
(optional, Monas only)
paint sky white"]
D --> E["VGGT
single forward pass:
depth + camera"]
E --> F["Unproject
keep top 50% confidence
(+ drop sky pixels)"]
F --> G["Clean
downsample + remove outliers"]
G --> H["Poisson mesh"]
H --> I["GLB"]
1. Frame sampling video360_ke_foto.ipynb
A walk-around video has thousands of nearly identical frames, many blurred by motion. I split the video into N equal intervals and keep only the sharpest frame of each.
jarak = total // JUMLAH # frames per interval
for i in range(total):
ok, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
skor = cv2.Laplacian(gray, cv2.CV_64F).var() # sharpness score
if skor > skor_terbaik: # remember the sharpest so far
terbaik, skor_terbaik = frame, skor
if (i + 1) % jarak == 0: # interval ends: keep the winner
cv2.imwrite(f"{OUT}/{n:03d}.png", terbaik)
terbaik, skor_terbaik = None, 0
2. Stitching the Monas video append_monas.ipynb
Monas was filmed in three clips. I join them into one video before sampling.
tulis("monas-1.mp4")
tulis("monas-2.mp4")
tulis("monas-3-reversed.mp4", balik=True) # written back to front
# every frame is resized to 1080 × 1920 (portrait)
3. Color normalization 01_color_normalization.ipynb
Exposure and white balance drift while filming, so the same surface can look different between frames. I reshape every frame's colors to match one reference frame.
reference = frames[len(frames) // 2] # middle frame of the set
result = match_histograms(image, reference, channel_axis=-1)
4. VGGT forward pass vggt_to_mesh.ipynb
model = VGGT.from_pretrained("facebook/VGGT-1B").to("cuda").eval()
model.track_head = None # not needed for a 3D model
model.point_head = None # use depth + camera instead (more accurate)
images = load_and_preprocess_images(paths, mode="pad") # (S, 3, H, W)
with torch.autocast("cuda", dtype=torch.bfloat16):
pred = model(images) # the single forward pass
extr, intr = pose_encoding_to_extri_intri(pred["pose_enc"], images.shape[-2:])
depth = pred["depth"] # D, per pixel
conf = pred["depth_conf"] # Σ^D, per pixel (≥ 1)
5. Depth to points, filtered by confidence
pts = unproject_depth_map_to_point_map(depth, extr, intr) # (S, H, W, 3)
keep = conf > np.percentile(conf, 50) # top 50% most confident
points, colors = pts[keep], rgb[keep] # flat list of (x, y, z)
6. Sky removal vggt_to_mesh.ipynb (Monas runs only)
A sky segmentation model marks which pixels are sky. Those pixels are painted white before VGGT, so the model never sees the sky, and they are dropped again from the point cloud afterwards.
sky_session = onnxruntime.InferenceSession("skyseg.onnx") # from huggingface: JianyuanWang/skyseg
def not_sky(img):
x = cv2.resize(img, (320, 320)) # model input size
x = (x - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225] # ImageNet normalization
out = sky_session.run(None, {"input": x})[0] # sky score per pixel
out = (out - out.min()) / (out.max() - out.min()) * 255 # rescale to 0..255
return cv2.resize(out, (w, h)) < 32 # True = not sky
# before VGGT: paint the sky white
sky = ~np.stack([not_sky(im) for im in images.permute(0, 2, 3, 1).cpu().numpy()])
images = images.masked_fill(torch.from_numpy(sky).to(images.device)[:, None], 1.0)
pred = model(images) # VGGT sees white instead of sky
# after VGGT: drop sky pixels from the point cloud too
keep &= ~sky
7. Remember which camera saw each point
cams = -np.einsum("sji,sj->si", R, t) # camera centers: C = −Rᵀ t
view = (cams[:, None, None] - pts)[keep] # direction: point → its camera
8. Clean the point cloud
pcd = pcd.voxel_down_sample(size / 1000) # merge points inside small cubes
pcd, _ = pcd.remove_statistical_outlier(20, 2.0) # drop floating points
9. Build the mesh
pcd.estimate_normals()
n[(n * view).sum(1) < 0] *= -1 # flip normals that point away from the camera
mesh, dens = create_from_point_cloud_poisson(pcd, depth=9)
mesh.remove_vertices_by_mask(dens < np.quantile(dens, 0.05)) # drop invented surface
mesh = mesh.crop(pcd.get_axis_aligned_bounding_box())
10. Export
vertices * [1, -1, -1] # OpenCV (y down, z forward) → glTF (y up, z back)
Without this flip the model opens upside down in model-viewer, three.js, or Blender.
Numbers are frame counts. Green marks a usable model; darker is better.
| Plain | 15 | 30 | 60 | 120 | 240 | 360 |
|---|---|---|---|---|---|---|
| Bundaran HI | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ |
| Monumen Nasional | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ |
| Diponegoro statue | ✓ | ✓ good | ✓ | ✓ | ✓ | ✓ |
| Color normalized | 15 | 30 | 60 | 120 | 240 | 360 |
| Bundaran HI | ✗ | ✗ | ✗ | ✗ | – | – |
| Monumen Nasional | ✗ | ✗ | ✗ | ✗ | – | – |
| Diponegoro statue | ✓ best | ✓ | ✓ | ✓ | – | – |
| Color normalized + sky removal | 15 | 30 | 60 | 120 | ||
| Monumen Nasional | ✗ | ✗ | ✗ | ✗ | ||
| Sky removal + external photos | 4 + 59 | 60 + 59 | 60 + 59 N | 4 + 59 N | ||
| Monumen Nasional | ✗ | ✗ | ✗ | ✗ | ||
Every run on these two scenes failed. Some examples:
These are my guesses, not tested causes. Each one links back to how VGGT works.
The statue is close, fills most of the frame, has rich texture, and the walk around it creates strong parallax. The best run used only 15 frames, inside the 2 to 24 range VGGT was trained on.
| Symbol | Meaning |
|---|---|
| Sizes and indices | |
| \(N\) | number of photos |
| \(i\) | photo index, \(1 \dots N\). Photo 1 is the reference |
| \(j\) | 3D point index (bundle adjustment) or query point index (tracking) |
| \(H, W\) | image height and width, in pixels |
| \(m\) | patch tokens per photo (depends on image size) |
| \(n\) | all tokens per photo: \(n = 1 + 4 + m\) |
| \(C\) | channels: how many numbers make up one token or one feature vector |
| \(L\) | number of backbone layers (24) |
| \(M\) | number of query points in the track loss |
| Points and pixels | |
| \(I_i\) | photo \(i\), shape \(3 \times H \times W\) (RGB) |
| \((u, v)\) | pixel position: column, row. Origin at the top-left corner |
| \(\mathbf{X}\) | a 3D point \((x, y, z)\) |
| \(\mathbf{X}_{\text{cam}}\) | a 3D point relative to one camera; \(z\) is how far in front of it |
| \(\mathbf{X}_{\text{world}}\) | a 3D point in the shared frame (photo 1's camera) |
| \(\mathbf{x}\), \(\mathbf{x}_{ij}\) | a 2D pixel position; \(\mathbf{x}_{ij}\) is where point \(j\) was found in photo \(i\) |
| \(\mathcal{X}\) | set of all true 3D points of a scene (used for normalization) |
| Camera | |
| \(\mathbf{g}_i\) | camera of photo \(i\): 9 numbers \([\mathbf{q}_i, \mathbf{t}_i, \mathbf{f}_i]\) |
| \(\mathbf{q}\) | rotation as a quaternion \((x, y, z, w)\), 4 numbers |
| \(R\) | rotation as a 3×3 matrix, built from \(\mathbf{q}\) |
| \(R^{\top}\) | transpose of \(R\); for a rotation it equals the inverse (undoes the rotation) |
| \(\mathbf{t}\) | translation, 3 numbers. \(\mathbf{X}_{\text{cam}} = R\mathbf{X} + \mathbf{t}\) |
| \(\mathbf{f} = (\theta_w, \theta_h)\) | field of view: how wide the lens sees, horizontally and vertically |
| \(f\), \(f_x, f_y\) | focal length in pixels (how zoomed in). Large \(f\) = narrow view |
| \(c_x, c_y\) | principal point; VGGT assumes the image center \((W/2, H/2)\) |
| \(K\), \(K_i\) | lens matrix (intrinsics), built from \(f_x, f_y, c_x, c_y\). Turns a camera-relative point into pixels |
| \(K^{-1}\) | inverse of \(K\). Turns a pixel into a viewing direction |
| \(\pi\) | perspective division: divide by depth \(z\), so far things appear smaller |
| Parallax | |
| \(Z\) | distance of a point from the camera |
| \(B\) | baseline: distance between two cameras |
| \(d\) | disparity: how far a point shifted between two photos, in pixels |
| Network | |
| \(f(\cdot)\) | the whole VGGT network, as one function |
| \(\mathbf{t}^{I}_i\) | patch tokens of photo \(i\), from DINO |
| \(\mathbf{t}^{g}_i\) | camera token of photo \(i\) |
| \(\mathbf{t}^{R}_i\) | the 4 register tokens of photo \(i\) |
| \(\mathbf{X}_i\) (in attention) | all \(n\) tokens of photo \(i\), stacked: shape \(n \times C\) |
| \(Q, K, V\) (in attention) | query, key, value: what a token looks for, what it offers, what it passes on. This \(K\) is not the lens matrix |
| \(W_Q, W_K, W_V\) | learned matrices that make \(Q, K, V\) from the tokens |
| \(F_i\) | full-resolution feature map inside the dense head |
| Outputs | |
| \(D_i\) | depth map: per pixel, how far in front of the camera (along \(z\)) |
| \(P_i\) | point map: per pixel, 3D position in photo 1's frame |
| \(\Sigma^{D}_i, \Sigma^{P}_i\) | per-pixel confidence for the depth map and the point map |
| \(T_i\) | tracking features: one feature vector per pixel |
| \(\mathbf{y}_q\) | query pixel chosen for tracking |
| \(\mathbf{h}\) | feature read from \(T_q\) at \(\mathbf{y}_q\) |
| \(\mathbf{y}_{j,i}\) | 2D position of query point \(j\) in photo \(i\) |
| \(\tau\) | confidence threshold for keeping a point |
| Loss | |
| \(\mathcal{L}\) | total loss: how wrong the predictions are |
| \(\lambda\) | weight of the track loss (0.05) |
| \(\alpha\) | weight of the uncertainty cost in the depth and point-map loss |
| \(\rho\), \(\rho_\epsilon\), \(\|\cdot\|_\epsilon\) | robust function; here the Huber loss with threshold \(\epsilon\) |
| \(s\) | scale factor: average distance of the true 3D points from the origin |
| Notation | |
| \(\hat{\ }\) (hat) | a prediction. \(\hat{D}\) = predicted depth, \(D\) = true depth |
| \(\mathbb{R}^{a \times b}\) | a grid of real numbers with shape \(a \times b\) |
| \(\|\cdot\|\) | length (size) of a vector, i.e. distance |
| \(\odot\) | multiply element by element (pixel by pixel) |
| \(\nabla\) | gradient: change between neighboring pixels |
| \(^{\top}\) | transpose: swap rows and columns |
| \(\leftarrow\) | replace the left side with the right side |