How to run a fastai model in the browser

As a data protection lawyer, I am very aware of the privacy implications when it comes to model deployment. That’s what got me thinking: Could you train a model in fastai and run it in the browser? Turns out you can!

All the pieces were already in place, but it was somewhat difficult to connect that dots. So I open-sourced my pet project and wrote a short blog post documenting the findings.

If you find any mistakes that I made, please let me know! I want to thank everybody in the fastai community, which is the most helpful community I have ever encountered.

11 Likes

Awesome!!. Can I use your front-end code for my personal project?

Yes, please go ahead. See License section in README, but tldr: my code is MIT licensed.

3 Likes

Hi, Looks like it doesn’t work anymore - I’m getting the following error:

Uncaught (in promise) Error: invalid inputs detected; op: unnamed_BatchNormalization_20

Turns out onnx.js 0.1.7 somehow doesn’t like the nn.BatchNorm1d layer. The workaround I found was to disable the input check in onnx.min.js (I had to pretty-print it first using Chrome dev tools, and we’re looking at lines 19789-19790):

if (!(t = e.op).checkInputs(h))
    throw new Error("invalid inputs detected; op: " + e.node.name);

If you comment these two out and add the below line instead, it works again:

t = e.op;
2 Likes