sgl-project/sglang · error · ValueError

camera trajectory must have shape (F, 4, 4); got {c2w.shape}

Error message

camera trajectory must have shape (F, 4, 4); got {c2w.shape}

What it means

Raised by sana_wm_load_camera when an .npy file loaded from path does not have shape (F, 4, 4) — i.e. not a 3D array of 4x4 camera-to-world matrices, one per frame.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/base.py:227

        if "s" in held:
            move -= forward * translation_speed
        if "d" in held:
            move += right * translation_speed
        if "a" in held:
            move -= right * translation_speed

        current = np.eye(4, dtype=np.float64)
        current[:3, :3] = rotation
        current[:3, 3] = translation + move
        poses.append(current.copy())

    return np.stack(poses, axis=0).astype(np.float32)


def sana_wm_load_camera(path: Path) -> np.ndarray:
    c2w = np.load(path).astype(np.float32)
    if c2w.ndim != 3 or c2w.shape[1:] != (4, 4):
        raise ValueError(
            f"camera trajectory must have shape (F, 4, 4); got {c2w.shape}"
        )
    return c2w


def sana_wm_load_intrinsics(path: Path, num_frames: int) -> np.ndarray:
    arr = np.load(path).astype(np.float32)
    if arr.shape == (4,):
        return np.broadcast_to(arr, (num_frames, 4)).copy()
    if arr.shape == (3, 3):
        vec = np.array([arr[0, 0], arr[1, 1], arr[0, 2], arr[1, 2]], dtype=np.float32)
        return np.broadcast_to(vec, (num_frames, 4)).copy()
    if arr.ndim == 3 and arr.shape[1:] == (3, 3) and arr.shape[0] >= num_frames:
        arr = arr[:num_frames]
        return np.stack(
            [arr[:, 0, 0], arr[:, 1, 1], arr[:, 0, 2], arr[:, 1, 2]], axis=1
        )
    raise ValueError(

View on GitHub (pinned to 0132848349)

Solutions

  1. Export the trajectory as np.stack(c2w_list, axis=0) with each element 4x4
  2. If you have a single pose, tile it: np.repeat(pose[None], F, axis=0)
  3. Verify with arr.shape == (F,4,4) before saving

Example fix

# before
np.save(path, pose)  # (4,)
# after
np.save(path, np.repeat(np.eye(4)[None], num_frames, axis=0))  # (F,4,4)
Defensive patterns

Strategy: validation

Validate before calling

arr = np.load(path)
assert arr.ndim == 3 and arr.shape[1:] == (4, 4), f'{path}: {arr.shape}'

Type guard

def is_trajectory(a) -> bool:
    import numpy as np
    return a.ndim == 3 and a.shape[1:] == (4, 4)

Prevention

When it happens

Trigger: Calling sana_wm_load_camera on an .npy containing a single (4,4) matrix (ndim=2), a (F,3,3) array, or arbitrary arrays. Called from _prepare_static_camera.

Common situations: Saved OpenCV-style w2c matrices instead of c2w; saved a single pose instead of a trajectory; exported (F,4,4) as nested lists that collapsed; wrong file passed as camera path.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/fb03df00697cd93d. Report an issue: GitHub.