Showing posts with label Data Science. Show all posts
Showing posts with label Data Science. Show all posts

ONNX Simplified


If you're working with machine learning models in frameworks like PyTorch or TensorFlow, you've likely heard of ONNX. But what exactly is ONNX, and why should you care about it when you're ready to move from model training to deployment?

Let’s break it down in a way that makes sense, even if you're not a deep learning expert.


What is ONNX?

ONNX stands for Open Neural Network Exchange. It’s an open-source format that allows you to move models between different frameworks and run them efficiently on various hardware. Think of it like exporting your Word document as a PDF so it can be viewed the same way on any device—ONNX lets your trained models be used across platforms regardless of the original training environment.


Why Do You Need ONNX?

When you train a model in TensorFlow or PyTorch, the model is saved in that framework’s own format. To run it elsewhere, you typically need the same framework installed. That can be bulky, complex, or incompatible with your production setup.

ONNX solves this by making your model framework-independent. This means:

  • You don’t need to install heavy ML libraries to run the model.

  • You can deploy the same model across different environments.

  • It’s easier to scale or integrate with production systems.


Benefits of Converting to ONNX

  1. Framework Freedom: Train in one tool, deploy in another.

  2. Optimized Inference: Use efficient runtimes like ONNX Runtime or TensorRT.

  3. Cross-platform Support: Run on cloud, edge, or mobile devices.

  4. Lower Latency & Memory Usage: Ideal for real-time systems.

  5. Hardware Acceleration: Take advantage of NVIDIA GPUs, Intel chips, and more.


When Should You Convert to ONNX?

  • When your model is trained and ready for deployment.

  • When your production environment doesn’t support your training framework.

  • When you want to run your model on devices with limited resources.

  • When performance (speed, memory) matters.


What About TensorFlow Models?

TensorFlow models can also be converted to ONNX using tools like tf2onnx. This opens up the same portability and performance benefits:

  • Share models with teams using other frameworks.

  • Use the model on devices that don’t support TensorFlow.

  • Optimize inference using non-TensorFlow runtimes.


What is TensorRT and How Does It Fit In?

TensorRT is a high-performance inference engine by NVIDIA. It makes deep learning models run faster on NVIDIA GPUs. Here’s what it does:

  • Reduces precision (e.g., from FP32 to FP16 or INT8) to save memory.

  • Optimizes operations for better performance.

  • Speeds up model inference in real-time applications.

Do You Need ONNX for TensorRT?

Not necessarily, but ONNX is the easiest and most versatile way to use TensorRT. TensorRT supports TensorFlow and Caffe as well, but ONNX provides:

  • Simpler integration

  • More framework compatibility

  • Less boilerplate code

So yes, TensorRT can work without ONNX, but ONNX makes it much more convenient and effective.


In Short

  • ONNX is your universal model format for deployment.

  • It makes AI models portable, fast, and production-ready.

  • It supports both PyTorch and TensorFlow workflows.

  • With ONNX, tools like TensorRT become easily accessible for further performance gains.

Whether you're working with PyTorch or TensorFlow, ONNX helps you bridge the gap between research and real-world use.

That’s all for this post.Thank you for reading! If you found this post helpful or have any questions about ONNX and AI deployment, please leave a comment below. Stay tuned for more insights on making AI easier and more accessible!


Difference between lazy learning and eager learning

Eager Learning  vs Lazy learning
When a machine learning algorithm builds a model soon after receiving training data set, it is called eager learning. It is called eager; because, when it gets the data set, the first thing it does – build the model. Then it forgets the training data. Later, when an input data comes, it uses this model to evaluate it. Most machine learning algorithms are eager learners.

K-NN vs K-Means

K-Nearest Neighbors (K-NN)
K-NN is a supervised algorithm used for classification. It means that we have some labelled data upfront which we provide to the model. It understand the dynamics within that data after training algorithm. It then uses those learnings to make inferences on the unseen data i.e. test. In the case of classification this labelled data is discrete in nature.

3D Spline fitting

This post is dedicated to interpolating spline from 3d point cloud data. In computer graphics, a spline is a smooth curve passing through two or more specific points. If points are in two dimension then we use regression techniques to interpolate the curve. But if data is having dimensions more than 2, fitting spline through the data is becomes more difficult. In this post we are dealing with noisy 3d data. 

Object Detection Using Machine Learning Techniques: A Fast Review

What is object detection ?
Predicting the location of the object along with the class is called object detection. so, object detection= locating object (localization ) + classifying object (classification). So in short, classification means answering ‘what’, and localization means answering ‘where’. 
e.g. Suppose you have an image , and you have to tell whether the image contains a cat or not. This is a classification problem, since we are referring to ‘what’ the image has. However, outlining the region within the image ‘where’ the cat is seen, is a localization problem. In short,
e.g. In the below image after classification we get elephant class.

Jupyter Notebook with Google Colab


Jupyter notebook is an open-source web application which allows us to create and share codes and documents. It provides an environment, where we can document our code, run it, look at the outcome, visualize data and see the results without leaving the environment. This makes it a handy tool for performing end to end data science workflows – data cleaning, statistical modeling, building and training machine learning models, visualizing data, and many, many other uses.

Jupyter Notebook Shortcuts

Shortcuts are one of the best things about Jupyter Notebooks. When you want to run any code block, all you need to do is press Ctrl+Enter. There are a lot more keyboard shortcuts that Jupyter notebooks offer that save us a bunch of time. Below are a few shortcuts we hand picked that will be of immense use to you, when starting out. I highly recommend trying these out as you read them one by one. You won’t know how you lived without them! 

Pandas for complete beginers

Introduction
This tutorial explains the basics and various functions of Pandas. It is one of the mostly used opensource python library for data analysis. It uses most of the functionalities of NumPy.  Pandas deals with the three data structures − Series, DataFrame and Panel. Series is  1D labeled homogeneous array, it is sizeimmutable. A Data frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. Pandas DataFrame consists of three principal components, the data, rows, and columns.


Python Libraries Numpy and Scipy for Beginers

Introduction to Numpy

NumPy, which stands for Numerical Python, is a library consisting of multidimensional array objects and a collection of routines for processing those arrays. Using NumPy, mathematical and logical operations on arrays can be performed. This tutorial explains the basics of NumPy. It is prepared for those who want to learn about various functions of NumPy. It is specifically useful for algorithm developers.

Hand written digits classification using OpenCV

This tutorial is about how to classify handwritten digit from scratch using SVM classifier.

SVM (Support vector machine) classifier – 
SVM (Support vector machine) is an efficient classification method for high dimensional feature vector. We use here SVM implementation of python library sci-kit learn. In sci-kit learn, we can specify the kernel function (here, linear). For more detail  about kernel functions and SVM refer – SVM Kernels and SVM.

My Kinect 3D Background and Foreground Subtraction Demo

Background subtraction is a classic computer vision technique used to separate the foreground (the subject of interest) from the backg...