Multi-model ยท detector โ ViTPose
ViTPose is top-down: it estimates one person per box. To handle a crowd, first find the people. This pairs YOLOS-tiny (object detection) with ViTPose โ the detector boxes every person, then ViTPose runs on each crop. Two models, one pipeline, entirely on your device.
Loads two models: YOLOS-tiny (~30 MB) for detection and ViTPose (~87 MB) for pose. Cached after first load.
const people = (await detector(image, { threshold })) // YOLOS-tiny
.filter(d => d.label === "person");
for (const d of people) { // one crop per person
const [x, y] = [d.box.xmin, d.box.ymin];
const crop = await image.crop([x, y, d.box.xmax, d.box.ymax]); // ViTPose resizes the whole input,
const box = [[[0, 0, crop.width, crop.height]]]; // so we crop the box ourselves
const { heatmaps } = await model(await processor(crop, { boxes: box }));
const [p] = processor.post_process_pose_estimation(heatmaps, box)[0];
// p.keypoints are in crop-space โ add [x, y] to map back to the full image.
}