Moving DanceSaga pose detection onto the device without losing the score

The old DanceSaga pipeline sent camera frames to a server, ran a sparse COCO-style keypoint model on a GPU and sent back a score. Any failure upstream showed up as a frozen dancer on screen. The migration moves inference into the browser and the phone with a denser full-body landmark model. The budget question is not speed: it is what the game does when the model, the GPU or the camera stops cooperating.

Four loops instead of one

The legacy client ran capture, inference, scoring and rendering inside a single animation callback, so one slow inference call stalled the whole frame. The new client splits them apart. Rendering holds a 33 ms frame budget whatever inference is doing, the pose loop publishes its latest skeleton with a timestamp, and scoring only consumes results younger than its tolerance window. When inference falls behind, the avatar interpolates from the last valid skeleton and scoring pauses, so the player is not penalised for a stall they did not cause. The cost is a second clock to reason about and a new class of bugs where stale poses look fresh. What it buys is measurable: a dropped inference frame no longer becomes a dropped render frame.

The part that hurts

Changing the landmark topology invalidates every reference choreography and every scoring threshold calibrated on the old model. Joints do not map one to one, the hip centre is derived differently and confidence lives on another scale, so a move that scored well last season can now score badly with no change in the dancer. Every reference track has to be extracted again and the thresholds retuned against recorded sessions. Our estimate is that roughly a quarter of the migration effort goes into calibration rather than code. There is no shortcut, because running both models side by side during the transition doubles client load on exactly the devices least able to carry it.

The GPU that returns wrong answers

The worst failure is not a crash. On certain mobile drivers the GPU delegate returns well-formed landmarks with plausible confidence and wrong geometry, so nothing throws and the score quietly drifts. The client therefore runs a cheap anatomical check on bone length ratios every frame. When the skeleton breaks anatomy for several consecutive frames, it tears down the GPU delegate, restarts on the CPU path with a lighter model and marks the session score as degraded instead of trusting it silently, and a WebGL context loss takes the same route. The fallback is less accurate, and that is acceptable: a coarse score the player can trust is worth more than a precise one that is wrong.

A rule for the support matrix

If a device cannot hold the frame budget on the CPU fallback path, list it as unsupported rather than degraded, because a fallback that cannot run is only a second way to fail.

Why not keep inference on the server and add redundancy there?

Server redundancy covers server failures, but in a living-room dance session it is the network that breaks most often, and no amount of backend replication fixes a weak Wi-Fi link. Running inference on the device also keeps raw video off the backend, which takes the camera stream out of scope for biometric privacy rules such as GDPR. By our estimate it also removes most of the GPU line from the hosting bill.

Back to DanceSaga - Pose Detection · Domains

← Back to DanceSaga - Pose Detection
Engineering & Architecture Brief

Moving DanceSaga pose detection onto the device without losing the score

The old DanceSaga pipeline sent camera frames to a server, ran a sparse COCO-style keypoint model on a GPU and sent back a score. Any failure upstream showed up as a frozen dancer on screen. The migration moves inference into the browser and the phone with a denser full-body landmark model. The budget question is not speed: it is what the game does when the model, the GPU or the camera stops cooperating.

Four loops instead of one

The legacy client ran capture, inference, scoring and rendering inside a single animation callback, so one slow inference call stalled the whole frame. The new client splits them apart. Rendering holds a 33 ms frame budget whatever inference is doing, the pose loop publishes its latest skeleton with a timestamp, and scoring only consumes results younger than its tolerance window. When inference falls behind, the avatar interpolates from the last valid skeleton and scoring pauses, so the player is not penalised for a stall they did not cause. The cost is a second clock to reason about and a new class of bugs where stale poses look fresh. What it buys is measurable: a dropped inference frame no longer becomes a dropped render frame.

The part that hurts

Changing the landmark topology invalidates every reference choreography and every scoring threshold calibrated on the old model. Joints do not map one to one, the hip centre is derived differently and confidence lives on another scale, so a move that scored well last season can now score badly with no change in the dancer. Every reference track has to be extracted again and the thresholds retuned against recorded sessions. Our estimate is that roughly a quarter of the migration effort goes into calibration rather than code. There is no shortcut, because running both models side by side during the transition doubles client load on exactly the devices least able to carry it.

The GPU that returns wrong answers

The worst failure is not a crash. On certain mobile drivers the GPU delegate returns well-formed landmarks with plausible confidence and wrong geometry, so nothing throws and the score quietly drifts. The client therefore runs a cheap anatomical check on bone length ratios every frame. When the skeleton breaks anatomy for several consecutive frames, it tears down the GPU delegate, restarts on the CPU path with a lighter model and marks the session score as degraded instead of trusting it silently, and a WebGL context loss takes the same route. The fallback is less accurate, and that is acceptable: a coarse score the player can trust is worth more than a precise one that is wrong.

A rule for the support matrix

If a device cannot hold the frame budget on the CPU fallback path, list it as unsupported rather than degraded, because a fallback that cannot run is only a second way to fail.

Technical FAQ: Why not keep inference on the server and add redundancy there?

Server redundancy covers server failures, but in a living-room dance session it is the network that breaks most often, and no amount of backend replication fixes a weak Wi-Fi link. Running inference on the device also keeps raw video off the backend, which takes the camera stream out of scope for biometric privacy rules such as GDPR. By our estimate it also removes most of the GPU line from the hosting bill.

Related Architecture Specifications (DANCEGOAL): rehabanalysis.com · workoutmove.com · fitnessdetection.com

More Technical Articles on flashbackdance.com

Keeping DanceSaga usable when pose inference stops →