This device is not compatible.


Using a PyTorch Model in JavaScript with ONNX

Get hands-on experience converting a pre-trained model in PyTorch and loading it in JavaScript with ONNX. We'll test the model performance before and after the conversion to verify that the conversion was done successfully.

Using a PyTorch Model in JavaScript with ONNX

You will learn to:

Use a pre-trained model in PyTorch.

Export a PyTorch model using ONNX.

Use the ONNX model in JavaScript.

Integrate a machine learning model in JavaScript.


Machine Learning

Using ML Models On The Web


Machine learning basics

Python programming basics

JavaScript programming basics





Project Description

In this project, we’ll convert a PyTorch model and use it in JavaScript with ONNX.

The Open Neural Network Exchange (ONNX) is an open-source artificial intelligence ecosystem that promotes innovation and collaboration in the AI sector. ResNet-18 is an 18 layer deep, convolutional neural network used for image classification.

We’ll start by importing a pre-trained ResNet-18 model. Then we’ll export the model from Python to ONNX. At the end of this project, we’ll import this model in JavaScript and use it to make predictions.

Project Tasks


Building Pytorch Model

Task 0: Introduction

Task 1: Load ResNet-18 Model

Task 2: Make a Prediction

Task 3: Export Model to ONNX



Task 4: Load the ONNX Model

Task 5: Transform the Image

Task 6: Make a Prediction

Task 7: Get the Class Name

Task 8: Start the Application

Task 9: Test the Model