22 comments

[ 0.14 ms ] story [ 1321 ms ] thread
(comment deleted)
Is this supposed to recognize a single digit? For me it can recognize only half of the digits correctly. What is the use case for sich a low-precision image recognition?
Judging by the fact the page gives no information about the model used but says it's "compiled on-the-fly to WebAssembly by loop_tool.js", I assume it's intended as a demo of loop_tool.js, not the model. It can't be a demo of MNIST itself. That's just a dataset, presumably used to train this model.
roll your own i-am-not-a-robot capture
It is trained on the mnist dataset, to have it recognize a digit you have to make sure the digit is sized roughly to fill the entire screen. It won't work if you draw a small digit in the corner. This is just a demo of the toolchain, it doesn't showcase any state of the art image recognition.
Ah, so it's a toolchain demo. That makes more sense, and I was also initially confused; it kept saying my 5s looked like 8s most of the time lol
The startup was excruciatingly slow ~20s, is it mining crypto in the background?
It is "compiled on the fly", including (hardware specific?) optimizations, which can take some time.
That's interesting. It was nearly instant on my iphone.
Would you mind sharing which device you're using? I'm still working on making the first compilation faster!
The code is compiled with Ecmascripten and the WASM binary is injected as part of the JS module. Since the downloading, processing and compiling is happening on the browser, it seems to be a reasonable time.

However, to avoid blocking the main thread, I would run all this process in a worker. Not sure if there's any limitation there

The quality is, ehm, not really good: https://imgur.com/a/uobGnpK
Unrelated to this demo, does anyone have pointers or recommendations for deploying 3D/WebGL + Wasm to the web?

Any good libraries, tools, or resources?

Wow the source code is kind of blowing my mind. I had no idea this was possible (only in theory).

  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 idea, I wonder if python wasm doesn’t make more sense though