Mnist Demo Compiled On-the-Fly to WebAssembly in the Browser
mnist-demo.glitch.me
mnist-demo.glitch.me
import * as torch from "./torch.mjs";
...
const w0 = torch.tensor(weights["conv1.0.weight"]);
const b0 = torch.tensor(weights["conv1.0.bias"]);
const w1 = torch.tensor(weights["conv2.0.weight"]);
const b1 = torch.tensor(weights["conv2.0.bias"]);
const lw = torch.tensor(weights["out.weight"]);
const lb = torch.tensor(weights["out.bias"]);
const convs = nn.Sequential(
nn.Conv2d(w0, b0, 1, 2),
nn.MaxPool2d(2),
nn.ReLU(),
nn.Conv2d(w1, b1, 1, 2),
nn.MaxPool2d(2),
nn.ReLU()
);
...
Looks like near identical python torch code except apparantely running in local js!Cool demo nontheless!
I don't hold the in browser POC at fault for the trained model (but am amused by the efficacy of the model).
Any good libraries, tools, or resources?
In particular, the interface between WASM and WebGL: https://github.com/speps/tt/blob/master/web/tt.js#L45
WASM is really quite straightforward in my opinion, export a C interface and link it with whatever you need from the browser APIs.
However, to avoid blocking the main thread, I would run all this process in a worker. Not sure if there's any limitation there