← All models

image-to-image Β· vision Β· WASM Β· ~444 MB

Surface normals β€” which way does every pixel face?

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.

Heavy model, honest speed. This is a ~444 MB int8 ViT. On WebGPU it would be seconds, but this demo ships the universal CPU (WASM) path β€” so the first estimate takes roughly 60–90 s in single-threaded WebAssembly. That is real, on-device inference, not a canned result. Once the normal map is computed, relighting and inspection are instant (they reuse the cached normals β€” no re-run).

At a glance

Modelonnx-community/sapiens-normal-0.3b β€” Sapiens human-centric ViT
Taskimage-to-image (dense per-pixel prediction) β€” run via raw ONNX Runtime Web
Runtimeonnxruntime-web 1.21 (transformers.js has no sapiens model class)
Inputpixel_values [1, 3, 1024, 768] β€” ImageNet-normalized RGB
Outputpredicted_normal [1, 3, 512, 384] β€” a 3D unit vector per pixel (X,Y,Z in camera space)
Quantizationint8 (model_quantized.onnx)
BackendWebAssembly (single-threaded on GitHub Pages; no WebGPU needed)
Download~444 MB, cached after first load
LicenseCC-BY-NC-4.0 (Sapiens, Meta) β€” non-commercial, attribution; weights loaded unmodified from the canonical onnx-community repo, not re-hosted
Web APIsWebAssembly, Web Workers, OffscreenCanvas, Canvas β€” all Baseline widely available

Run it

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.

Public-domain studio portrait of a seated woman Sample face portrait Another sample face portrait
Drop a photo of a person, or click to choose

Input

Selected photo

Surface normals (RGB-encoded)

See inside

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.

R = X Β· surface faces left ↔ right
G = Y Β· surface faces down ↕ up
B = Z Β· surface faces away ↔ toward you
Estimate a normal map, then hover it to inspect vectors.

Why it matters

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:

Use cases

Basics

One photo in, a colour-encoded surface-normal map out β€” read orientation as colour.

Practical

Relighting studio β€” drag a light around and watch the face shade correctly from its normals (an AR-lighting concept).

Wild

Three-point light rig β€” key, fill and rim lights in colour, all driven by the normal field.

Multi-model

Normals + depth β†’ 2.5D relight: shade by orientation, deepen by distance.

How the API works

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.

References