How can ONNX help you in your ML pipeline


Hello Reader,

Welcome to another edition of the AIFEE newsletter!

Another week, another Machine Learning topic!

This week, I want to share more insights about ONNX framework.

What is ONNX?

​

​

​

In last week's edition, I shared with you different approaches you can use to deploy your Tensorflow models in C++. One of these approaches is by using ONNX Runtime.

​
So ONNX (Open Neural Network Exchange) is a framework or a whole ecosystem that allows for the standardization of neural networks.
​
Here’s the problem that ONNX is trying to solve.
​
There are many machine learning frameworks and libraries. Pytorch, Tensorflow and scikit-learn are famous examples.
​
Which one should you use?
​
Well, the answer is : it depends on so many factors!
​
There is no free launch!
​
So what ONNX aims to do is to make your choice easier. Basically, you can choose whichever framework you want, train your model with it and then, once you’re happy with your model, transform it into ONNX format and keep the production code working in ONNX only.
​
So ONNX will help you achieve 3 things:

  • Keep your options open when it comes to choosing a machine learning library for your training.
  • Standardize your production code, since you’ll only need to maintain one main dependency which is for ONNX.
  • Moreover, you can use your ONNX models in Python, C++ or other languages.

Transforming models to ONNX format

If you're a Tensorflow developer or PyTorch developer then the first step for you to use ONNX in production would be to transform your model to ONNX format.
​
To transform your Tensorflow models into onnx format, you can use a tool called tf2onnx. The image below shows how to use this tool.

​

​
You can learn more about this tool on their github repo.
If you’re a Pytorch user, then you can transform your model from torch to onnx format directly using Pytorch. This is done using the module torch.onnx.
An example of this can be found here.

Deploying ONNX models in C++

Transforming your models to ONNX format is just the beginning. After this, you can deploy your model using different programming languages.

To deploy your ONNX models in C++, there is a library called ONNX Runtime which you can use to load your ONNX models and make predictions.

If you’re a Visual Studio user (not VS Code!) then the easiest way to install this library is by using NuGet packages. You can simply go to β€œProject” then β€œManage nuget packages”. In the search bar you type β€œonnx runtime”.

After that you click on β€œinstall”.

With this library, you can load any onnx model that you converted from Tensorflow or Pytorch.

Many examples can be found in the docs.

Machine Learning for Medical Imaging

πŸ‘‰ Learn how to build AI systems for medical imaging domain by leveraging tools and techniques that I share with you! | πŸ’‘ The newsletter is read by people from: Nvidia, Baker Hughes, Harvard, NYU, Columbia University, University of Toronto and more!

Read more from Machine Learning for Medical Imaging

Hi Reader! I hope you're doing well in this fine weekend! In the past weeks I've been working on implementing basic image segmentation models for 2D and 3D from scratch. While doing so, I found a few things that were delightfully surprising while other things were painfully irritating. I tell you all about it in this edition of the newsletter! What Building AI Models from Scratch has Thought me One of the reasons why I did these experimentations was to understand some of the nitty gritty...

Hi Reader, I haven't sent you a newsletter email for some time now. This is because there are major events happening in my personal life. We just had our first kid, so I'm still trying to adapt to the new routine set by this cute little creature! I also changed my office! I used to work from home, but now I am working in a coworking space. I'm hoping that this will help me deliver more value to the newsletter subscribers as well as our clients at PYCAD. Now, back to the newsletter! I've got...

Dental implant - Wikipedia

Hello Reader, Welcome to another edition of PYCAD newsletter where we cover interesting topics in Machine Learning and Computer Vision applied to Medical Imaging. The goal of this newsletter is to help you stay up-to-date and learn important concepts in this amazing field! I've got some cool insights for you below ↓ Applications of Machine Learning for Dentistry At PYCAD, we have worked a lot on the applications of AI to the dentistry domain. Here are 3 incredible ones. 1 - Diagnosis and...