webmachinelearning / webnn

🧠 Web Neural Network API
https://www.w3.org/TR/webnn/
Other
371 stars 46 forks source link

Add a more advanced example #70

Closed anssiko closed 4 years ago

anssiko commented 4 years ago

We should add a more advanced example to the spec that makes use of (some of) the new ops we've added to the spec recently. We should keep a simple "Hello World" style example and in addition add another more advanced one within a reasonable LOC limit.

The examples in specs are often a starting point for web developers who try out a new API for the first time, so we need to make sure the examples are maintained along the spec definition.

huningxin commented 4 years ago

I propose to add an example of convolution neural network (CNN) for handwritten digit classification. For example, we can use LeNet-5 topology as it only contains a few layers.

There are couple of references:

  1. The ONNX.js handwritten digit prediction demo showcases the real-world usage.
  2. The OpenVINO/nGraph example showcases about 100 lines of C++ code to build the LeNet.

Based on the reference, the required ops include: conv2d, add, maxPool2d, reshape, matmul, relu and softmax. All ops are supported by webnn spec except softmax which is being reviewed in PR #68.

anssiko commented 4 years ago

Thanks for the proposal! I feel this computer-vision problem is a classic and as such well suited for an advanced example and also gives us good op coverage with respect to what is specified currently.

Thoughts from others?

anssiko commented 4 years ago

Related RESOLUTION: Add an example of convolution neural network (CNN) for handwritten digit classification:

huningxin commented 4 years ago

Related RESOLUTION: Add an example of convolution neural network (CNN) for handwritten digit classification:

PR https://github.com/webmachinelearning/webnn-samples/pull/1 has been created.

A live version is hosted at: https://huningxin.github.io/webnn-samples/lenet/.

Here is a screenshot: image

The LeNet graph building code is about 74 LOC: https://github.com/huningxin/webnn-samples/blob/lenet/lenet/lenet.js#L22-L96 that uses conv2d, add, maxPool2d, reshape, matmul, relu and softmax ops.

If it looks good, I can create another PR to add the example into the spec.