Use of BatchNormalisation variables

Anthair: <p>Hi all,<br>
due to IT reasons, I cannot run the inference on my dataset using pytorch (long story).<br>
I have created a C++11 code that loads weights and biases from a pytorch training and uses them to run the inference.<br>
So far, the C++ inference works fine.</p>
<p>However, the model I’m currently using for my dataset relies on Batch Normalisation techniques (BatchNorm1D); I managed to extract the following normalisation variables from my training:</p>
<ul>
<li>normalise.weight (vector)</li>
<li>normalise.bias (vector)</li>
<li>normalise.running_mean (vector)</li>
<li>normalise.running_var (vector)</li>
<li>normalise.num_batches_tracked (int number)</li>
</ul>
<p>I have some troubles understanding how to use these values to normalise the inputs during the inference process. To be clear, I need to understand the underlying vector/matrix algebra of the normalization process.</p>
<p>I know that, given X as input:</p>
<pre><code class="lang-auto">X_norm = (X - mean)/sqrt{var + 1e-5}
out = gamma * X_norm + beta
</code></pre>
<p>but it is not clear to me which of the previous values are gamma and beta. My guess would be:<br>
<code>gamma = normalise.weights</code><br>
and<br>
<code>beta = normalise.bias</code><br>
I had a look at the original Batch Normalization paper, but that focuses more on the normalisation in batches during the training.</p>
<p>Any idea?<br>
Thanks</p>

ptrblck: <p>You are correct in your assumption.<br>
<code>gamma</code> corresponds to the <code>weights</code> and <code>beta</code> to the <code>bias</code>.</p>
<p>Are you now allowed to use PyTorch in Python or PyTorch in general for inference?<br>
If it’s all about Python, we also have a C++ API, which could make your life a bit easier.</p>

Anthair: <p>Thank you for your answer <a class="mention" href="/u/ptrblck">@ptrblck</a>!</p>
<p>I tried using the C++ API for inference but it is not a feasible option due to technical issues with compilation.<br>
I need to implement the inference process on a code based on CERN ROOT; something fails during the linking when trying to link both the Torch libraries (either pre-built of from source) and CERN ROOT and I’m therefore unable to use torch to implement the inference process on our code (you can find additional details here: <a href="https://root-forum.cern.ch/t/trouble-with-root-libtorch-make-compilation/32975" rel="nofollow noopener">Link to ROOT forum</a>).</p>
<p>After a couple months of work I managed to compile CERN ROOT + Torch under gcc 4.8.5, which seems to be the only version of gcc that supports this combination of libraries; unfortunately, gcc 4.8.5 is not supported by our IT department.</p>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://root-forum.cern.ch/uploads/default/original/2X/5/545acb64199d12b11bc2c230cbb664c825525dd4.ico" class="site-icon" width="16" height="16">
      <a href="https://root-forum.cern.ch/t/trouble-with-root-libtorch-make-compilation/32975" target="_blank" title="01:32PM - 01 March 2019" rel="nofollow noopener">ROOT Forum – 1 Mar 19</a>
  </header>
  <article class="onebox-body">
    <img src="https://root-forum.cern.ch/uploads/default/original/3X/e/f/ef709c59ac83aa7a976f7319043f93b0c8cd2bf5.png" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://root-forum.cern.ch/t/trouble-with-root-libtorch-make-compilation/32975" target="_blank" rel="nofollow noopener">Trouble with ROOT+libtorch make compilation</a></h3>

<p>Dear Root forum members,  I am hitting a problem with cmake compilation and ROOT libraries.  I have followed the ROOT guide to create a CMakeLists for my code and I managed to have a compiled running code. (Here the guide that I have followed:...</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


ptrblck: <p>If you have such restrictions, would it be possible to isolate your code in a docker container and install all libs there?<br>
This wouldn’t touch the bare metal, so that you won’t mess up the server install.</p>

Anthair: <p>That’s a possibility; to be honest, I’m not really experienced with docker containers and the code will have to run on a distributed computing system. I guess this would make such an implementation way more complex</p>