image-to-image Β· vision Β· WASM Β· ~444 MB
Depth tells you how far a pixel is; a surface normal tells you which way it faces β the little arrow sticking out of the surface in 3D. Sapiens predicts one normal per pixel from a single photo, giving you the classic pastel normal map that graphics engines use to relight, emboss, and fake geometry. It runs entirely on your device.
| Model | onnx-community/sapiens-normal-0.3b β Sapiens human-centric ViT |
|---|---|
| Task | image-to-image (dense per-pixel prediction) β run via raw ONNX Runtime Web |
| Runtime | onnxruntime-web 1.21 (transformers.js has no sapiens model class) |
| Input | pixel_values [1, 3, 1024, 768] β ImageNet-normalized RGB |
| Output | predicted_normal [1, 3, 512, 384] β a 3D unit vector per pixel (X,Y,Z in camera space) |
| Quantization | int8 (model_quantized.onnx) |
| Backend | WebAssembly (single-threaded on GitHub Pages; no WebGPU needed) |
| Download | ~444 MB, cached after first load |
| License | CC-BY-NC-4.0 (Sapiens, Meta) β non-commercial, attribution; weights loaded unmodified from the canonical onnx-community repo, not re-hosted |
| Web APIs | WebAssembly, Web Workers, OffscreenCanvas, Canvas β all Baseline widely available |
Sapiens is trained on people, so it works best on a photo of a person. Pick a sample or upload your own, then estimate. The pastel colours ARE the geometry: red encodes left/right, green up/down, blue toward/away from the camera.
The model outputs a 3D unit vector per pixel, not a picture. The colours are just those vectors mapped to RGB. The sphere below is the key β every direction a surface can face, coloured the same way. Hover or tap the normal map to read the exact vector at any pixel.
| predicted_normal shape | β |
|---|---|
| picked pixel normal (x, y, z) | hover the map⦠|
| mean normal direction | β |
| pixels predicted | β |
A per-pixel normal map is the single most useful ingredient for making a flat photo behave like a 3D surface β no mesh, no scan, no special hardware. Once you know which way every pixel faces, client-side effects open up that depth alone can't do:
One photo in, a colour-encoded surface-normal map out β read orientation as colour.
Relighting studio β drag a light around and watch the face shade correctly from its normals (an AR-lighting concept).
Three-point light rig β key, fill and rim lights in colour, all driven by the normal field.
Normals + depth β 2.5D relight: shade by orientation, deepen by distance.
transformers.js has no sapiens class, so we run the ONNX graph directly. It's a clean
imageβimage model β normalize in, unit-vector field out:
import * as ort from "onnxruntime-web";
const session = await ort.InferenceSession.create(sapiensBytes, { executionProviders: ["wasm"] });
// image β [1,3,1024,768], ImageNet-normalized
const input = new ort.Tensor("float32", preprocess(image), [1, 3, 1024, 768]);
const { predicted_normal } = await session.run({ pixel_values: input });
// predicted_normal β [1,3,512,384] raw XYZ vectors; L2-normalize per pixel β unit surface normals
// RGB-encode with (n * 0.5 + 0.5) * 255 to get the classic pastel normal map
Inference runs in a Web Worker, and the RGB normal-map composite is built there too (OffscreenCanvas β transferred ImageBitmap), so the ~444 MB model never freezes the page. The unit-normal field is transferred back so relighting and pixel-inspection run without re-inference.