Running pytorch models in browser

Hi,

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?

5 Likes

Writing in order to bump this. I have no idea, but I’ve been seeing demos that run Keras & Tensorflow models…

Presumably the answer is, “Great idea, why don’t you write this and we’ll include it! ;-)”, but… Is anyone working on this?

UPDATE: Seems the thing to do is save your model in ONNX format, an then use web tools that can read ONNX.

AFAIK currently the only way to do this would be:
PyTorch -> ONNX -> TensorFlow -> TensorFlow.js

4 Likes

It tried it with a PyTorech based U-net did not work with PyTorch 0.4

1 Like

Any alternative on tensorflow? I do not want to convert my code to tensorflow since I have custom loss functions

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.

6 Likes

Found this thread via a Google search and thought I’d mention this: https://github.com/microsoft/onnxjs Benchmarks look really promising. Haven’t tried it yet.

There’s also this blog post: https://drsleep.github.io/Tutorial-PyTorch-to-TensorFlow-JS/ which explains the tensorflow.js approach (pytorch --> keras --> tensorflow.js).

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.

1 Like

onnxjs was nice, but it hasn’t been updated in almost a year :frowning_face:

1 Like

Hi,
Sorry to bump this thread.

Onnx is working quite nicely in nodejs and allow to run a lot of models !
However, it allows only inference…

There is a pytorch implementation in C++ (libtorch) so maybe there could be some nodejs bindings (with NAPI ?) to train models in nodejs ?

Anyone is aware of a method to train models in JS or NodeJs ?

Thanks in advance,
Have a great day.

A more active fork: GitHub - arition/torch-js: Node.js binding for PyTorch.