Mastering Object Detection with YOLO-NAS

Rania
Clique Community
Published in
6 min readJul 30, 2023

Object detection is a challenging task, but it is becoming increasingly important as we move into a world where machines need to be able to understand the world around them. I’m sure that many of you must have heard about the famous YOLO (You Only Look Once) algorithm if you are familiar with the world of computer vision. We now have YOLO-NAS, which is a new object detection model that is more efficient and accurate than previous versions of YOLO. It works by using a neural architecture search (NAS) technique to automatically design the network architecture. This means that YOLO-NAS can find the best network architecture for a particular task without any human intervention. Think of it as YOLO on steroids, with an extra sprinkle of magic. It’s like YOLO decided to hit the gym, learn some new tricks, and return even stronger, faster, and smarter than ever before.

This new found automation in YOLO-NAS is a game-changer, enabling researchers and developers to focus on the bigger picture and innovative applications rather than getting bogged down in architecture design. It’s like having an AI architect at your service, meticulously crafting the most efficient and powerful models for object detection tasks.

We can see from the graph given below that all versions of YOLO-NAS achieves good accuracy as compared to previous versions of YOLO models.

Source: Deci-AI YOLO-NAS

In this blog post, we will take a closer look at YOLO-NAS and see how it works.

Versions of YOLO-NAS:

YOLO-NAS is a new object detection model that comes in three different sizes: S, M, and L. The size of the model determines its accuracy and efficiency. The S version is the smallest and most efficient, but it is also the least accurate. The M version is a good balance between accuracy and efficiency. The L version is the largest and most accurate, but it is also the least efficient.

Source: Deci-AI YOLO-NAS

In addition to the three main versions, there are also quantized versions of YOLO-NAS. Quantized models are smaller and faster than non-quantized models, but they may have a slightly lower accuracy.

Let’s try to understand Quantization better:
Quantization is a useful technique to deploy deep learning models on resource-constrained devices like mobile phones, embedded systems, or IoT devices. It allows the model to be more lightweight, reducing memory footprint and enabling real-time inference on devices with limited computational power.

  1. YOLO Model without Quantization: In the context of machine learning and neural networks, quantization refers to the process of converting high-precision floating-point numbers (usually 32-bit) into lower-precision fixed-point or integer representations. When we talk about the YOLO model without quantization, it means that the model’s parameters, activations, and computations are represented using full precision (usually 32-bit floating-point numbers). This results in a more accurate but potentially larger and computationally intensive model.
  2. YOLO Model with Quantization: On the other hand, the YOLO model with quantization applies the technique of quantization to the model’s parameters and activations. By using lower-precision representations (e.g., 8-bit fixed-point or even binary), the model becomes more memory-efficient and computationally faster. However, the downside of quantization is that it may lead to a slight degradation in model accuracy compared to the full-precision counterpart.

Use of AutoNAC in YOLO-NAS:

In YOLO-NAS, AutoNAC is used to design the network architecture. AutoNAC stands for Automated Neural Architecture Construction. It is a technique that uses machine learning to automatically design neural network architectures. This is a challenging task, as there are a vast number of possible architectures to choose from. AutoNAC addresses this challenge by using a reinforcement learning algorithm to search for the best architecture for a particular task.

The use of AutoNAC in YOLO-NAS has several benefits. First, it allows YOLO-NAS to find a network architecture that is more efficient than those that can be designed by humans. Second, the use of AutoNAC allows YOLO-NAS to find a network architecture that is more scalable.

Overall, the use of AutoNAC is a significant improvement over previous versions of YOLO. This makes YOLO-NAS a powerful tool for object detection applications.

Source: Deci-AI

Moreover, YOLO-NAS is pre-trained on prominent datasets such as COCO, Objects365, and Roboflow 100. Pre-training YOLO-NAS on a large dataset of images allows it to learn the features that are common to objects. This makes it more accurate at detecting objects in new images.

Implementation of YOLO-NAS:

Step 1: To try out YOLO-NAS, we need to install the super-gradients library which is a Deci’s Pytorch-based computer vision library.

pip install super-gradients

Step 2: Import the Super-Gradients library and retrieve the model by using the version according to your requirement. Here, we will be using the yolo_nas_l version.

from super_gradients.training import models
#Retrieve the model
yolo_nas_l = models.get("yolo_nas_l", pretrained_weights="coco")

Step 3: Infer on images. I have used the following codes for the inference.

#Infer on an image
url = 'https://www.heart.org/-/media/Images/News/2022/April-2022/0406WalkingSpeedHealth_SC.jpg'
yolo_nas_l.predict(url).show()

url_2 = 'https://www.cultofmac.com/wp-content/uploads/2021/11/Setup-Cypher_27-Reddit-Nov-4-2021-1536x1152.jpg'
yolo_nas_l.predict(url_2).show()

url_3 = 'https://ggsc.s3.amazonaws.com/images/made/images/uploads/The_Emotional_Life_of_Animals_And_What_It_Means_for_Us_600_399_int_c1-2x.png'
yolo_nas_l.predict(url_3).show()

Here are the output images generated by the model:

Result #1
Result #2
Result #3

As you can see in the Result #1, even the background objects like the parking meter and the fire hydrant are detected by the model. This proves the efficiency of the model.

#Bonus TIP:

During the setup of YOLO-NAS, I had difficulty in installing super-gradients in my environment. It had some errors like:
error: could not build wheels for pycocotools, which is required to install pyproject.toml-based projects’

If you face similar issues, try downloading Visual Studio Build Tools from the below link:
https://visualstudio.microsoft.com/downloads/

After the download is complete, choose the tools as given in the image below and complete the setup by installing it. Hopefully, the super-gradients installation will work after that as it did for me.

Visual Studio Tools Setup

Conclusion:

In this blog post, we have explored the YOLO-NAS object detection model. We have seen how YOLO-NAS uses AutoNAC to automatically design neural network architectures. We have also seen how Super Gradients can be used to train and deploy YOLO-NAS.

Overall, YOLO-NAS is a powerful tool that can be used to build efficient and accurate object detection applications.
Some additional thoughts:

  1. YOLO-NAS is still a relatively new model, so there is still room for improvement. However, it is already showing great promise and has the potential to revolutionize the field of object detection.
  2. The use of neural architecture search is a rapidly growing field, and there are many other NAS libraries available besides Super Gradients. If you are interested in learning more about NAS, I encourage you to check out some of the other libraries that are available.

Thank you for reading it till the end. Here is my LinkedIn if you wish to connect!
https://www.linkedin.com/in/rania-syed-89596a21a/

References:

https://medium.com/codex/decis-yolo-nas-next-generation-model-for-object-detection-8ccb7f2013a7

https://docs.ultralytics.com/models/yolo-nas/

--

--