{'fraction_non_alphanumeric': 0.03322420982890993, 'fraction_numerical': 0.016777738805097628, 'mean_word_length': 5.063208884688091, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Self-Supervised Keypoint Discovery in Behavioral Videos

We propose a method for learning the posture and structure of agents from unlabelled behavioral videos. Starting from the observation that behaving agents are generally the main sources of movement in behavioral videos, our method, Behavioral Keypoint Discovery (B-KinD), uses an encoder-decoder architecture with a geometric bottleneck to reconstruct the spatiotemporal difference between video frames. By focusing only on regions of movement, our approach works directly on input videos without requiring manual annotations. Experiments on a variety of agent types (mouse, fly, human, jellyfish, and trees) demonstrate the generality of our approach and reveal that our discovered keypoints represent semantically meaningful body parts, which achieve state-of-the-art performance on keypoint regression among self-supervised methods. Additionally, B-KinD achieve comparable performance to supervised keypoints on downstream tasks, such as behavior classification, suggesting that our method can dramatically reduce model training costs vis-a-vis supervised methods.


Introduction
Automatic recognition of object structure, for example in the form of keypoints and skeletons, enables models to capture the essence of the geometry and movements of objects. Such structural representations are more invariant to background, lighting, and other nuisance variables and are much lower-dimensional than raw pixel values, making them good intermediates for downstream tasks, such as behavior classification [4,11,15,40,44], video alignment [27,45], and physics-based modeling [7,12].
However, obtaining annotations to train supervised pose detectors can be expensive, especially for applications in behavior analysis. For example, in behavioral neuroscience [35], datasets are typically small and lab-specific, and the training of a custom supervised keypoint detector presents a significant bottleneck in terms of cost and effort. Additionally, once trained, supervised detectors often do not generalize well to new agents with different structures without new supervision. The goal of our work is to enable keypoint discovery on new videos without manual supervision, in order to facilitate behavior analysis on novel settings and different agents.
Recent unsupervised/self-supervised methods have made great progress in keypoint discovery [21,22,53] (see also Section 2), but these methods are generally not designed for behavioral videos. In particular, existing methods do not address the case of multiple and/or non-centered agents, and often require inputs as cropped bounding boxes around the object of interest, which would require an additional detector module to run on real-world videos. Furthermore, these methods do not exploit relevant structural properties in behavioral videos (e.g., the camera and the background are typically stationary, as observed in many real-world behavioral datasets [5,15,23,30,35,40]).
To address these challenges, the key to our approach is to discover keypoints based on reconstructing the spatiotemporal difference between video frames. Inspired by previous works based on image reconstruction [21,38], we use an encoder-decoder setup to encode input frames into a geometric bottleneck, and train the model for reconstruction. We then use spatiotemporal difference as a novel reconstruction target for keypoint discovery, instead of single image reconstruction. Our method enables the model to focus on discovering keypoints on the behaving agents, which are generally the only source of motion in behavioral videos.
Our self-supervised approach, Behavioral Keypoint Discovery (B-KinD), works without manual supervision across diverse organisms ( Figure 1). Results show that our discovered keypoints achieve state-of-the-art performance on downstream tasks among other self-supervised keypoint discovery methods. We demonstrate the performance of our keypoints on behavior classification [43], keypoint regression [21], and physics-based modeling [7]. Thus, our method has the potential for transformative impact in behavior analysis: first, one may discover keypoints from behavioral videos for new settings and organisms; second, unlike methods that predict behavior directly from video, our low-dimensional keypoints are semantically meaningful so that users can directly compute behavioral features; finally, our method can be applied to videos without the need for manual annotations.
To summarize, our main contributions are: 1. Self-supervised method for discovering keypoints from real-world behavioral videos, based on spatiotemporal difference reconstruction. 2. Experiments across a range of organisms (mice, flies, human, jellyfish, and tree) demonstrating the generality of the method and showing that the discovered keypoints are semantically meaningful. 3. Quantitative benchmarking on downstream behavior analysis tasks showing performance that is comparable to supervised keypoints.
Pose estimation models that were developed for behavioral videos [16,31,36,40] require human annotations of anatomically defined keypoints, which are expensive and time-consuming to obtain. In addition to the cost, not all data can be crowd-sourced due to the sensitive nature of some experiments. Furthermore, organisms that are translucent (jellyfish) or with complex shapes (tree) can be difficult for non-expert humans to annotate. Our goal is to enable keypoint discovery on videos for behavior analysis, without the need for manual annotations.
After pose estimation, behavior analysis models generally compute trajectory features and train behavior classifiers in a fully supervised fashion [5,15,18,40,44]. Some works have also explored using unsupervised methods to discover new motifs and behaviors [3,19,29,52]. Here, we apply our discovered keypoints to supervised behavior classification and compare against baseline models using supervised keypoints for this task.
Keypoint Estimation. Keypoint estimation models aim to localize a predefined set of keypoints from visual data, and many works in this area focus on human pose. With the success of fully convolutional neural networks [41], recent methods [8,33,46,51] employ encoder-decoder networks by predicting high-resolution outputs encoded with 2D Gaussian heatmaps representing each part. To improve model performance, [33,46,51] propose an iterative refinement approach, [8,37] design efficient learning signals, and [9,49] exploit multi-resolution information. Beyond human pose, there are also works that focus on animal pose estimation, notably [16,31,36]. Similar to these works, we also use 2D Gaussian heatmaps to represent parts as keypoints, but instead of using human-defined keypoints, we aim to discover keypoints from video data without manual supervision.
Unsupervised Part Discovery. Though keypoints provide a useful tool for behavior analysis, collecting annotations is time-consuming and labor-intensive especially for new domains that have not been previously studied. Unsupervised keypoint discovery [21,22,53] has been proposed to reduce keypoint annotation effort and there have been Figure 2. B-KinD, an approach for keypoint discovery from spatiotemporal difference reconstruction. It and It+T are video frames at time t and t + T . Both frame It and frame It+T are fed to an appearance encoder Φ and a pose decoder Ψ. Given the appearance feature from It and geometry features from both It and It+T (Sec 3.1), our model reconstructs the spatiotemporal difference (Sec 3.2.1) computed from two frames using the reconstruction decoder ψ. many promising results on centered and/or aligned objects, such as facial images and humans with an upright pose. These methods train and evaluate on images where the object of interest is centered in an input bounding box. Most of the approaches [21,28,53] use an autoencoder-based architecture to disentangle the appearance and geometry representation for the image reconstruction task. Our setup is similar in that we also use an encoder-decoder architecture, but crucially, we reconstruct spatiotemporal difference between video frames, instead of the full image as in previous works. We found that this enables our discovered keypoints to track semantically-consistent parts without manual supervision, requiring neither keypoints nor bounding boxes.
There are also works for parts discovery that employ other types of supervision [22,38,39]. For example, [38] proposed a weakly-supervised approach using class label to discriminate parts to handle viewpoint changes, [22] incorporated pose prior obtained from unpaired data from different datasets in the same domain, and [39] proposed a template-based geometry bottleneck based on a pre-defined 2D Gaussian-shaped template. Different from these approaches, our method does not require any supervision beyond the behavioral videos. We chose to focus on this setting since other supervisory sources are not readily available for emerging domains (ex: jellyfish, trees).
In previous works, keypoint discovery has been applied to downstream tasks, such as image and video generation [22,32], keypoint regression to human-annotated poses [21,53], and video-level action recognition [26,32]. While we also apply keypoint discovery to downstream tasks, we note that our work differs in approach (we discover keypoints directly on behavioral videos using spatiotemporal difference reconstruction), focus (behavioral videos of diverse organisms), and application (real-world behavior analysis tasks [7,43]).

Method
The goal of B-KinD ( Figure 2) is to discover semantically meaningful keypoints in behavioral videos of diverse organisms without manual supervision. We use an encoderdecoder setup similar to previous methods [21,38], but instead of image reconstruction, here we study a novel reconstruction target based on spatiotemporal difference. In behavioral videos, the camera is generally fixed with respect to the world, such that the background is largely stationary and the agents (e.g. mice moving in an enclosure) are the only source of motion. Thus spatiotemporal differences provide a strong cue to infer location and movements of agents.

Self-supervised keypoint discovery
Given a behavioral video, our work aims to reconstruct regions of motion between a reference frame I t (the video frame at time t) and a future frame I t+T (the video frame T timesteps later, for some set value of T .) We accomplish this by extracting appearance features from frame I t and keypoint locations ("geometry features") from both frames I t and I t+T (Figure 2). In contrast, previous works [21,22,28,38,39] use appearance features from I t and geometry features from I t+T to reconstruct the full image I t+T (instead of difference between I t and I t+T ).
We use an encoder-decoder architecture, with shared appearance encoder Φ, geometry decoder Ψ, and reconstruction decoder ψ. During training, the pair of frames I t and I t+T are fed to the appearance encoder Φ to generate appearance features, and those features are then fed into the geometry decoder Ψ to generate geometry features. In our approach, the reference frame I t is used to generate both appearance and geometry representations, and the future frame I t+T is only used to generate a geometry representation. The appearance feature h t a for frame I t are defined simply as the output of Φ: h t a = Φ(I t ). The pose decoder Ψ outputs K raw heatmaps X i ∈ R 2 , then applies a spatial softmax operation on each heatmap channel. Given the extracted p i = (u i , v i ) locations for i = {1, . . . , K} keypoints from the spatial softmax, we define the geometry features h t g to be a concatenation of 2D Gaussians centered at (u i , v i ) with variance σ.
Finally, the concatenation of the appearance feature h t a and the geometry features h t g and h t+T g is fed to the decoder ψ to reconstruct the learning objectiveŜ discussed in the next section:Ŝ = ψ(h t a , h t g , h t+T g ).

Spatiotemporal difference
Our method works with different types of spatiotemporal differences as reconstruction targets. For example: Structural Similarity Index Measure (SSIM) [50]. This is a method for measuring the perceived quality of the two images based on luminance, contrast, and structure features. To compute our reconstruction target based on SSIM, we apply the SSIM measure locally on corresponding patches between I t and I t+T to build a similarity map between frames. Then we compute dissimilarity by taking the negation of the similarity map.
Frame differences. When the video background is static with little noise, simple frame differences, such as absolute difference (S |d| = |I t+T − I t |) or raw difference (S d = I t+T − I t ), can also be directly applied as a reconstruction target.

Reconstruction loss
We apply perceptual loss [24] for reconstructing the spatiotemporal difference S. Perceptual loss compares the L2 distance between the features computed from VGG network ϕ [42]. The reconstructionŜ and the target S are fed to VGG network, and mean squared error is applied to the features from the intermediate convolutional blocks: (1)

Rotation equivariance loss
In cases where agents can move in many directions (e.g. mice filmed from above can translate and rotate freely), we would like our keypoints to remain semantically consistent. We enforce rotation-equivariance in the discovered keypoints by rotating the image with different angles and imposing that the predicted keypoints should move correspondingly. We apply the rotation equivariance loss (simi-+ Figure 3. Behavior Classification Features. Extracting information from the raw heatmap (Section 3.3): the confidence scores and the covariance matrices are computed from normalized heatmaps. Note that the features are computed for all x, y coordinates. We visualize the zoomed area around the target instance for illustrative purposes.
lar to the deformation equivariance in [48]) on the generated heatmap. Given reference image I and the corresponding geometry bottleneck h g , we rotate the geometry bottleneck to generate pseudo labels h R • g for rotated input images We apply mean squared error between the predicted geometry bottlenecksĥ g from the rotated images and the generated pseudo labels h g : (2)

Separation loss
Empirical results show that rotation equivariance encourages the discovered keypoints to converge at the center of the image. We apply separation loss to encourage the keypoints to encode unique coordinates, and prevent the discovered keypoints from being centered at the image coordinates [53]. The separation loss is defined as follows:

Final objective
Our final loss function is composed of three parts: reconstruction loss L recon , rotation equivariance loss L r , and separation loss L s : We adopt curriculum learning [2] and apply L r and L s once the keypoints are consistently discovered from the semantic parts of the target instance.

Feature extraction for behavior analysis
Following standard approaches [5,18,40], we use the discovered keypoints from B-KinD as input to a behavior quantification module: either supervised behavior classifiers or a physics-based model. Note that this is a separate process from keypoint discovery; we feed discovered geometry information into a downstream model.
In addition to discovered keypoints, we extracted additional features from the raw heatmap ( Figure 3) to be used as input to our downstream modules. For instance, we found that the confidence and the shape information from the of the network prediction of keypoint location was informative. When a target part is well localized, our keypoint discovery network produces a heatmap with a single high peak with low variance; conversely, when a target part is occluded, the raw heatmap contains a blurred shape with lower peak value. This "confidence" score (heatmap peak value) is also a good indicator for whether keypoints are discovered on the background (blurred over the background with low confidence) or tracking anatomical body parts (peaked with high confidence), visualized in Supplementary materials. The shape of a computed heatmap can also reflect shape information of the target (e.g. stretching).
Given a raw heatmap X k for part k, the confidence score is obtained by choosing the maximum value from the heatmap, and the shape information is obtained by computing the covariance matrix from the heatmap. Figure 3 visualizes the features we extract from the raw heatmaps. Using the normalized heatmap as the probability distribution, additional geometric features are computed:

Experiments
We demonstrate that B-KinD is able to discover consistent keypoints in real-world behavioral videos across a range of organisms (Section 4.1.1). We evaluate our keypoints on downstream tasks for behavior classification (Section 4.2) and pose regression (Section 4.3), then illustrate additional applications of our keypoints (Section 4.4). [43] is a large-scale dataset for behavior analysis consisting of videos and trajectory data from a pair of interacting mice. Every frame is annotated by an expert for three behaviors: sniff, attack, mount. There are 507k frames in the train split, and 262k frames in the test split (video frame: 1024 × 570, mouse: approx 150 × 50). We use only the train split on videos without miniscope cable to train B-KinD. Following [43], the downstream behavior classifier is trained on the entire training split, and performance is evaluated on the test split.

Experimental setting
MARS-Pose. This dataset consists of a set of videos with similar recording conditions to the CalMS21 dataset. We use a subset of the MARS pose dataset [40] with keypoints from manual annotations to evaluate the ability of our model to predict human-annotated keypoints, with {10, 50, 100, 500} images for train and 1.5k images for test.
Fly vs. Fly. These videos consists of interactions between a pair of flies, annotated per frame by domain experts. We use the Aggression videos from the Fly vs. Fly dataset [15], with the train and test split having 1229k and 322k frames respectively (video frame: 144 × 144, fly: approx 30 × 10). Similar to [44], we evaluate on behaviors of interest with more than 1000 frames in the training set (lunge, wing threat, tussle).
Human 3.6M. Human 3.6M [20] is a large-scale motion capture dataset, which consists of 3.6 million human poses and images from 4 viewpoints. To quantitatively measure the pose regression performance against baselines, we use the Simplified Human 3.6M dataset, which consists of 800k training and 90k testing images with 6 activities in which the human body is mostly upright. We follow the same evaluation protocol from [53] to use subjects 1, 5, 6, 7, and 8 for training and 9 and 11 for testing. We note that each subject has different appearance and clothing.
Jellyfish. The jellyfish data is an in-house video dataset containing 30k frames of recorded swimming jellyfish (video frame: 928×1158, jellyfish: approx 50 pix in diameter). We use this dataset to qualitatively test the performance of B-KinD on a new organism, and apply our keypoints to detect the pulsing motion of the jellyfish.
Vegetation. This is an in-house dataset acquired over several weeks using a drone to record the motion of swaying trees. The dataset consists of videos of an oak tree and corresponding wind speeds recorded using an anemometer, with a total of 2.41M video frames (video frame: 512×512, oak tree: varies, approx 1 4 of the frame). We evaluate this dataset using a physics-based model [7] that relates the visually observed oscillations to the average wind speeds.

Training and evaluation procedure
We train B-KinD using the full objective in Section 3.2.5. During training, we rescale images to 256 × 256 and use T of around 0.2 seconds, except Human3.6M, where we use After training the keypoint discovery model, we extract the keypoints and use it for different evaluations based on the labels available in the dataset: behavior classification (CalMS21, Fly), keypoint regression (MARS-Pose, Human), and physics-based modeling (Vegetation).
For keypoint regression, similar to previous works [21,22], we compare our regression with a fully supervised 1stack hourglass network [33]. We evaluate keypoint regression on Simplified Human 3.6M by using a linear regressor without a bias term, following the same evaluation setup from previous works [28,53]. On MARS-Pose, we train our model in a semi-supervised fashion with 10, 50, 100, 500 supervised keypoints to test data efficiency. For behavior classification, we evaluate on CalMS21 and Fly, using available frame-level behavior annotations. To train behavior classifiers, we use the specified train split of each dataset. For CalMS21 and Fly, we train the 1D Convolutional Network benchmark model provided by [43] using B-KinD keypoints. We evaluate using mean average precision (MAP) weighted equally over all behaviors of interest.

Behavior classification results
CalMS21 Behavior Classification. We evaluate the effectiveness of B-KinD for behavior classification (Table 1). Compared to supervised keypoints trained for this task, our keypoints (without manual supervision) is comparable when using both pose and confidence as input. Compared to other self-supervised methods, even those that use bounding boxes, our discovered keypoints on the full image generally achieve better performance.
Keypoints discovered with image reconstruction, similar to baselines [21,38] cannot track the agents well without using bounding box information ( Figure 4) and does not per- .880 ± .005 Self-supervised Jakab et al. [21] ✓ .186 ± .008 Image Recon. Table 1. Behavior Classification Results on CalMS21. "Ours" represents classifiers using input keypoints from our discovered keypoints. "conf" represents using the confidence score, and "cov" represents values from the covariance matrix of the heatmap. † refers to models that require bounding box inputs before keypoint estimation. Mean and std dev from 5 classifier runs are shown.
.500 ± .024 Image Recon. bbox † .750 ± .020 Ours .727 ± .022 Table 2. Behavior Classification Results on Fly. "FlyTracker" represents classifiers using hand-crafted inputs from [15]. The self-supervised keypoints all use the same "generic features" computed on all keypoints: speed, acceleration, distance, and angle. † refers to models that require bounding box inputs before keypoint estimation. Mean and std dev from 5 classifier runs are shown.
form well for behavior classification (Table 1). When we provide bounding box information to the model based on image reconstruction, the performance is significantly improved, but this model does not perform as well as B-KinD keypoints from spatiotemporal difference reconstruction. For the per-class performance (see the Supplementary materials), the biggest gap exists between B-KinD and MARS on the "attack" behavior. This is likely because during attack, the mice are moving quickly, and there exists a lot of motion blur and occlusion which is difficult to track without supervision. However, once we extract more information from the heatmap, through computing keypoint confidence, our keypoints perform comparably to MARS.
Fly Behavior Classification. The FlyTracker [15] uses hand-crafted features computed from the image, such as contrast, as well as features from tracked fly body parts, Number Training Samples Keypoint Data Efficiency (PCK at 0.5cm) Figure 5. Keypoint data efficiency on MARS-Pose. The supervised model is based on [40] using stacked hourglass [33], while the semi-supervised model uses both our self-supervised loss and supervision. PCK is computed at 0.5cm threshold, averaged across nose, ears, and tail keypoints, over 3 runs. "b" and "w" indicates the black and white mouse respectively. such as wing angle or distance between flies. Using discovered keypoints, we compute comparable features without assuming keypoint identity, by computing speed and acceleration of every keypoint, distance between every pair, and angle between every triplet. For all self-supervised methods, we use keypoints, confidence, and covariance for behavior classification. Results demonstrate that while there is a small gap in performance to the supervised estimator, our discovered keypoints perform much better than image reconstruction, and is comparable to models that require bounding box inputs (Table 2).

Pose regression results
MARS Pose Regression. We evaluate the pose estimation performance of our method in the setting where some human annotated keypoints exist ( Figure 5). For this experiment, we train B-KinD in a semi-supervised fashion, where the loss is a sum of both our keypoint discovery objective (Section 3.2.5) as well as standard keypoint estimation objectives based on MSE [40]. For both black and white mouse, when using our keypoint discovery objective in a semi-supervised way during training, we are able to track keypoints more accurately compared to the supervised method [40] alone. We note that the performance of both methods converge at around 500 annotated examples.
Simplified Human 3.6M Pose Regression. To compare with existing keypoint discovery methods, we evaluate our discovered keypoints on Simplified Human3.6M (a standard benchmarking dataset) by regressing to annotated keypoints (Table 3). Though our method is directly applicable to full images, we train the discovery model using cropped bounding box for a fair comparison with baselines, which all use cropped bounding boxes centered on the subject. Compared to both self-supervised + prior information and self-supervised + regression, our method shows state-  of-the-art performance on the keypoint regression task, suggesting spatiotemporal difference is an effective reconstruction target for keypoint discovery.
Learning Objective Ablation Study We report the pose regression performance on Simplified Human3.6M (Table 4) by varying the spatiotemporal difference reconstruction target for training B-KinD. Here, image reconstruction also performs well since cropped bounding box is used as an input to the network. Overall, spatiotemporal difference reconstruction yield better performance over image reconstruction, and performance can be further improved by extracting additional confidence and covariance information from the discovered heatmaps.

Additional applications
We show qualitative performance and demonstrate additional downstream tasks using our discovered keypoints, on pulse detection for Jellyfish and on wind speed regression for Vegetation.
Qualitative Results. Qualitative results ( Figure 6) demonstrates that B-KinD is able to track some body parts consistently, such as the nose of both mice and keypoints Pulse Detection. Jellyfish swimming is among the most energetically efficient forms of transport, and its control and mechanics are studied in hydrodynamics research [10]. Of key interest is the relationship between body plan and swim pulse frequency across diverse jellyfish species. By computing distance between B-KinD keypoints, we are able to extract a frequency spectrogram to study jellyfish pulsing, with a visible band at the swimming frequency (Supplementary materials). This provides a way to automatically annotate swimming behavior, which could be quickly applied to video from multiple species to characterize the relationship between swimming dynamics and body plan.
Wind Speed Modeling. Measuring local wind speed is useful for tasks such as tracking air pollution and weather forecasting [6]. Oscillations of trees encode information on wind conditions, and as such, videos of moving trees could function as wind speed sensors [6,7]. Using the Vegetation dataset, we evaluate the ability of our keypoints to predict wind speed using a physics-based model [7]. This model defines the relationship between the mean wind speed and the structural oscillations of the tree, and requires tracking these oscillations from video, which was previously done manually. We show that B-KinD can accomplish this task automatically. Using our keypoints, we are able to regress the measured ground truth wind speed with an R 2 = 0.79, suggesting there is a good agreement between the proportionality assumption from [7] and the experimental results using the keypoint discovery model.
Limitations. One issue we did not explore in detail, and which will require further work, is keypoint discovery for agents that may be partially or completely occluded at some point during observation, including self-occlusion. Additionally, similar to other keypoint discovery models [28,39,53], we observe left/right swapping of some body parts, such as the legs in a walking human. One approach that might overcome these issues would be to extend our model to discover the 3D structure of the organism, for instance by using data from multiple cameras. Despite these challenges, our model performs comparably to supervised keypoints for behavior classification.

Discussion and conclusion
We propose B-KinD, a self-supervised method to discover meaningful keypoints from unlabelled videos for behavior analysis. We observe that in many settings, behavioral videos have fixed cameras recording agents moving against a (quasi) stationary background. Our proposed method is based on reconstructing spatiotemporal difference between video frames, which enables B-KinD to focus on keypoints on the moving agents. Our approach is general, and is applicable to behavior analysis across a range of organisms without requiring manual annotations.
Results show that our discovered keypoints are semantically meaningful, informative, and enable performance comparable to supervised keypoints on the downstream task of behavior classification. Our method will reduce the time and cost dramatically for video-based behavior analysis, thus accelerating scientific progress in fields such as ethology and neuroscience.

Acknowledgements
This work was generously supported by the Simons Collaboration on the Global Brain grant 543025 (to PP and DJA), NIH Award #R00MH117264 (to AK), NSF Award #1918839 (to YY), NSF Award #2019712 (to JOD and RHG), NINDS Award #K99NS119749 (to BW), NIH Award #R01MH123612 (to DJA and PP), NSERC Award #PGSD3-532647-2019 (to JJS), as well as a gift from Charles and Lily Trimble (to PP).

Supplementary Material
We present additional experimental results (Section A), additional implementation details (Section B), and visualizations (Section C). Additional video visualizations and code are available in the project website: https://sites.google. com/view/b-kind.
Benefits and risks of this technology. Automating the analysis of behavior is useful across many fields: in neuroscience, to study the neural control of behavior; in ethology and conservation, to study animal behavior and their response to human encroachment; in rehabilitation, to track patients' recovery of motor function; and in helping improve safety in the workplace. Risks are inherent in any application where humans behavior is analyzed, and care must be taken to respect privacy and human rights. Responsible use in research requires following all applicable rules and policies, including filing for permission with the relevant internal review board (IRB), and obtaining written informed consent from human subjects being filmed.

A.1. CalMS21 Ablation Study
Similar to the main paper, we evaluate CalMS21 on the behavior classification train/test split described in task 1 [43], and show results using Mean Average Precision (MAP) across the annotated behavior classes. We use B-KinD keypoints as input to behavior classification to compare against supervised and other self-supervised baselines.
Effect of Hyperparameters. For all experiments on CalMS21, we use a frame gap of 6 with 10 discovered keypoints. Here, we vary the number of discovered keypoints and frame gap for our model, and apply the learned keypoints to behavior classification (Table 5). There are small variations in performance, in particular, the downstream performance generally improves with increasing the number of keypoints, and a frame gap of 6 or 12 works better than larger frame gaps. We note that the number of low confidence background keypoints also increases with the number of discovered keypoints (Figure 7), and due to the large proportion of background keypoints, we do not use background keypoints in the 20 keypoints case for the classification task. In all cases, we note that we do better than other self-supervised baselines even with bounding box information (MAP = .819) for this task.
Varying Amount of Unlabeled Video Data. We vary the amount of input data (unlabelled image pairs) used to train B-KinD, and observe comparable performance at different amounts of data availability (Table 6). In particular, we are able to achieve comparable performance on behavior classification to supervised keypoints (Table 8) by using only 7.8k input training pairs in our model (approximately 4 minutes of video recorded at 30Hz; approximately 30 minutes of video considering no overlaps on selected image pairs). We note that this experiment is varying the amount of unlabelled data for training the keypoint discovery model, while the train/test split for evaluating the behavior classifier stays the same.
Loss Ablation Study. We compare B-KinD trained with the full objective (reconstruction, rotation equivariance, separation) to one trained only on spatiotemporal difference reconstruction ( Table 7). The rotation equivariance loss is qualitatively important for tracking semantically consistent parts of the mouse (Figure 8) and the separation loss prevents the model from predicting keypoints at the center of the image, which are rotationally consistent but do not track semantic body parts. The full objective is important to achieving comparable performance to supervised baselines. We would like to note that the image reconstruction baselines in our main results are also trained with the full objective, except the reconstruction is based on image reconstruction. Additionally, since keypoint locations are not consistent for spatiotemporal difference reconstruction only, we note that adding confidence and covariance significantly improves the performance of the reconstruction loss only model (Table 7).
Single Geometry Branch. Our proposed model extracts appearance features from the frame at time t, and two geometry features (the keypoints), where one is for frame at time t and the other is for frame at time t + k. It is also possible to train the model using only one geometry branch only for the frame at time t + k, without the geometry branch for time t. On CalMS21, training B-KinD with one geometry branch reduced the classification performance from MAP of 0.852 ± 0.013 (full model) to 0.835 ± 0.013 (single branch).

No rotation
With rotation Figure 8. Qualitative Results on CalMS21 for loss ablation study. With the full training objective for our discovered keypoints, we are able to track 8/10 keypoints consistently, while without rotation loss, there are only 5/10 tracked keypoints on both mice. Additionally, some of the discovered keypoints without rotation are not semantically consistent (for example, the pink and orange keypoints, two keypoints on the body of the white mouse, shift in order as the white mouse moves around). See quantitative results in Table 7.

CalMS21
Pose  Table 8. Per-Class Behavior Classification Results on CalMS21. "Ours" represents classifiers using input keypoints from B-KinD. "conf" represents using the confidence score, and "cov" represents values from the covariance matrix of the heatmap. † refers to models that require bounding box inputs before keypoint estimation. Mean and standard dev from 5 classifier runs are shown.

A.2. CalMS21 Per-Class Performance
B-KinD keypoints achieve comparable performance to supervised keypoints when using pose and confidence features from the heatmap (Table 8). For both supervised keypoints and our keypoints, the behavior classes with the biggest improvement when adding confidence features is on the "Attack" class, which contains frames with occlusion and motion blur since the mice are moving quickly and chasing/tussling. Heatmap confidence and covariance values provides more information about the detected part ( Figure 16). For example, when a part is well localized (ex: visible nose of mouse), our keypoint discovery network produces a heatmap with a single high peak with low variance; conversely, when a target part is occluded, the heatmap contains a blurred shape with lower peak value. We note that performance is similar for the supervised keypoints and our keypoints on the "Investigation" and "Mount" classes.

A.3. Human3.6M Ablation Study
We evaluate the effect of number of keypoints and frame gaps on simplified Human 3.6M (Table 9). Note that we use frame difference, instead of SSIM, as a reconstruction target for studying the effect of hyperparameters. When the frame gap is too small, the region of motion becomes too narrow, which results in slightly lower performance. Also, discovering more keypoints does not always guarantee better performance. Empirical results show that informative keypoints are discoverable with 16 keypoints.  Table 9. Hyperparameters Study on Simplified Human 3.6M. %-MSE error from a single run is shown. For frame gap experiments, the number of keypoints is set to 16. Frame gap is set to 20 for experiments with a varying number of keypoints. We use frame difference here as a reconstruction target for studying the effect of hyperparameters.
swim pulse frequency swimming swimming pause Figure 9. Spectrogram from Distance of Discovered Keypoints. From a recorded video of jellyfish swimming at 48Hz, we discover keypoints at each frame using our model and compute a spectrogram based on the average distance between discovered keypoints on the jellyfish.
We also perform an ablation study using a single geometry branch at time t + k for two different reconstruction targets (image and SSIM), using the same %-MSE error metric as the main paper. Training with one geometry branch reduced the pose regression performance from 2.534 ± 0.056 to 2.596 ± 0.1089 (image) and 2.556 ± 0.0320 (SSIM) where the standard deviation is computed over 5 runs. As a loss ablation study, we train our model without the rotation equivariance loss on simplified Human 3.6M, and the pose regression performance is reduced to 2.61.

A.4. Jellyfish Pulse Detection
The energy efficiency of swimming jellyfish combined with their structural simplicity makes them a good organism for understanding the hydrodynamics of animal propulsion [10]. In particular, researchers would like to study the relationship between body plan and swim pulse frequency across jellyfish species. This has applications in ethology, hydrodynamics, as well as bio-inspired vehicles. Here, we use Clytia hemisphaerica as our jellyfish species to study jellyfish pulsing during swimming using our discovered keypoints. After videos are recorded from a swimming jellyfish from in a tank, we apply our keypoint discovery model to track keypoints automatically on the jellyfish (visualization provided in project website). We also compute the swim pulse frequency by computing the distance between all pairs of our discovered keypoints with high confidence (5 keypoints) and extracting a frequency spectrogram based on average keypoint distance (Figure 9). We observe a visible band at the swimming frequency around 7Hz, and we note that between 110 to 200 seconds, the jellyfish is not swimming (floating), and thus the swimming frequency band is not visible in that duration. Since our discovered keypoints are able to detect pulsing, this provides a way to automatically annotate swimming behavior. This method can be applied to videos from other jellyfish species to study the relationship between swimming dynamics and body plan.

A.5. Vegetations Wind Speed Regression
Videos of oscillation of tree branches and leaves encode information on local wind conditions, and could function as wind speed sensors. Local wind speed measurements are useful for a variety of tasks, including air pollution monitoring, weather forecasting, and predicting movement of forest fires [6,7]. We use the Vegetation dataset to study the effectiveness of our discovered keypoints for capturing oscillating movement of trees. This dataset consists of videos of swaying trees Figure 10. Wind Speed Regression from Discovered Keypoints. Mean wind speed,Ū , vs. the fourth root of the sway amplitude equivalent measured from the standard deviation of the convex hull area of the 15 discovered keypoints in each clip, based on model from [7]. The scatter represents 10-mintute averages of the same data used for training the keypoint model. The black lines represent the best linear regression fit for the proportionality assumption. The proportionality coefficient and the R 2 values are presented in the legend.
recorded from an overhead camera from a drone, while the wind speed is measured using an anemometer. We observe that the discovered keypoints from our approach are of different parts of the tree in separate views but are consistent within a single clip, as to capture oscillations of branches/leaves (visualization provided in project website).
We use a physics-based model [7] to study the relationship between oscillations of trees and wind speed. This model defines the relationship between structural oscillation and wind speed as: where σ is the standard deviation of the amplitude of the structural oscillations,Ū is the mean wind speed, and I u is the measure of the turbulence intensity of the streamwise component, defined as the standard deviation of the streamwise velocity fluctuations normalized to the mean wind speed. The model requires tracing of the structural oscillations of the branches/leaves, which was previously done manually and we show that the keypoint discovery model can do this automatically. The 15 detected keypoints track these oscillations in a 2D space and a representative measure of these oscillations in both coordinates is calculated using the convex hull area, or the sway amplitude equivalent, ϕ. The average sway amplitude equivalent of the keypoints,φ, provides the following proportionality relationship: where C 0 is the coefficient of proportionality. The best regression fit of the experimental data calculated using the least squares method has R 2 = 0.79 suggesting there is a good agreement between the proportionality assumption and the experimental results using the keypoint detection model (Figure 10).

B. Additional Implementation Details
Architecture Details Our method uses ResNet-50 [17] as an encoder Φ, GlobalNet [8] as a pose decoder Ψ, and a series of convolution blocks as a reconstruction decoder ψ, following the unsupervised keypoint discovery model from [38]. Architecture details about reconstruction decoder is shown in Table 10. For more implementation details, the code is available on our project website: https://sites.google.com/view/b-kind.
The hyperparameters for the keypoint discovery model is included in Table 11. All models use SSIM image as the reconstruction target, unless stated otherwise. All keypoint discovery models are trained until convergence of the training loss on a NVIDIA V100 Tensor Core GPU. Below, we include a additional details on the keypoint discovery model and downstream task used to evaluate each dataset. CalMS21. The CalMS21 dataset [43] consists of videos and trajectory data from a pair of interacting mice, annotated with behavior labels at each frame by neuroscientists. There is one black mouse and one white mouse engaging in social behaviors, recorded at 1024 × 570 at 30 Hz. The supervised keypoints provided with CalMS21 are from the MARS detector [40] developed for this dataset, which detects 7 anatomically-defined keypoints for each mouse. For training keypoint discovery, we use a subset of the training split without miniscope cable (26k images), and we use the full train/test split defined by [43] on Task 1 for evaluating behavior classification. For behavior classification, we use the same setup (1D Conv Net architecture, hyperparameters, random seeds, data split, etc.) as the CalMS21 dataset benchmarks, except we replace the supervised input keypoints with our discovered keypoints for evaluation. We additionally experiment with adding heatmap confidence and convariance during classification by appending these additional features to input keypoints during classifier training. This dataset is available under the CC-BY-NC-SA license.
MARS-Pose. MARS-Pose is a set of mouse interaction images with human keypoint annotations [40] and these images are recorded in similar recording conditions to CalMS21 [43]. We use a subset of the images for training (10,50,100,500) and test on the full 1.5k images test set. We evaluate this dataset based on pose estimation performance to the human-annotated keypoints. For the supervised model, we use the stacked hourglass model [33] and for the semi-supervised model, we add a supervised keypoint estimation loss based on MSE to our keypoint discovery framework.
Fly vs. Fly. This dataset consists of videos of two interacting flies [15] with frame-level behavior annotations. We use the "Aggression" videos from this dataset (144 × 144 at 30 Hz) and use the behaviors with more than 1000 annotated training samples, with the same setup as [44]. The provided FlyTracker with this dataset computes hand-crafted behavioral features directly from video for behavior classification. Since keypoints may be discovered from any body part, we compute corresponding generic features not based on keypoint identity: speed of every keypoint, acceleration of every keypoint, distance between every pair, and angle between every triplet. Additionally, since the flies are similar in appearance, when extracting keypoint locations from the B-KinD heatmaps, we detect 2 max locations for the 2 peaks. We then take the spatial softmax over the region around each max location, instead of taking the spatial softmax over the whole heatmap. In terms of identity, we always use the fly with smaller y values at centroid as the first fly, and the fly with larger y values as the second. For the classifier model, we use the same setup (1D Conv Net architecture (except frame gap in the Conv Net is 1 instead of 2 since flies have faster behaviors), hyperparameters, random seeds, data split, etc.) as the CalMS21 dataset benchmarks, except using the fly features as input to classify annotated behavior at each frame. This dataset is available under the CC0 1.0 Universal license.
Human3.6M. Human 3.6M dataset [20] is a large-scale dataset containing 3.6 million 3D and 2D human poses with corresponding images. The videos are taken from 4 different viewpoints for 17 scenarios (discussion, taking photo, walking, ...) with the same background. This dataset is available for academic use, and the dataset license is provided by the Human 3.6M authors on the dataset website, link available within [20]. Simplified Human 3.6M dataset, introduced by [ static background assumption, we crop a pair of full images using the same bounding box for training a keypoint discovery model. The final image has 128×128 resolution. We evaluate the pose regression performance on the same testing set from the Simplified Human 3.6M dataset.
Jellyfish. This is an in-house video dataset consisting of a freely swimming Clytia hemisphaerica in a water tank. We train and run our keypoint discovery model on the same 30k frames, recorded at 48Hz, to demonstrate our keypoints on new organisms and on detecting swimming frequency. Since the jellyfish is very small (∼ 50 pix) relative to the size of the image (928 × 1158), we first use the SSIM image to identify a rough bounding box around the jellyfish (150 × 150) before re-scaling the input to the keypoint discovery model to 256 × 256. We note that this step would not be necessary given a GPU with more memory, since the jellyfish would still be visible at higher resolutions. More details on the pulse detection is in Section A.4.
Vegetations. This is an in-house video dataset captured from a drone flying overhead of an Oak tree as the tree is swaying in the wind, and local wind speed is recorded using an anemometer. The video frames are processed at 512 × 512 and 120 Hz, and re-scaled to be 256 × 256 for the keypoint discovery model. The drone may shift slightly over the video recording, and we use existing image alignment methods [47] to align video frames before computing the spatiotemporal difference reconstruction target for our method. More details on the wind speed regression is in Section A.5.
Confidence Visualizations. We observe that keypoints discovered on the background and not tracking agent parts generally have very low confidence ( Figure 16). This is because heatmaps of background keypoints are not well-localized, and is spread over the image, thus have a low peak value (low confidence). In comparison, discovered keypoints on body parts (such as the nose), is localized to a specific part of the image and has higher peak values. Additionally, confidence values can provide information on occluded parts. For example, for the nose of the white mouse (third column, first row, Figure 16), the confidence varies from 0.5 ∼ 0.6 when the nose is visible in the first two examples to 0.3 ∼ 0.4 when the nose is harder to see in the last two examples.
Challenges. Difficult examples for our model are visualized in Figure 15. When there is occlusion, such as in the mouse examples, the keypoint is generally discovered on the visible parts, and when there is heavy occlusion, such as from the miniscope cable, discovered keypoint location may be shifted. This is likely why including additional information from the heatmap, such as confidence ( Figure 16) is helpful for behavior classification. We can see similar effects on self-occlusion for humans, and also left-right swapping of some keypoints for when humans are facing towards or away from the camera (this has also been observed with other keypoint discovery models [28,39,53]). Unusual poses may also be difficult, such as when the fly is completely tilted towards the camera in the last column of row 1. Future directions to integrate 3D structure, for instance by using multi-view videos, could help address these issues. Despite this, we note that our current discovery model achieves state-of-the-art results among other self-supervised methods for behavior classification and keypoint regression. Figure 11. Qualitative Results on CalMS21. We observe that keypoints are discovered for noses of both mice and generally along the spine of the mice.   Qualitative Results on Simplified Human 3.6M. We observe that keypoints are generally discovered on visible joints and end points of humans, such as head, elbows, hands, upper legs, knees and feet. We note that there is left/right swapping of body parts, since when the human is facing forwards or backwards, keypoints are generally on the same side.