Running pytorch models in browser

octopusyo: <p>Hi,</p>
<p>Is there any way to run model trained in pytorch in a browser (through javascript)? I found that there is keras.js library for Keras, but maybe there is something available for PyTorch also?</p>

drscotthawley: <p>Writing in order to bump this.  I have no idea, but I’ve been seeing demos that run Keras &amp; Tensorflow models…</p>
<p>Presumably the answer is, “Great idea, why don’t you write this and we’ll include it! ;-)”, but… Is anyone working on this?</p>
<p><strong>UPDATE:</strong> Seems the thing to do is save your model in ONNX format, an then use web tools that can read ONNX.</p>

RicCu: <p>AFAIK currently the only way to do this would be:<br>
PyTorch -&gt; ONNX -&gt; TensorFlow -&gt; TensorFlow.js</p>

dambo: <aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://assets-cdn.github.com/favicon.ico" class="site-icon" width="16" height="16">
      <a href="https://github.com/mil-tokyo/webdnn" target="_blank" rel="nofollow noopener">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars0.githubusercontent.com/u/9211471?s=400&amp;v=4" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://github.com/mil-tokyo/webdnn" target="_blank" rel="nofollow noopener">mil-tokyo/webdnn</a></h3>

<p>webdnn - The Fastest DNN Running Framework on Web Browser</p>


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

<p>It tried it with a PyTorech based U-net did not work with PyTorch 0.4</p>

stefa91: <p>Any alternative on tensorflow? I do not want to convert my code to tensorflow since I have custom loss functions</p>

karanchahal: <p>Hello, is anyone working on a JS port of Pytorch? I would love to work on it. We can look at how TF.js was coded and the pytorch codebase and try to build an inference and training pipeline.</p>

h_j: <p>Found this thread via a Google search and thought I’d mention this: <a href="https://github.com/microsoft/onnxjs" rel="nofollow noopener">https://github.com/microsoft/onnxjs</a> Benchmarks look really promising. Haven’t tried it yet.</p>
<p>There’s also this blog post: <a href="https://drsleep.github.io/Tutorial-PyTorch-to-TensorFlow-JS/" rel="nofollow noopener">https://drsleep.github.io/Tutorial-PyTorch-to-TensorFlow-JS/</a> which explains the tensorflow.js approach (pytorch --&gt; keras --&gt; tensorflow.js).</p>
<p>I think tensorflow.js is in the process of converting their code to WebAssembly, so perhaps the benchmarks with onnx.js will be much closer once that is finished.</p>

RicCu: <p>onnxjs was nice, but it hasn’t been updated in almost a year <img src="https://discuss.pytorch.org/images/emoji/apple/frowning_face.png?v=9" title=":frowning_face:" class="emoji" alt=":frowning_face:"></p>

Pierre_Snell: <p>Hi,<br>
Sorry to bump this thread.</p>
<p>Onnx is working quite nicely in nodejs and allow to run a lot of models !<br>
However, it allows only inference…</p>
<p>There is a pytorch implementation in C++ (libtorch) so maybe there could be some nodejs bindings (with NAPI ?) to train models in nodejs ?</p>
<p>Anyone is aware of a method to train models in JS or NodeJs ?</p>
<p>Thanks in advance,<br>
Have a great day.</p>

Nehc: <aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/torch-js/torch-js">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">

      <a href="https://github.com/torch-js/torch-js" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/345;"><img src="https://opengraph.githubassets.com/d63763b1c8000baab23e1ce32779cf5ebccc30f3c096399b5cf2335ae662f69a/torch-js/torch-js" class="thumbnail" width="690" height="345"></div>

<h3><a href="https://github.com/torch-js/torch-js" target="_blank" rel="noopener nofollow ugc">GitHub - torch-js/torch-js: Node.js binding for PyTorch.</a></h3>

  <p>Node.js binding for PyTorch. Contribute to torch-js/torch-js development by creating an account on GitHub.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


Ziyuan: <p>A more active fork: <a href="https://github.com/arition/torch-js" class="inline-onebox" rel="noopener nofollow ugc">GitHub - arition/torch-js: Node.js binding for PyTorch.</a></p>