Demo · DeepLabCut × CEBRA

From pose to action.

DeepLabCut tracks a mouse in an open field. CEBRA turns its pose into a low-dimensional embedding where rearing, grooming and exploring separate, and a small decoder turns it back into actions, as probabilities rather than hard labels. The CEBRA encoder can run right here, in your browser, with PyTorch's ExecuTorch runtime.

From video to action with DeepLabCut and CEBRA

Mouse OFT_39 was never seen in training. Play or scrub the video, or drag the embedding to rotate it.

—0.0 s
CEBRA-Behavior embeddingcomputed with the CEBRA PyTorch API
      —macro F1, whole session
      Activity
      Actions
      Raters
      Motion
      primitives
      Whole clip
      About this demo

      The ethogram has three levels. Actions are the probabilities from a small neural-network decoder (one hidden layer) that reads 31 frames (1.2 s) of the embedding, lightly smoothed for display; curves overlap where the decoder is unsure. The raters scored supported rears, unsupported rears and grooming; Locomote and Pause split the remaining time by body speed (above or below about 0.6 body lengths per second), so that split is a simple rule, not decoded. Activity groups the actions one level up: Explore (locomoting or rearing), Stopped (pausing) and Self-care (grooming). Motion primitives show half a second of DeepLabCut poses (five frames, oldest faintest), aligned to the body axis at the newest frame, without the tail tip. Keypoints are the published DeepLabCut tracking after cleaning: points with low confidence, sudden jumps (far from their 7-frame running median) or overstretched bones (a skeleton constraint) were replaced by interpolation in time, about 3% of all points. The Raters row shows how many of the three human raters chose each label. Embeddings are three-dimensional and computed for all 15,243 frames of the held-out session; the video shows a 150 s excerpt, starting 3 s in. CEBRA-Behavior uses the rater labels of the 19 training mice during training. The macro F1 averages the four rated classes over the whole session.

      Run it in your browser

      Run the model on your own machine.

      The figures above were computed with the CEBRA PyTorch API. Press run and your browser repeats that work itself, with no Python and no server:

      1. Freeze. After training, we export the CEBRA encoder from PyTorch as a fixed graph of operations, with torch.export.
      2. Package. ExecuTorch, PyTorch's runtime for phones and other devices, stores that graph and its weights in one small file (about 60 KB).
      3. Run. Your browser loads the ExecuTorch runtime, built for the web as WebAssembly, and runs the encoder on your GPU through WebGPU, or on the CPU if WebGPU is not available. The small action decoder then runs in plain JavaScript.

      The panel compares every number with the PyTorch result.

      ExecuTorch WebGPU ↗

      Downloads about 1 MB (compressed). ExecuTorch's WebGPU backend is experimental.

      Press run to watch the embedding form here.
      Backend—
      Frames embedded—
      Time—
      Match with PyTorch—
      Decoded actions match PyTorch—

      The embedding above switches to the one your browser computed.

      Watch CEBRA learn

      From a random cloud to actions in 400 steps.

      We saved the model every 100 training steps. Drag the slider to see how each snapshot embeds the held-out mouse: at step 0 (one update from random weights) the points are a shapeless cloud; within a few hundred steps, supported rears pull into their own cluster. Training loss (gray) and the loss on the held-out mouse (amber) fall together, and the held-out F1 (teal) climbs with them. The demo above uses the model at step 400.

      step 400
        How it works

        Three steps, three libraries.

        1

        Track with DeepLabCut

        Body points in every frame, at 25 frames per second. This demo uses the DeepLabCut tracking published with the dataset (13 points). For a new top-view video, the pretrained SuperAnimal-TopViewMouse model gives keypoints with no labeling or training. We align each pose to the body axis, scale it by body length, and add the distance to the arena walls.

        import deeplabcut
        deeplabcut.video_inference_superanimal(
            ["my_mouse.mp4"], "superanimal_topviewmouse",
            model_name="hrnet_w32",
            detector_name="fasterrcnn_mobilenet_v3_large_fpn")
        2

        Embed with CEBRA

        A convolutional encoder sees a short window of poses (0.4 s) and maps it to a point on a 3D sphere. Contrastive learning pulls together frames that share an action label (CEBRA-Behavior). A small neural network then reads 1.2 s of the embedding and gives the probability of each action.

        import cebra
        model = cebra.CEBRA(model_architecture="offset10-model",
                            output_dimension=3, conditional="time_delta",
                            temperature_mode="constant", temperature=1.0,
                            batch_size=4096, max_iterations=400)
        model.fit(poses, actions)   # CEBRA-Behavior
        embedding = model.transform(poses)
        # decoder: MLP over 31-frame windows of the embedding
        3

        Run anywhere with ExecuTorch

        The trained encoder is exported once and runs in the browser on WebGPU, with a WebAssembly fallback on the CPU.

        ep = torch.export.export(encoder, (windows,))
        pte = to_edge_transform_and_lower(
            ep, partitioner=[WebGPUPartitioner()]).to_executorch()

        Data & credits

        • Videos, DeepLabCut tracking and behavior ratings: Sturman, von Ziegler et al. (2020), Neuropsychopharmacology. Videos on Zenodo (CC BY 4.0); tracking and ratings in DLCAnalyzer (GPL-3.0). We use the 20 open-field sessions rated by three raters, and show a cropped excerpt of OFT_39.
        • SuperAnimal-TopViewMouse: Ye et al. (2024), Nature Communications. The arena features and the 31-frame decoder follow that paper's open-field analysis.
        • CEBRA: Schneider, Lee & Mathis (2023), Nature · cebra.ai
        • DeepLabCut: Mathis et al. (2018), Nature Neuroscience · DeepLabCut page
        • ExecuTorch WebGPU and Wasm runtime: pytorch/executorch v1.6.0 (BSD license).