|
| 1 | +--- |
| 2 | +title: "Modelling Motion Capture Data with the GP-LVM" |
| 3 | +date: 2021-05-19 |
| 4 | +published: 2021-05-19 |
| 5 | +week: 0 |
| 6 | +ipynb: cmu-mocap-gplvm.ipynb |
| 7 | +layout: software |
| 8 | +categories: |
| 9 | +- notes |
| 10 | +--- |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +<!-- Do not edit this file locally. --> |
| 15 | +<!----> |
| 16 | +<!-- Do not edit this file locally. --> |
| 17 | +<!-- Do not edit this file locally. --> |
| 18 | +<!-- The last names to be defined. Should be defined entirely in terms of macros from above--> |
| 19 | +<!-- |
| 20 | +
|
| 21 | +--> |
| 22 | +<h2 id="setup">Setup</h2> |
| 23 | +<!--setupplotcode{import seaborn as sns |
| 24 | +sns.set_style('darkgrid') |
| 25 | +sns.set_context('paper') |
| 26 | +sns.set_palette('colorblind')}--> |
| 27 | +<h2 id="pods">pods</h2> |
| 28 | +<div style="text-align:right"> |
| 29 | +<span class="editsection-bracket" style="">[</span><span class="editsection" style=""><a href="https://github.com/lawrennd/talks/edit/gh-pages/_software/includes/pods-software.md" target="_blank" onclick="ga('send', 'event', 'Edit Page', 'Edit', 'https://github.com/lawrennd/talks/edit/gh-pages/_software/includes/pods-software.md', 13);">edit</a></span><span class="editsection-bracket" style="">]</span> |
| 30 | +</div> |
| 31 | +<p>In Sheffield we created a suite of software tools for ‘Open Data Science.’ Open data science is an approach to sharing code, models and data that should make it easier for companies, health professionals and scientists to gain access to data science techniques.</p> |
| 32 | +<p>You can also check this blog post on <a href="http://inverseprobability.com/2014/07/01/open-data-science">Open Data Science</a>.</p> |
| 33 | +<p>The software can be installed using</p> |
| 34 | +<div class="sourceCode" id="cb1"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="op">%</span>pip install <span class="op">--</span>upgrade git<span class="op">+</span>https:<span class="op">//</span>github.com<span class="op">/</span>lawrennd<span class="op">/</span>ods</span></code></pre></div> |
| 35 | +<p>from the command prompt where you can access your python installation.</p> |
| 36 | +<p>The code is also available on github: <a href="https://github.com/lawrennd/ods" class="uri">https://github.com/lawrennd/ods</a></p> |
| 37 | +<p>Once <code>pods</code> is installed, it can be imported in the usual manner.</p> |
| 38 | +<div class="sourceCode" id="cb2"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> pods</span></code></pre></div> |
| 39 | +<h2 id="mlai">mlai</h2> |
| 40 | +<div style="text-align:right"> |
| 41 | +<span class="editsection-bracket" style="">[</span><span class="editsection" style=""><a href="https://github.com/lawrennd/talks/edit/gh-pages/_software/includes/mlai-software.md" target="_blank" onclick="ga('send', 'event', 'Edit Page', 'Edit', 'https://github.com/lawrennd/talks/edit/gh-pages/_software/includes/mlai-software.md', 13);">edit</a></span><span class="editsection-bracket" style="">]</span> |
| 42 | +</div> |
| 43 | +<p>The <code>mlai</code> software is a suite of helper functions for teaching and demonstrating machine learning algorithms. It was first used in the Machine Learning and Adaptive Intelligence course in Sheffield in 2013.</p> |
| 44 | +<p>The software can be installed using</p> |
| 45 | +<div class="sourceCode" id="cb3"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="op">%</span>pip install <span class="op">--</span>upgrade git<span class="op">+</span>https:<span class="op">//</span>github.com<span class="op">/</span>lawrennd<span class="op">/</span>mlai.git</span></code></pre></div> |
| 46 | +<p>from the command prompt where you can access your python installation.</p> |
| 47 | +<p>The code is also available on github: <a href="https://github.com/lawrennd/mlai" class="uri">https://github.com/lawrennd/mlai</a></p> |
| 48 | +<p>Once <code>mlai</code> is installed, it can be imported in the usual manner.</p> |
| 49 | +<div class="sourceCode" id="cb4"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> mlai</span></code></pre></div> |
| 50 | +<div class="sourceCode" id="cb5"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="op">%</span>pip install gpy</span></code></pre></div> |
| 51 | +<h2 id="gpy-a-gaussian-process-framework-in-python">GPy: A Gaussian Process Framework in Python</h2> |
| 52 | +<div style="text-align:right"> |
| 53 | +<span class="editsection-bracket" style="">[</span><span class="editsection" style=""><a href="https://github.com/lawrennd/talks/edit/gh-pages/_software/includes/gpy-software.md" target="_blank" onclick="ga('send', 'event', 'Edit Page', 'Edit', 'https://github.com/lawrennd/talks/edit/gh-pages/_software/includes/gpy-software.md', 13);">edit</a></span><span class="editsection-bracket" style="">]</span> |
| 54 | +</div> |
| 55 | +<p>Gaussian processes are a flexible tool for non-parametric analysis with uncertainty. The GPy software was started in Sheffield to provide a easy to use interface to GPs. One which allowed the user to focus on the modelling rather than the mathematics.</p> |
| 56 | +<div class="figure"> |
| 57 | +<div id="gpy-software-figure" class="figure-frame"> |
| 58 | +<div class="centered" style=""> |
| 59 | +<img class="" src="../slides/diagrams/gp/gpy.png" width="70%" height="auto" align="center" style="background:none; border:none; box-shadow:none; display:block; margin-left:auto; margin-right:auto;vertical-align:middle"> |
| 60 | +</div> |
| 61 | +</div> |
| 62 | +<div id="gpy-software-magnify" class="magnify" onclick="magnifyFigure('gpy-software')"> |
| 63 | +<img class="img-button" src="{{ '/assets/images/Magnify_Large.svg' | relative_url }}" style="width:1.5ex"> |
| 64 | +</div> |
| 65 | +<div id="gpy-software-caption" class="caption-frame"> |
| 66 | +<p>Figure: GPy is a BSD licensed software code base for implementing Gaussian process models in Python. It is designed for teaching and modelling. We welcome contributions which can be made through the Github repository <a href="https://github.com/SheffieldML/GPy" class="uri">https://github.com/SheffieldML/GPy</a></p> |
| 67 | +</div> |
| 68 | +</div> |
| 69 | +<p>GPy is a BSD licensed software code base for implementing Gaussian process models in python. This allows GPs to be combined with a wide variety of software libraries.</p> |
| 70 | +<p>The software itself is available on <a href="https://github.com/SheffieldML/GPy">GitHub</a> and the team welcomes contributions.</p> |
| 71 | +<p>The aim for GPy is to be a probabilistic-style programming language, i.e. you specify the model rather than the algorithm. As well as a large range of covariance functions the software allows for non-Gaussian likelihoods, multivariate outputs, dimensionality reduction and approximations for larger data sets.</p> |
| 72 | +<p>The documentation for GPy can be found <a href="https://gpy.readthedocs.io/en/latest/">here</a>.</p> |
| 73 | +<h2 id="cmu-mocap-database">CMU Mocap Database</h2> |
| 74 | +<div style="text-align:right"> |
| 75 | +<span class="editsection-bracket" style="">[</span><span class="editsection" style=""><a href="https://github.com/lawrennd/talks/edit/gh-pages/_datasets/includes/cmu-mocap-data.md" target="_blank" onclick="ga('send', 'event', 'Edit Page', 'Edit', 'https://github.com/lawrennd/talks/edit/gh-pages/_datasets/includes/cmu-mocap-data.md', 13);">edit</a></span><span class="editsection-bracket" style="">]</span> |
| 76 | +</div> |
| 77 | +<p>Motion capture data from the CMU motion capture data base <span class="citation" data-cites="CMU-mocap03">(CMU Motion Capture Labb, 2003)</span>.</p> |
| 78 | +<div class="sourceCode" id="cb6"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> pods</span></code></pre></div> |
| 79 | +<p>You can download any subject and motion from the data set. Here we will download motion <code>01</code> from subject <code>35</code>.</p> |
| 80 | +<div class="sourceCode" id="cb7"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>subject<span class="op">=</span><span class="st">'35'</span> </span> |
| 81 | +<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>motion<span class="op">=</span>[<span class="st">'01'</span>]</span></code></pre></div> |
| 82 | +<div class="sourceCode" id="cb8"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>data <span class="op">=</span> pods.datasets.cmu_mocap(subject, motion)</span></code></pre></div> |
| 83 | +<p>The data dictionary contains the keys ‘Y’ and ‘skel,’ which represent the data and the skeleton..</p> |
| 84 | +<div class="sourceCode" id="cb9"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>data[<span class="st">'Y'</span>].shape</span></code></pre></div> |
| 85 | +<p>The data was used in the hierarchical GP-LVM paper <span class="citation" data-cites="Lawrence:hgplvm07">(Lawrence and Moore, 2007)</span> in an experiment that was also recreated in the Deep Gaussian process paper <span class="citation" data-cites="Damianou:deepgp13">(Damianou and Lawrence, 2013)</span>.</p> |
| 86 | +<div class="sourceCode" id="cb10"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(data[<span class="st">'citation'</span>])</span></code></pre></div> |
| 87 | +<p>And extra information about the data is included, as standard, under the keys <code>info</code> and <code>details</code>.</p> |
| 88 | +<div class="sourceCode" id="cb11"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(data[<span class="st">'info'</span>])</span> |
| 89 | +<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>()</span> |
| 90 | +<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(data[<span class="st">'details'</span>])</span></code></pre></div> |
| 91 | +<p>The original data has the figure moving across the floor during the motion capture sequence. We can make the figure walk ‘in place,’ by setting the x, y, z positions of the root node to zero. This makes it easier to visualize the result.</p> |
| 92 | +<div class="sourceCode" id="cb12"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Make figure move in place.</span></span> |
| 93 | +<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>data[<span class="st">'Y'</span>][:, <span class="dv">0</span>:<span class="dv">3</span>] <span class="op">=</span> <span class="fl">0.0</span></span></code></pre></div> |
| 94 | +<p>We can also remove the mean of the data.</p> |
| 95 | +<div class="sourceCode" id="cb13"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>Y <span class="op">=</span> data[<span class="st">'Y'</span>]</span></code></pre></div> |
| 96 | +<p>Now we create the GP-LVM model.</p> |
| 97 | +<div class="sourceCode" id="cb14"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> GPy</span></code></pre></div> |
| 98 | +<div class="sourceCode" id="cb15"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>model <span class="op">=</span> GPy.models.GPLVM(Yhat, <span class="dv">2</span>, normalizer<span class="op">=</span><span class="va">True</span>)</span></code></pre></div> |
| 99 | +<p>Now we optimize the model.</p> |
| 100 | +<div class="sourceCode" id="cb16"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>model.optimize(messages<span class="op">=</span><span class="va">True</span>, max_f_eval<span class="op">=</span><span class="dv">10000</span>)</span></code></pre></div> |
| 101 | +<h1 id="references">References</h1> |
| 102 | +<div style="text-align:right"> |
| 103 | +<span class="editsection-bracket" style="">[</span><span class="editsection" style=""><a href="https://github.com/lawrennd/talks/edit/gh-pages/cmu-mocap-gplvm.gpp.markdown" target="_blank" onclick="ga('send', 'event', 'Edit Page', 'Edit', 'https://github.com/lawrennd/talks/edit/gh-pages/cmu-mocap-gplvm.gpp.markdown', 13);">edit</a></span><span class="editsection-bracket" style="">]</span> |
| 104 | +</div> |
| 105 | +<div id="refs" class="references csl-bib-body hanging-indent" role="doc-bibliography"> |
| 106 | +<div id="ref-CMU-mocap03" class="csl-entry" role="doc-biblioentry"> |
| 107 | +CMU Motion Capture Labb, 2003. The <span>CMU</span> mocap database. |
| 108 | +</div> |
| 109 | +<div id="ref-Damianou:deepgp13" class="csl-entry" role="doc-biblioentry"> |
| 110 | +Damianou, A., Lawrence, N.D., 2013. Deep <span>G</span>aussian processes. pp. 207–215. |
| 111 | +</div> |
| 112 | +<div id="ref-Lawrence:hgplvm07" class="csl-entry" role="doc-biblioentry"> |
| 113 | +Lawrence, N.D., Moore, A.J., 2007. Hierarchical <span>G</span>aussian process latent variable models. pp. 481–488. |
| 114 | +</div> |
| 115 | +</div> |
| 116 | + |
0 commit comments