4

I'm looking into running a trained PyTorch model (containing LSTM/GRU layers) fully in the browser (no backend) as part of an interactive blog post. I've looked at ONNX.js, and that works great, but not for a model containing a GRU layer. I saw someone comment on the ONNX.js github that Gated RNN's are not supported yet, but that was over half a year ago and I can't find any other information about this.

Other than that, it seems like the best option would be to just rewrite the model in Tensorflow and export to Tensorflow.js.

Is there an easier and more direct solution?

Bart
  • 1,077
  • 1
  • 12
  • 22
  • I would just give it a try. Create a sequence with a single LSTM layer, and then just export it. You don't have to train it. If you can run it on Onnx and get random output of the correct shape, then it should be working. – Reactgular Feb 21 '20 at 18:44
  • 1
    Yes I've tried that and the export succeeds, but it gives an error when loading it in ONNX.js. Googling the error gives me 1 hit of someone saying it isn't supported in ONNX.js yet. So i guess it's supported in ONNX, but not the javascript library. – Bart Feb 23 '20 at 13:50
  • 1
    Onnx is the only library I've seen as a successful path to JavaScript for PyTorch, and if that's not working then I'd move onto TensorFlow. When you're targeting JavaScript your options are limited to what works, and not what is best. It would be nice if we could run everything in JS, but honestly these models can quickly grow beyond a reasonable download size. Small models aren't very useful on big problems. So I don't think people take JS very seriously for AI. – Reactgular Feb 23 '20 at 14:40

1 Answers1

1

There is this thread, that describes the options but is not receiving a lot of attention.

In summary, as of May 2020, there are only two options:

1) ONNX.js but its development is currently stale.

2) Converting the model to Tensorflow.

Technically there is a third one, that includes no server. And that is to run the model in a Mobile Application.

Santiago M. Quintero
  • 1,237
  • 15
  • 22