www.xbdev.net
xbdev - software development
Thursday February 20, 2025
Home | Contact | Support | WebNN API Maching Learning On The Web (In The Browser) ...
     
 

WebNN API

Maching Learning On The Web (In The Browser) ...

 




Do You Want to Learn about WebNN?


The WebNN API is a builtin browser API - that enables web applications to perform machine 'learning inference' with high efficiency. It allows you to leverage hardware acceleration for neural network computations directly within web browsers (no need to install anything - the browser has it builtin).

WebNN has been in development since 2021 - with the First Public Working Draft published on June 22, 2021. The current version is now almost stable with very few changes.

The official documentation and details for the API are online (free and open source):
https://www.w3.org/TR/webnn/

What if you don't have WebNN?
You can still run Machine Learning projects in your browser - but you'll have to depend on external libraries - load them on the fly - ome popular web libraries for machine learning that you can use in a browser:

TensorFlow.js
ml5.js
Brain.js
Synaptic.js
ConvNetJS

As WebNN has been around since 2001 - there are lots of examples online - but most of them don't work - as the API has been through a number of changes - with API member functions getting renamed - this has caused a lot fo the online demos to `fail` - not constantly updated and maintained so they don't work anymore. It's a shame - but it's just the way things are with new API standards.

I've provided a few complete minimal working exaples below you can work through to get started - they run in a browser with out any external resoures - you can train them in a browser.


Working Examples (Notebooks)


Getting Started with WebNN (Simple Steps)

Training Network for WebNN (Sin Wave)

Conv2D Network (Images)

LTSM Text Example


Training with Synaptic


Train XOR Network with Synatpic.js And Use With WebNN

WebNN Sine Wave (Trained from Synaptic)


Example of training a neural network using Synaptic (iteratively watch the training) - uses a 1-17-17-1 network using ReLU. We ...
Example of training a neural network using Synaptic (iteratively watch the training) - uses a 1-17-17-1 network using ReLU. We save it out to a JSON and load it into the WebNN to use the trained network.



WebNN Example Using Tensorflow Training

WebNN Example Using PyTorch


WebNN Is Only 'Half' an API


A crucial point about WebNN - it's not the same as TensorFlor or Synaptic - it was primarily developed as a resource for `running` neural network projects (not training them). Hence, the WebNN is only half an API - no real training resources! So if you want to train a complex network - you can't do it! Instead you have to do thatin Python or another library - then save the trained network and load it into the WebNN.

As the official documentation says - WebNN is designed for neural network inference rather than training because it focuses on efficiently running pre-trained models in web applications. This allows for real-time AI tasks like image recognition and speech processing directly in the browser, without the need for server communication.

Personally, I think it was a bad decision to have WebNN focus on `inference` only - they could have had both! It would have made the API a much more attractive one stop solution for learning and developing solutions. Since you're downloading the trained model - it means you can download tensorflor or another library that would use WebGPU and do both and more - while WebNN is limited. Anyhow, it's too late now! They should have been more open minded and ambitious.


















WebNN API fast and to the point - get up to speed in 20 minutes. Become a JavaScript Ninja! Taste the JavaScript rainbow. Userscripts - Do you use the internet reguarly? Do you ever find web pages or tasks painful and annoying. WebGPU Development Pixels - coding fragment shaders from post processing to ray tracing! WebGPU by Example: Fractals, Image Effects, Ray-Tracing, Procedural Geometry, 2D/3D, Particles, Simulations WebGPU Games WGSL 2d 3d interactive web-based fun learning WebGPU Compute WebGPU API - Owners WebGPU Development Cookbook - coding recipes for all your webgpu needs! WebGPU & WGSL Essentials: A Hands-On Approach to Interactive Graphics, Games, 2D Interfaces, 3D Meshes, Animation, Security and Production Kenwright



 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.