JavaScript ML Frameworks vs Native JavaScript API
WebNN can be used either through supported JavaScript machine learning frameworks or directly via its native API. Choose the approach that best suits your needs.
ML Frameworks
WebNN API is integrating into major JavaScript machine learning frameworks like ONNX Runtime Web, Transformers.js, and LiteRT. This enables web developers to build AI applications using these high-level frameworks with less codes while leveraging WebNN’s efficient, low-level neural network operations.
Native WebNN API
Use the WebNN API directly to create custom computational graphs and neural network models with greater flexibility in your AI applications. However, building models with the raw WebNN API requires more complex code compared to using mature solutions like ONNX and TFLite.
Using the WebNN JavaScript API directly instead of a ML framework reduces application size by eliminating framework distributions overhead.