Markerless tracking of user-defined features with deep learning

by   Alexander Mathis, et al.
Harvard University

Quantifying behavior is crucial for many applications in neuroscience. Videography provides easy methods for the observation and recording of animal behavior in diverse settings, yet extracting particular aspects of a behavior for further analysis can be highly time consuming. In motor control studies, humans or other animals are often marked with reflective markers to assist with computer-based tracking, yet markers are intrusive (especially for smaller animals), and the number and location of the markers must be determined a priori. Here, we present a highly efficient method for markerless tracking based on transfer learning with deep neural networks that achieves excellent results with minimal training data. We demonstrate the versatility of this framework by tracking various body parts in a broad collection of experimental settings: mice odor trail-tracking, egg-laying behavior in drosophila, and mouse hand articulation in a skilled forelimb task. For example, during the skilled reaching behavior, individual joints can be automatically tracked (and a confidence score is reported). Remarkably, even when a small number of frames are labeled (≈ 200), the algorithm achieves excellent tracking performance on test frames that is comparable to human accuracy.



There are no comments yet.


page 2

page 3

page 4

page 5

page 6

page 7

page 13

page 14


Sperm detection and tracking in phase-contrast microscopy image sequences using deep learning and modified CSR-DCF

Nowadays, computer-aided sperm analysis (CASA) systems have made a big l...

3D Based Landmark Tracker Using Superpixels Based Segmentation for Neuroscience and Biomechanics Studies

Examining locomotion has improved our basic understanding of motor contr...

Learning Policies for Adaptive Tracking with Deep Feature Cascades

Visual object tracking is a fundamental and time-critical vision task. R...

Deep Flow Collaborative Network for Online Visual Tracking

The deep learning-based visual tracking algorithms such as MDNet achieve...

Beyond Tracking: Using Deep Learning to Discover Novel Interactions in Biological Swarms

Most deep-learning frameworks for understanding biological swarms are de...

Haptic human-human interaction does not improve individual visuomotor adaptation

Haptic interaction between two humans, for example, parents physically s...

Feature Based Framework to Detect Diseases, Tumor, and Bleeding in Wireless Capsule Endoscopy

Studying animal locomotion improves our understanding of motor control a...

Code Repositories


Markerless tracking of user-defined features with deep learning

view repo
This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

I Introduction

Accurate quantification of behavior is essential for understanding the brain Tinbergen (1963); Bernstein (1967); Krakauer et al. (2017). Both within and beyond the field of neuroscience, there is a fruitful tradition of using cutting edge technology to study movement. Often, the application of new technology has the potential to reveal unforeseen features of the phenomena being studied, as in the case of Muybridge’s famous photography studies in the mid 19th century, or modern high-speed videography that has revealed previously unknown motor sequences, such as “tap dancing” in the songbird Bernstein (1967); Ota et al. (2015); Wade (2016)

. Historically, collected data was analyzed manually, which is a time-consuming, labor-intensive, and an error-prone process that is prohibitively inefficient at today’s high rates of acquisition. Conversely, advances in computer vision have persistently inspired methods of data analysis to reduce human labor 

Dell et al. (2014); Gomez-Marin et al. (2014); Anderson and Perona (2014).

We are particularly interested in extracting the pose of animals, i.e. the geometrical configuration of multiple body parts. The gold standard for pose estimation in the field of motor control is the combination of video recordings with easily recognizable reflective markers applied to locations of interest, which greatly simplifies subsequent analysis and allows for tracking of body parts with high accuracy 

Winter (2009); Vargas-Irwin et al. (2010); Wenger et al. (2014); Maghsoudi et al. (2017). However, such systems can be expensive, potentially distracting to animals Perez-Escudero et al. (2014); Nakamura et al. (2016), and markers need to be placed before recording, which pre-defines the features that can be tracked. This mitigates one of the benefits of video data, i.e. it’s low level of invasiveness. One alternative to physical markers is to fit skeleton/active contour models de Chaumont et al. (2012); Matsumoto et al. (2013); Perez-Escudero et al. (2014); Nakamura et al. (2016); Uhlmann et al. (2017). These methods can work quite well and are fast, but require sophisticated skeleton models, which are difficult to develop and to fit to data, limiting the flexibility of such methods Felzenszwalb and Huttenlocher (2005); Toshev and Szegedy (2014). Another alternative is training regressors based on various computationally derived features to track particular body parts in a supervised way Dollár et al. (2010); Perez-Escudero et al. (2014); Dell et al. (2014); Machado et al. (2015); Guo et al. (2015). Training predictors based on features from deep neural networks also falls in this category Krizhevsky et al. (2012); He et al. (2016)

. Indeed, the best algorithms for challenging benchmarks in pose estimation of humans from images use deep features 

Toshev and Szegedy (2014); Wei et al. (2016); Pishchulin et al. (2016); Insafutdinov et al. (2016); Feichtenhofer et al. (2017); Insafutdinov et al. . This suggests that deep learning architectures should also greatly improve the accuracy of pose estimation for lab applications. However, the labeled data sets for these benchmarks are rather large (e.g. in the MPII Human Pose data set Andriluka et al. (2014)), which may render deep learning approaches infeasible as efficient tools at the scale of interest to neuroscience labs. Yet, due to transfer learning Donahue et al. (2014); Yosinski et al. (2014); Goodfellow et al. (2016); Kümmerer et al. (2016) we will show that this need not be the case.

Here, we demonstrate that by capitalizing on state-of-the-art methods for detecting human limb configurations, we can achieve excellent performance on pose estimation problems in the laboratory setting with minimal training data. Specifically, we investigated the feature detector architecture from DeeperCut Insafutdinov et al. (2016); Pishchulin et al. (2016), one of the best performing pose estimation algorithms, and demonstrate that a small number of training images (

) can be sufficient to train this network to within human-level labeling accuracy. This is possible due to transfer learning: the feature detectors are based on extremely deep neural networks, which were pre-trained on ImageNet, a massive data set for object recognition 

He et al. (2016). By labeling only a few hundred frames one can train tailored, robust feature detectors that are capable of localizing a variety of experimentally relevant body parts. We illustrate the power of this approach by tracking the snout, ears, and tail-base during an odor-guided navigation task, multiple body parts of a fruit fly behaving in a 3D chamber, as well as joints of individual digits during a reaching task.

Figure 2: Evaluation during Trail-Tracking. A: Two example frames with close-ups, showing snout, ears and tail base labeled by a human. The odor-trail as well as reward drops are visible under infra-red light and introduce a time-varying visual background. B: Cross-entropy loss for splits when training with of the frames. C: Corresponding root mean square error (RMSE) between the human and the predicted label on training and test images for those splits evaluated every iterations ( splits). The average of those individual curves is also shown (thick line). Human variability as well as confidence interval are depicted in black/gray. D: Corresponding RMSE when evaluated only for snout and tail base. Thus, the algorithm reaches human level variability on a test set comprising of all images. E: Example body part prediction for two frames, which were not used during the training (of one split in C). Prediction closely matches human annotator’s labels. F: RMSE for snout and tail for several splits of training and test data compared to RMSE of a human scorer. Each split is denoted by a cross, the average by a dot. For of the data the algorithm achieves human level accuracy on the test set (D). As expected, test RMSE increases for fewer training images. Around frames are enough to provide average tracking performance ( pixel accuracy). G: Snout-RMSE comparison between human and model per image for one split with

training set size. Most RMSE differences are small with few outliers. The two extreme errors (on the left) are due to labeling errors across trials by the human.

Ii Results

DeeperCut achieves outstanding performance on multi-human pose detection benchmarks Insafutdinov et al. (2016). However, to achieve this performance its neural network architecture has been trained on thousands of labeled images. Here we focus on a subset of DeeperCut: its feature detectors, which are variations of Deep Residual Neural Networks (ResNet) He et al. (2016) with readout layers that predict the location of a body part (see Methods, Figure 1). To distinguish the feature detectors from the full DeeperCut, we refer to this autonomous portion as DeepLabCut. In this paper, we (1) evaluate the performance of DeepLabCut for posture tracking in various laboratory behaviors, (2) investigate the amount of required training data for good generalization, and (3) provide an open source toolbox based on DeeperCut that is broadly accessible to the neuroscience community (

ii.1 Benchmarking

Analyzing videos taken in a dynamically changing environment can be challenging. Therefore, to test the utility of our toolbox, we first focused on an odor-guided navigation task for mice. Briefly, mice run freely on an ‘endless’ paper spool that includes an adapted ink-jet printer to deliver odor trails in real-time as a mouse runs and tracks trails (further details and results will be published elsewhere). The video captured during the behavior poses several key challenges: inhomogeneous illumination, transparent side walls that appear dark, shadows around the mouse from overhead lighting, distortions due to a wide-angle lens, the mouse often crosses the odor trail, and rewards are often directly in front of its snout ( which influences its appearance). Yet, accurately tracking the snout as a mouse samples the “odorscape” is crucial for studying odor-guided navigation.

First, we extracted distinct frames from multiple videos (across two cameras and different mice, see Methods) and manually labeled the snout, left ear, right ear, and tail base in all frames (Figure 2A, Figure S1). In order to facilitate comparisons to ground truth and to quantify the robustness of predictors, we estimated variability (root mean square error; RMSE) within one human labeler by comparing two distinct label sets of the same data. We found the average variability for all body parts to be very small pixels (mean s.e.m. body part image pairs; Figure S1, see Methods), which is less than the width of the mouse’s snout in low resolution camera frames (Figure 2A). The RMSE across two trials of annotating the same images is referred to as ‘human variability’ (note that the variability differs slightly across body parts).

To quantify the feature detector’s performance, we randomly split the data into a training and test set () and evaluated the performance of DeepLabCut on test images across all body parts (Figure 2B, C) and in a sub-set of body parts (snout/tail)(Figure 2D). Unless otherwise noted, we always trained (and tested) with the labels from the first set of human labels. The test RMSE for different training/test set splits achieved average human variability (Figure 2D). Thus, we found that when trained with of the data the algorithm achieved human-level accuracy on the test set for detection of the snout and the tail base (Figure 2D, E).

Next, we systematically varied the size of the training set and trained distinct networks ( splits for and training set size; splits for , , and training set fraction). As expected, the test error increases for decreasing number of training images (Figure 2F). Yet remarkably, the test RMSE only slowly attenuates from training set fraction to , where one still achieves an average pixel error of less than pixels. Such average errors are on the order of the size of the snout in the low resolution camera (around pixels) and much smaller than the size of the snout in higher resolution camera (around pixels). Thus, we found that even frames are enough to achieve excellent generalization.

Figure 3: A trail-tracking mouse. Green and cyan dots show future and past (respectively) snout positions of the snout during trail-tracking, each ms apart. The body postures of the the snout, ears and tail base at various past time points are depicted as magenta rhombi. Together those four points capture the body and head orientation of the mouse and illustrate the swinging head movements. The printed odor trail is visible in gray (see video at

Since the RMSE is computed as an average across images, we next checked if there were any systematic differences across images by comparing the human variability across the two splits vs. the model variability (trained with the first set of human labels; Figure 2G: data for split with a training set size). We found that both the human and the algorithm produced only a few outliers, but no systematic error was detected (see Figure 2G for examples).

Thus far, we used a part detector based on the layer deep ResNet- Insafutdinov et al. (2016); He et al. (2016). We also trained deeper networks with layers and found that both the training and testing errors decreased slightly, suggesting that the performance can be further improved if required (Average test RMSE for identical splits of training set fraction: ResNet-: , ResNet-: and ResNet- with intermediate supervision: , pixel mean s.e.m.; see Figure S2A).

Overall, given the robustness and the low error rate of DeepLabCut even with small training sets, we find this to be a useful tool for studies such as odor-guided navigation. For example, Figure 3 recapitulates a salient signature of the tracking behavior, namely that rodents swing their snout across the trail Khan et al. (2012). Knowing the location of the ears as well as the tail is also important to computationally assess the orientation of the mouse (Figure 3). Furthermore, having an automated pose estimation algorithm as presented will be crucial for video-rich experiments (such as this one).

ii.2 Generalization & transfer learning

Figure 4: Generalization: A: Frame-by-frame extracted snout and tail base trajectory in a novel mouse (not part of training set) during trail tracking on moving paper ground. Continuity of the trajectory suggests accurate training, which is also confirmed by histogram of pairwise, frame-by-frame differences in x- and y-coordinates. B: Body part predictions for images with multiple mice. Predictions of a network which was trained with images only containing a single mouse. It readily detects body parts in images with multiple (novel) mice (top), unless they are occluding each other (bottom). Additionally, these mice are younger than the ones in the training set (and have a different body shape).

We have demonstrated that DeepLabCut can accurately detect body parts across different mice, but how does it generalize to novel scenarios? Firstly, we found that DeepLabCut generalizes to novel mice during trail tracking (Figure 4A). Secondly, we tested if the trained network could identify multiple body parts across multiple mice within the same frame (transfer learning). Remarkably, although the network has only been trained with images containing a single mouse, it could detect all the body parts of each mouse in images with multiple interacting mice. Although not error-free, we found that the model performed remarkably well in a social task (three mice interacting in an unevenly illuminated open field, Figure 4B). The performance of the body part detectors could be improved by training the network with training images that include multiple mice with occlusions, and/or by training image-conditioned pairwise terms between body parts to harness the power of multi human pose estimation models Insafutdinov et al. (2016) (see discussion). Nonetheless, this example of multi-mice tracking illustrates that even the single-mouse trained feature detectors alone can readily transfer to extensions, as would be useful in studies of social behaviors Dell et al. (2014); Li et al. (2017); Robie et al. (2017).

ii.3 The power of end-to-end training

Figure 5: End-to-end training: We trained ‘specialized’ networks with only the snout or tail labels, respectively. We compare the RMSE against the full model that was trained on all body parts, but is also only evaluated on the snout or tail, respectively (i.e. “full@snout” means the model trained with all body parts (full), and RMSE evaluated on the snout). Training (blue) and test (red) performance for the full model and specialized models trained with the same three splits of the data (crosses) and average RMSE (dots). Although all networks have exactly the same information about the location of the snout or tail during training, the network that also received information about the other body parts outperforms the ‘specialized’ networks.
Figure 6: Markerless Tracking of Drosophila. A: Example body part predictions closely match with human annotator’s labels, shown for two frames that were not used in the training set ( training set size). B: Example frames and body part predictions for a fly that was not part of the training data in various postures and orientations. C: Example labels against a cluttered background comprised of numerous laid eggs. D: Example sequence of proboscis extension being automatically and accurately tracked (same fly as B). See video at

Due to the architecture of DeeperCut, the deconvolution layers are specific to each body part, but the deep pre-processing network (ResNet) is shared (Figure 1). We hypothesized that this architecture can facilitate the localization of one body part based on other labeled body parts. To test this hypothesis, we examined the performance of networks trained with only the snout/tail data while using the identical splits of training data as in Figure 2B. We found that the network that was trained with all body part labels simultaneously outperforms the specialized networks nearly twofold (Figure 5). This result also demonstrates that training the weights throughout the whole network in an end-to-end fashion rather than just the readout weights substantially improves the performance. This further highlights the advantage of such deep learning based models over approaches with fixed feature representations, which cannot be refined during training.

ii.4 Drosophila in 3D behavioral chamber

To further demonstrate the flexibility of the DeepLabCut toolbox, we tracked the bodies of freely behaving fruit flies (Drosophila) exploring a small cubical environment in which one surface contained an agar-based substrate for egg laying. Freely behaving flies readily exhibit many orientations, and also frequent the walls and ceiling. When viewed from a fixed perspective, these changes in orientation dramatically alter the appearance of flies as the spatial relationship of body features change, or as different body parts come into or out of view. Moreover, reliably tracking features across an entire egg-laying behavioral session could potentially be challenging to DeepLabCut owing to significant changes in the background (the accumulation of new eggs or changes in the agar substrate appearance due to evaporation).

To build towards an understanding of the behavioral patterns that surround egg-laying in an efficient way, we chose distinct points on the body of the fly and labeled frames of diverse orientation and posture from six different animals, labeling only those features that were visible within a given frame. We labeled four points on the head (the dorsal tip of each compound eye, the ocellus, and the tip of the proboscis), the posterior tip of the scutellum on the thorax, the joint between the femur and tibia on each metathoracic leg, the abdominal stripes on the four most posterior abdominal segments (A-A), and the ovipositor.

Figure 7: Markerless Tracking of Digits. A: Example test images labeled by human (yellow) and automated labeling (red/purple): the most likely joint is labeled in red if the probability of the peak in the score-map (see below) is larger than 10% at the peak, and purple otherwise. Here DeepLabCut was trained with only images. In images where targets were occluded, the model typically reduces its confidence in the label position (purple), including in frames where the human was not confident enough to apply labels (bottom right) or when the digit tips are not visible (upper right). Score-maps are shown for two example labels (highlighted by red arrows), and score-maps are to the right of the image. For better visibility log-transformed score-maps are also shown. B: Example analysis of trajectories after automated labeling. C: Extracted reach and pull trajectories from the wrist (purple), and digit 1 (blue) for pulls D: Trajectories in C. Dashed lines are the X-axis and solid lines represent the Y-axis. E: Based on the predicted wrist location, we extracted images of the hand from the video of one behavioral session and performed dimensionality reduction by t-SNE embedding of those images. The blue point cloud shows the 2D-embedding with several images corresponding to the red highlighted coordinates. This figure illustrates the richness of hand postures during reaching and pulling of the mouse. F: Labeled body parts with connecting edges giving rise to ‘skeleton’ of hand (see video at

We trained DeepLabCut with of the data and found a test error of pixels (mean s.e.m.; corresponding to an average training error of pixels, n= splits, mean s.e.m.). Figure 6A depicts some example test frames with human and network applied labels. Generalization to flies not used in the training set was excellent and the feature detectors are robust to changes in orientation (Figure 6B) and background (Figure 6C). Although fly bodies are relatively rigid, which simplifies tracking, there are exceptions. For instance, the proboscis dramatically changes its visual appearance during feeding behaviors. Yet, the feature detectors can resolve fast motor movements such as the extension and retraction of the proboscis (Figure 6D). Thus, DeepLabCut allows accurate extraction of low-dimensional pose information from videos of freely behaving Drosophila.

ii.5 Digit Tracking During Reaching

To further illustrate the versatility and capabilities of DeepLabCut we tracked segments of individual digits of a mouse hand (Figure 1 and 7A). We recently established a head-fixed, skilled reaching paradigm in mice Mathis et al. (2017)

, where mice grab a 2-degree of freedom joystick and pull it from a virtual start location to a target location. While the joystick allows for spatially accurate measurement of the joystick (hand) position during the pull with high temporal precision, it neither constrains the hand position on the joystick, nor provide position during the reaches or between pulls (when the mice might or might not hold the joystick). Placing markers is difficult as the mouse hand is a small, and a highly complex structure with multiple bones, joints, and muscles. Moreover, it is intrusive to the mice and can disrupt performance. Therefore, in principle, markerless tracking is a promising approach for analyzing reaching dynamics. However, tracking is challenging due to the complexity of possible hand articulations, as well as the presence of the other hand in the background. The images are also subject to very different image statistics, making this task well posed to highlight the generality of our DeepLabCut toolbox.

We labeled points per frame: points per visible digit ( digits): the digit tip, one mid digit joint, the base of the digit joint (these roughly correspond to the proximal interphalangeal joint (PIP) and the metacarpophalangeal joint (MCP), respectively), as well as point at the base of the hand (wrist). Remarkably, we found that by using just training frames we achieved an average test error of pixels (mean s.e.m.; corresponding to average training error pixels, splits, mean s.e.m.). For reference, the width of a single digit is pixels. Figure 7A depicts some example test frames. We believe that this application of hand pose estimation highlights the excellent generalization performance of DeepLabCut despite training with only a few images.

So far we have shown that the body part estimates derived from DeeperCut are highly accurate. But, in general, especially when sieving through massive data sets, the end user would like to have each point estimate accompanied by a confidence measure of the label location. The location predictions in DeeperCut are obtained by extracting the most likely region, based on a scalar field that represents the probability that a particular body part is in a particular region. In DeeperCut these probability maps are called “score-maps”, and predictions are generated by finding the point with the highest probability value (see Methods). The amplitude of the maximum can be used as a confidence read-out to examine the strength of evidence for individual localizations of the individual parts to be detected. For instance, the peak probability of the digit tip is low when the mouse holds the joystick (which causes occlusions of the digit tips). Similarly, when the features cannot be disambiguated, the likelihood becomes small (Figure 7A). This confidence readout also works in other contexts, for instance in the drosophila example frames we only depicted the predicted body parts when the probability was larger than (Figure 6B-D). Using this threshold, the point estimate for the left leg can be automatically excluded in Figure 6C, D. Indeed, all occluded body parts are also omitted in Figure 6B and Figure 7F.

Lastly, once a network is trained on the hand posture frames, the body part locations can be extracted from videos and utilized in many ways. Here we illustrate a few examples: digit positions during a reach across time (Figure 7B; note that this trajectory comes from frame by frame prediction without any temporal filtering), comparison of movement patterns across body parts (Figure 7C, D), dimensionality reduction to reveal the richness of mouse hand postures during reaching (Figure 7E) and creating ‘skeletons’ based on semantic meaning of the labels (Figure 7F).

Iii Discussion

Detecting postures from monocular images is a challenging problem. Traditionally, postures are modeled as a graph of parts, where each node encodes the local visual properties of the part in question, and then these parts are connected by spring-like links. This graph is then fit to images by minimizing some appearance cost function Felzenszwalb and Huttenlocher (2005). This minimization is hard to solve, but designing the model topology together with the visual appearance model is even more challenging Felzenszwalb and Huttenlocher (2005); Toshev and Szegedy (2014); this can be illustrated by considering the diversity of fruit fly (Figure 6) and hand postures we examined (Figure 7). In contrast, casting this problem as a minimization with deep residual neural networks allows each joint predictor to have more than just local access to the image Toshev and Szegedy (2014); Wei et al. (2016); Insafutdinov et al. (2016); Pishchulin et al. (2016); Feichtenhofer et al. (2017). Due to the extreme depth of ResNets, architectures like DeeperCut have large receptive fields, which can learn to extract postures in a robust way Insafutdinov et al. (2016).

Here we demonstrated that cutting-edge deep learning models can be efficiently utilized in the laboratory. Specifically, we leveraged the fact that adapting pre-trained models to new tasks can dramatically reduce the amount of training data required, a phenomena known as transfer learning Donahue et al. (2014); Yosinski et al. (2014); Goodfellow et al. (2016); Insafutdinov et al. (2016); Kümmerer et al. (2016). We first estimated the accuracy of a human labeler who could readily identify the body parts we were interested in for odor guided navigation, and then demonstrated that a deep architecture can achieve similar performance on detection of body parts such as the snout, or the tail after training on only a few hundred images. Moreover, this solution requires no computational body-model, stick figure, time-information, or sophisticated inference algorithm. Thus, it can also be quickly applied to completely different behaviors that pose qualitatively distinct challenges to computer vision, like skilled reaching or egg-laying in drosophila.

We believe that DeepLabCut will supplement the rich literature of computational methods for video analysis Drai and Golani (2001); Sousa et al. (2006); Gomez-Marin et al. (2012); Matsumoto et al. (2013); Machado et al. (2015); Guo et al. (2015); Dollár et al. (2010); Ben-Shaul (2017); Dell et al. (2014); Anderson and Perona (2014)

, where powerful feature detectors of user-defined body parts need to be learned for a specific situation, or where regressors based on standard image features and thresholding heuristics 

Gomez-Marin et al. (2012); Robie et al. (2017); Dell et al. (2014) fail to provide satisfying solutions. This is particularly the case in dynamic visual environments (e.g. with varying background and reflective walls (Figures 2 and 6) or when tracking highly articulated objects like the hand (Figure 7).

Dataset labeling and fine-tuning

Deep learning algorithms are extremely powerful and can learn to associate arbitrary categories to images Zhang et al. (2016); Goodfellow et al. (2016). This is consistent with our own observation that the training set should be free of errors (Figure 2G) and approximate the diversity of visual appearances. Thus, in order to train DeepLabCut for specific applications we recommend labeling maximally diverse images (i.e. different poses, different individuals, luminance conditions, data collected with different cameras, etc.) in a consistent way and curate the labeled data well. Even for a extremely small training set, the typical errors can be small, but large errors for test images that are quite distinct from the training set can start to dominate the average error. One limitation for generalizing to novel situations comes from stochasticity in training set selection. Given that we only select a small number of training samples (i.e. a few hundred frames), and do so randomly from the data, it is plausible that images representing behaviors that are especially sparse or noisy (i.e. due to motion blur) could be sub-optimally sampled or entirely excluded from the training data, resulting in difficulties at test time.

Therefore, a user can expand the initial training dataset in an iterative fashion using the score-maps as a guide. Specifically, errors can be addressed via post-hoc “fine tuning” of the network weights, taking advantage of the fact that the network outputs confidence estimates for its own generated labels (Figure 7

A, see Methods). By using these confidence estimates to select sequences of frames containing a sparse behavior (by sampling around points of high probability), or to find frames where reliably captured behaviors are largely corrupted with noise (by sampling points of low probability), a user can then selectively label frames based on these confidence criteria to generate a minimal yet additional training set for fine tuning the network. This selectively improves model performance on edge cases, thereby extending the architecture’s capacity for generalization in an efficient way. Thus, for generalization to large data sets, one can use features of the score-maps such as the amplitude or width, or use heuristics such as the continuity of body part trajectories, to identify images where the decoder might make large errors. Images with insufficient automatic labeling performance that are identified in this way can then be manually labeled to increase the training set and iteratively improve the feature detectors. Such an active learning framework can be used to achieve a predefined level of confidence for all images with minimal labeling cost. Then, due to the large capacity of the neural network that underlies the feature detectors, one can continue training the network with these additional examples.

We note however, that not every low probability score-map value necessarily reflects erroneous detection. As we showed, low probabilities can also be indicative of occlusions, as in the case of the digit tips when the mouse is holding the joystick (Figure 7). Here, multiple camera angles can be used to fully capture a behavior of interest, or heuristics can be used (such as a body-model) to approximate occluded body parts based on temporal and spatial information.

Speed and accuracy of DeepLabCut

Another important feature of DeepLabCut is that it can accurately transform large videos into low-dimensional time sequence data with semantic meaning, as the experimenter pre-selects the parts that will presumably provide the most information about the behavior being studied. Such low-dimensional time sequence data is also highly amenable to behavioral clustering and analysis due to its computational tractability Berman (2018); Dell et al. (2014); Anderson and Perona (2014); Gomez-Marin et al. (2014). On modern hardware pose extraction is also fast. For instance, one can process the sized frames of the drosophila behavior at around frames per second on a NVIDIA -Ti GPU. Such fast pose extraction can make this tool potentially amenable for real-time feedback Mathis et al. (2017) based on video-based posture estimates. This processing speed can be further improved by cropping input frames in an adaptive way around the animal, and/or adapting the network architecture to speed up processing times.


As presented, DeepLabCut extracts the posture data frame-by-frame, but one can add temporal Kalman filtering to improve performance (as for other approaches) 

Stauffer and Grimson (1999); Ristic et al. (2003); Dell et al. (2014). Here we omitted such methods due to the high precision of the model without these additional steps, and to focus on the prediction based on single frames solely driven by within-frame visual information in a variety of contexts.

While temporal information could indeed be beneficial in certain contexts, challenges remain to using end-to-end trained deep architectures for video data to extract postures. Due to the curse of dimensionality, deep architectures on videos must rely on lower spatial resolution input images, and thus, the best performing action recognition algorithms still rely on frame-by-frame analysis with deep networks pre-trained on ImageNet due to hardware limitations 

Feichtenhofer et al. (2017); Carreira and Zisserman (2017); Insafutdinov et al. . As this is an active area of research, we believe this situation will likely change due to improvements in hardware (and in deep learning algorithms), and this should have a strong influence on pose estimation in the future. Therefore currently, in situations where occlusions are very common, such as in social behaviors, pairwise interactions could also be added to improve performance Felzenszwalb and Huttenlocher (2005); de Chaumont et al. (2012); Matsumoto et al. (2013); Perez-Escudero et al. (2014); Nakamura et al. (2016); Uhlmann et al. (2017); Dell et al. (2014); Insafutdinov et al. ; Insafutdinov et al. (2016). Here we focused on the deep feature detectors alone to demonstrate remarkable transfer learning for laboratory tasks without the need for such extensions.


Together with this paper we provide an open source software package called DeepLabCut. The toolbox uses the feature detectors from DeeperCut and provides routines to a) extract distinct frames from videos for labeling, b) generate training data based on labels, c) train networks to the desired feature sets, and d) extract these feature locations from unlabeled data (Figure 1). The typical use case would be that an experimenter extracts distinct frames from videos and labels the body-parts of interest to create tailored part detectors. Then, after only a few hours of labeling and a day of training the network, they can apply DeepLabCut to novel videos. While we demonstrate the utility of this toolbox on mice and Drosophila, there is no inherent limitation of this framework, and our toolbox can be applied to other model, or non-model, organisms in a diverse range of behaviors.

Iv Methods

Mouse Odor Trail-Tracking

The trail-tracking behavior is part of an investigation into odor guided navigation, where one or multiple wild type (C57BL/6J) mice are running on a paper spool and following odor trails. These experiments were carried out in the Murthy lab at Harvard University and will be published elsewhere. For trail-tracking we extracted random, distinct frames from multiple experimental sessions observing different mice. Data was recorded by two different cameras ( pixels, and at approximately ) at Hz. The latter images are prohibitively large to process by this deep neural network without down-sampling, therefore we cropped around mice to generate images that are approximately . One human annotator was instructed to localize the snout, the tip of the left and right ear as well as the base of the tail in the example images on two different occasions, generating two distinct label sets ( month apart to reduce memory bias, see Figure S1).

Mouse Reach & Pull Joystick Task

Experimental procedures for the training of the joystick behavior and the construction of the behavioral set-up can be found in Mathis et al. (2017). In brief, head-fixed mice were trained to reach, grab, and pull a joystick for a liquid reward. To generate a train/test set of images, we labeled frames at the digit tip, the joint in the middle and at the base of the digit for four digits (which roughly correspond to the proximal interphalangeal joint (PIP) and the metacarpophalangeal joint (MCP), respectively), as well as the base of the hand (wrist). The data was collected across different mice (C57BL/6J, male and female) and were recorded at resolution with a frame rate of Hz. For tracking the digits we used the supplied toolbox code to crop the data to only extract regions of interest containing the movement of the arm to limit the size of the input image to the network.

All surgical and experimental procedures for mice were in accordance with the National Institutes of Health Guide for the Care and Use of Laboratory Animals and approved by the Harvard Institutional Animal Care and Use Committee.

Drosophila Egg-Laying Behavior

Experiments were carried out in the laboratory of Richard Axel at Columbia University and will be published elsewhere. In brief, egg-laying behavior was observed in custom designed 3D-printed chambers (Protolabs). Individual chambers were 4.1 mm deep and tapered from top to bottom, with the top dimensions 7.3 mm 5.8 mm and the bottom dimensions 6.7mm 4.3mm. One side of the chamber opened to a reservoir within which 1% agar was poured and allowed to set. Small acrylic windows were slid into place within grooves at the top and bottom to enclose the fly within the chamber and to allow for viewing. The chamber was illuminated by a 2 inch off-axis ring light (Metaphase) and video recording was performed from above the chamber using an IR-sensitive CMOS camera (Basler) with a 0.5x telecentric lens (Edmund Optics) at Hz ( pixels). We identified 12 distinct points of interest to quantify the behavior of interest on the body of the fly. One human annotator manually extracted 589 distinct and informative frames from six different animals, labeling only those features that were visible within a given frame. The 12 points comprise: four points on the head (the dorsal tip of each compound eye, the ocellus, and the tip of the proboscis), the posterior 10 tip of the scutellum on the thorax, the joint between the femur and tibia on each metathoracic leg, the abdominal stripes on the four most posterior abdominal segments (A3-A6), and the ovipositor.

Deep feature detector architecture

We employ strong body part detectors, which are part of state-of-the art algorithms for human pose estimation called DeeperCut Insafutdinov et al. (2016); Pishchulin et al. (2016); Insafutdinov et al. . Those part detectors build upon state-of-the-art object recognition architectures, namely extremely deep Residual Networks (ResNet) He et al. (2016). Specifically, we use a variant of the ResNet with 50 layers, which achieved outstanding performance in object recognition competitions He et al. (2016)

. In the DeeperCut implementation, the ResNets were adapted to represent the images with higher spatial resolution, and the softmax layer used in the original architecture after the conv5 bank (as would be appropriate for object classification) was replaced by “deconvolutional layers” that produce a scalar field of activation values corresponding to regions in original image. This output is also connected to the conv3 bank to make use of finer features generated earlier in the ResNet architecture  

Insafutdinov et al. (2016). For each body part, there is a corresponding output layer whose activity represents probability “score-maps”. These score-maps represent the probability that a body part is at a particular pixel Insafutdinov et al. (2016); Pishchulin et al. (2016). During training, a score-map with positive label (unity probability) is generated for all locations up to pixels away from the ground truth per body part (distance variable). The ResNet architecture used to generate features is initialized with weights trained on ImageNet He et al. (2016)

and the cross-entropy loss between the predicted score-map and the ground-truth score-map is minimized by stochastic gradient descent 

Insafutdinov et al. (2016). Around five hundred thousand training steps were enough for convergence and training takes around 24-36h on a GPU (NVIDIA GTX 1080 Ti; see Figure 2B). We used a batch size of , which allows to have images of different size, decreased the learning rate over training and performed data augmentation during training by rescaling the images (all like DeeperCut, but we used a range of to ). Unless otherwise noted we used a distance variable (pixel radius) and scale factor (which affects the ratio of the input image to output score-map). We cross validated the choice of for a higher resolution output (scale factor = 1) and found that the test performance is not improved when varying widely, but the rate of performance improvement was strongly decreased for small (Figure S2). We also compared deeper networks with 101 layers, ResNet-101, as well as ResNet-101ws (with intermediate supervision, Figure S2A; more technical details for this architecture can be found in Insafutdinov et al. (2016)).

Evaluation and error measures

The trained network can be used to predict body part locations. At any state of training the network can be presented with novel frames, for which the prediction of the location of a particular body part is given by the peak of the corresponding score-map. This estimate is further refined based on learned correspondences between the score-map grid and ground truth joint positions Insafutdinov et al. . In the case of multiple mice the local maxima of the score-map are extracted as predictions of the body part locations (Figure 4).

To compare between datasets generated by the human scorer, as well as with/between model-generated labellings, we used the Euclidean distance (root mean square error, abbreviated: RMSE) calculated pairwise per body-part. Depending on the context this metric is either shown for a specific body-part, averaged over all body-parts, or averaged over a set of images. To quantify the error across learning, we stored snapshots of the weights in TensorFlow (usually every

iterations) and evaluated the RMSE for predictions generated by these frozen networks post-hoc. Note that the RMSE is not the loss function minimized during training. However, the RMSE is the relevant performance metric for pose estimation for assessing labeling precision.

The RMSE between the first and second annotation is referred to as human variability. In figures we also depict the confidence interval for this RMSE, whose limits are given as mean

times the standard error of the mean (Figure 

2C, D, F; Figure 4 Figure 5; Figure S2A-D). Depending on the figure, the RMSE is averaged over all or just a subset of body parts.

In (Figure 7) we extracted cropped images of the hand from full frames by centering it using the predicted wrist position. We then performed dimensionality reduction by t-SNE embedding of those images Pedregosa et al. (2011) and randomly selected certain and sufficiently distant points to illustrate the corresponding hand postures.

DeepLabCut Toolbox

This publication is accompanied by open source Python code for selecting training frames, checking human annotator labels, generating training data in the required format, as well as evaluating the performance on test frames. The toolbox also contains code to extract postures from novel videos with trained feature detectors. Thus, this toolbox allows one to train a tailored network based on labeled images and can then perform automatic labeling for novel data. See for details.

We are grateful to Eldar Insafutdinov and Christoph Lassner for suggestions on how to best use the TensorFlow implementation of DeeperCut. We thank Naoshige Uchida for generously providing resources for the joystick behavior, and Richard Axel for generously providing resources for the drosophila research. We also thank Adrian Hoffmann, Jonas Rauber, Tanmay Nath, David Klindt, and Travis DeWolf for a critical reading of the manuscript as well as members of the Bethge lab, especially Matthias Kümmerer, for discussions. We also thank the -testers for trying our toolbox and sharing their results with us. Funding: AM: Marie Sklodowska-Curie International Fellowship within the 7th European Community Framework Program under grant agreement No. 622943 and by DFG grant MA 6176/1-1. MWM: Project ALS (Women the Brain Fellowship for Advancement in Neuroscience) & a Rowland Fellowship from the Rowland Institute at Harvard. MB: German Science foundation (DFG) through the CRC 1233 on “Robust Vision” and from IARPA through the MICrONS program. Contributions: Conceptualization: AM, MWM, MB. Software: AM, MWM. Formal Analysis: AM. Experiments: AM & VNM (trail-tracking), MWM (mouse reaching), KC (Drosophila). Labeling: PM, KC, TA, MWM, AM. Writing: AM & MWM with input from all authors.


V Supplementary Materials

Materials related to main figures of Mathis et al. Please also see for video demonstrations of the tracking.

Figure S1: Illustration of labeled data set. A: Example images with human applied labels (first and second trial by the same labeler colored in yellow and cyan) illustrating the variability. Top row shows full frames that were labeled and illustrate typical examples of the random frames, which comprise the data set. Rows below are cropped for visibility of the labels and indicate the average RMSE in pixels across all body parts above the image. The scorer was highly accurate, as illustrated by B. B: x-axis and y-axis difference in pixels between the first - second trial. Only a few labels strongly deviate between the two trials. Most errors are smaller than pixels as can be seen in the histogram of trial-by-trial labeling errors (cropped at pixels) (C).
Figure S2: Cross validating model parameters and testing deeper networks. A: Average training and test error for the same splits with training set size for three different architectures: ResNet-50, ResNet-101 as well as ResNet-101ws, where part loss layers are added to conv4 bank Insafutdinov et al. . For these networks the training error is strongly reduced, and the test performance modestly improved, indicating that the deeper networks do not overfit (but do not offer radical improvement). Averaged over splits, individual simulation results shown in as faint lines. The deeper networks reach human level accuracy on test set. The data for ResNet-50 is also depicted in Figure 2D. B-D: Cross validating model parameters for ResNet-50 and -training set fraction. We varied the distance variable , which determines the width of the score-map template during training around the ground truth value with scale variable (otherwise the scale ratio of the output layer was set to relative to the the input image size). Varying distance parameters only mildly improves the test performance (after training steps). The average performance for scale and is indicated by horizontal lines (from Figure 2D). In particular, for smaller distance parameters the RMSE increases and learning proceeds much slower (C,D). C-D: evolution of the training and test errors at various states of the network training for various distance variables corresponding to B.