{"id":7057,"date":"2023-08-08T11:49:36","date_gmt":"2023-08-08T19:49:36","guid":{"rendered":"https:\/\/live-cometml.pantheonsite.io\/?p=7057"},"modified":"2025-04-24T17:14:55","modified_gmt":"2025-04-24T17:14:55","slug":"introducing-yolo-nas-a-new-state-of-the-art-for-object-detection","status":"publish","type":"post","link":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/","title":{"rendered":"Introducing YOLO-NAS: A New State-of-the-Art for Object Detection"},"content":{"rendered":"\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<figure class=\"mj mk ml mm mn mo mg mh paragraph-image\">\n<div class=\"mp mq eb mr bg ms\" tabindex=\"0\" role=\"button\">\n<div class=\"mg mh mi\">\n<\/div><\/div><\/figure><\/div><\/div><\/div>\n\n\n\n<figure class=\"wp-block-image alignnone bg mt mu c\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*mR__xCOs_j8c5A0hMq3B5Q.gif\" alt=\"GIF of YOLO-NAS predicting object detection bounding boxes on a scene of a woman dancing in her pajamas with a cup of coffee in the kitchen.\"\/><figcaption class=\"wp-element-caption\">\ud83c\udfce\ufe0fYOLO-NAS in action<\/figcaption><\/figure>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"794d\">YOLO models are famous for two main reasons:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Impressive speed and accuracy.<\/li>\n\n\n\n<li>Ability to detect objects in images quickly and dependably.<\/li>\n<\/ol>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"8957\">The first version of YOLO was introduced in 2016 and changed how object detection was performed by treating object detection as a single regression problem.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"ef77\">It divided images into a grid and simultaneously predicted bounding boxes and class probabilities. Though it was faster than previous object detection methods, YOLOv1 had limitations in detecting small objects and struggled with localization accuracy. Since the first YOLO architecture hit the scene, 15 <a class=\"af og\" href=\"https:\/\/deeplearningdaily.substack.com\/p\/welcome-to-the-world-of-yolo-where\" target=\"_blank\" rel=\"noopener ugc nofollow\">YOLO-based architectures have been developed<\/a>, all known for their accuracy, real-time performance, and enabling object detection on edge devices and in the cloud.<\/p>\n\n\n\n<p class=\"oh oi fo be oj ok ol om on oo op oq or ni os ot ou nm ov ow ox nq oy oz pa pb bj\" id=\"ac0f\"><strong>But just because we have all these YOLOs doesn\u2019t mean that deep learning for object detection is a dormant area of research.<\/strong><\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"1389\">In the subfield of computer vision, the competition for cutting-edge object detection is fierce.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"26cd\">At Deci, <a class=\"af og\" href=\"https:\/\/deeplearningdaily.substack.com\/p\/unleashing-the-power-of-yolo-nas\" target=\"_blank\" rel=\"noopener ugc nofollow\">a team of researchers aimed to create a model that would stand out amongst the rest<\/a>. Their objective was to make revolutionary improvements, just as sprinters aim to shave milliseconds off their times. The team embraced the challenge of pushing the limits of performance, knowing that even small increases in mAP and reduced latency could truly revolutionize the object detection model landscape.<\/p>\n\n\n\n<h2 class=\"wp-block-heading ph oi fo be oj pi pj go on pk pl gr or pm pn po pp pq pr ps pt pu pv pw px py bj\" id=\"d0d6\">And in the process, a new YOLO architecture was born: \ud83c\udfce\ufe0fYOLO-NAS<\/h2>\n\n\n\n<figure class=\"mj mk ml mm mn mo mg mh paragraph-image\">\n<div class=\"mp mq eb mr bg ms\" tabindex=\"0\" role=\"button\">\n<div class=\"mg mh pz\">\n<picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*RIE_7B2kytLZA4uhlc1Hsg.gif 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture>\n<\/div><\/div><\/figure>\n\n\n\n<figure class=\"wp-block-image alignnone bg mt mu c\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*RIE_7B2kytLZA4uhlc1Hsg.gif\" alt=\"A diagram of the neural architecture of YOLO-NAS, including the backbone, neck, and head compononets.\"\/><figcaption class=\"wp-element-caption\">The \ud83c\udfce\ufe0fYOLO-NAS Architecture<\/figcaption><\/figure>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"1727\">YOLO-NAS is composed of a backbone, neck, and head, mirroring many similar models.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"a8f7\">The backbone extracts features from the input image.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"d160\">YOLO-NAS has a dual-path backbone with dense feature extraction and sparse feature fusion paths. The dense path has multiple convolutional layers with skip connections in dense blocks, while the transition blocks in the sparse path reduce spatial resolution and boost the number of channels. Both paths interconnect via cross-stage partial connections, which enables gradient flow.<\/p>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<blockquote class=\"qi\"><p id=\"b93a\" class=\"qj qk fo be ql qm qn qo qp qq qr nu dv\" data-selectable-paragraph=\"\">Innovation and academia go hand-in-hand. Listen to our own CEO Gideon Mendels chat with the Stanford MLSys Seminar Series team about the future of MLOps and <a class=\"af og\" href=\"https:\/\/www.youtube.com\/watch?v=7XCsi64HLQ8%3Futm_source%3Dheartbeat&amp;utm_medium=referral&amp;utm_campaign=AMS_US_EN_AWA_heartbeat_CTA\" target=\"_blank\" rel=\"noopener ugc nofollow\">give the Comet platform a try for free<\/a>!<\/p><\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<p id=\"81bc\" class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" data-selectable-paragraph=\"\">The neck further enhances the features extracted by the backbone, creating predictions at varied scales.<\/p>\n<p id=\"b465\" class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" data-selectable-paragraph=\"\">The YOLO-NAS system utilizes a multi-scale feature pyramid and backbone features to make small, medium, and large predictions. The neck of the system combines upsampling and concatenation to blend features from various levels, thus broadening the receptive field. The head performs final classification and regression tasks.<\/p>\n<p id=\"98b5\" class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" data-selectable-paragraph=\"\">The YOLO-NAS head consists of two parallel branches.<\/p>\n<p id=\"cfbc\" class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" data-selectable-paragraph=\"\">One is a classification branch, and the other is a regression branch that uses generalized IoU loss. The classification branch predicts the class probability of each anchor box, while the regression branch estimates the bounding box coordinates.<\/p>\n<h2 id=\"e751\" class=\"ph oi fo be oj pi pj go on pk pl gr or pm pn po pp pq pr ps pt pu pv pw px py bj\">What\u2019s New in \ud83c\udfce\ufe0fYOLO-NAS?<\/h2>\n<figure class=\"mj mk ml mm mn mo mg mh paragraph-image\">\n<div class=\"mp mq eb mr bg ms\" tabindex=\"0\" role=\"button\">\n<div class=\"mg mh qs\">\n<picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*11VfHXRB2KEefut1rrSy4g.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*11VfHXRB2KEefut1rrSy4g.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*11VfHXRB2KEefut1rrSy4g.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*11VfHXRB2KEefut1rrSy4g.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*11VfHXRB2KEefut1rrSy4g.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*11VfHXRB2KEefut1rrSy4g.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*11VfHXRB2KEefut1rrSy4g.png 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*11VfHXRB2KEefut1rrSy4g.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*11VfHXRB2KEefut1rrSy4g.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*11VfHXRB2KEefut1rrSy4g.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*11VfHXRB2KEefut1rrSy4g.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*11VfHXRB2KEefut1rrSy4g.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*11VfHXRB2KEefut1rrSy4g.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*11VfHXRB2KEefut1rrSy4g.png 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture>\n<\/div><\/div><\/figure><\/div><\/div><\/div>\n\n\n\n<figure class=\"wp-block-image alignnone bg mt mu c\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*11VfHXRB2KEefut1rrSy4g.png\" alt=\"Graph showing the accuracy vs latency of the YOLO-NAS model, as compared with other YOLO model versions; YOLO-NAS performs far better (faster and more accurate) than any other YOLO version).\"\/><figcaption class=\"wp-element-caption\">\ud83c\udfce\ufe0fYOLO-NAS vs The World<\/figcaption><\/figure>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"277c\">\u2728 YOLO-NAS utilizes cutting-edge methods such as attention mechanisms, quantization aware blocks, and inference time reparametrization, raising the bar for object detection in various industries.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"bc0d\">\u2728 It\u2019s an open-source model with pre-trained weights (for non-commercial research) through Deci\u2019s PyTorch-based computer vision library called <a class=\"af og\" href=\"https:\/\/github.com\/Deci-AI\/super-gradients\" target=\"_blank\" rel=\"noopener ugc nofollow\">SuperGradients<\/a>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"f873\">\u2728 It\u2019s a foundation model for object detection pretrained on COCO, Objects365, and Roboflow 100, preparing you for success in downstream object detection tasks.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"6e06\">\u2728 The algorithm for selecting layers in the model quantizes certain parts to minimize loss of information while ensuring a balance between latency and accuracy.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"ed05\">\u2728 Post-training, the network converts to INT8, enhancing efficiency even further.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"1fc4\">\u2728 Compared to other top YOLO models, YOLO-NAS (m) model achieves a 50% increase in throughput and a 1 mAP improvement in accuracy on the NVIDIA T4 GPU.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"6ec4\">There\u2019s no paper for YOLO-NAS, but <a class=\"af og\" href=\"https:\/\/deci.ai\/blog\/YOLO-NAS-object-detection-foundation-model\" target=\"_blank\" rel=\"noopener ugc nofollow\">a technical blog<\/a> details the architecture and training procedure.<\/p>\n\n\n\n<h2 class=\"wp-block-heading ph oi fo be oj pi pj go on pk pl gr or pm pn po pp pq pr ps pt pu pv pw px py bj\" id=\"f6b1\">\ud83e\udee3 Sneak peek: Inference with YOLO-NAS<\/h2>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"d589\">Before jumping into the section on fine-tuning, I wanted to show you the power of YOLONAS out of the box.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"2510\">Start by instantiating a pretrained model. YOLONAS comes in three flavors: <code class=\"cw qt qu qv qw b\">yolo_nas_s<\/code>, <code class=\"cw qt qu qv qw b\">yolo_nas_m<\/code>, and <code class=\"cw qt qu qv qw b\">yolo_nas_l<\/code>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"ae61\">You\u2019ll use <code class=\"cw qt qu qv qw b\">yolo_nas_l<\/code> throughout this tutorial. Because you should always go big or go home.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"a93f\">It\u2019s a good life philosophy.<\/p>\n\n\n\n<h3 class=\"wp-block-heading oh oi fo be oj ok ol om on oo op oq or ni os ot ou nm ov ow ox nq oy oz pa pb bj\" id=\"847a\">\ud83d\udc68\ud83c\udffd\u200d\ud83d\udd27 Install SuperGradients<\/h3>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"8ad5\"><strong class=\"be qx\">\ud83d\udea8 Note (for Google Colab):<\/strong> after installation is complete (it will take a few minutes), you\u2019ll need to restart the runtime after installation completion.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"7826\">This is a known <a class=\"af og\" href=\"https:\/\/github.com\/obss\/sahi\/discussions\/781\" target=\"_blank\" rel=\"noopener ugc nofollow\">issue<\/a> that is on our roadmap.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"2d7c\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\">pip install super-gradients==3.1.1<\/span><\/pre>\n\n\n\n<h3 class=\"wp-block-heading oh oi fo be oj ok ol om on oo op oq or ni os ot ou nm ov ow ox nq oy oz pa pb bj\" id=\"4a0d\">\ud83d\udc47\ud83c\udffdInstantiate a pre-trained model<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"1c9a\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> super_gradients.training <span class=\"hljs-keyword\">import<\/span> models\n\nyolo_nas_l = models.get(<span class=\"hljs-string\">\"yolo_nas_l\"<\/span>, pretrained_weights=<span class=\"hljs-string\">\"coco\"<\/span>)<\/span><\/pre>\n\n\n\n<h3 class=\"wp-block-heading oh oi fo be oj ok ol om on oo op oq or ni os ot ou nm ov ow ox nq oy oz pa pb bj\" id=\"e580\">\ud83d\uddbc\ufe0f Inference on an image<\/h3>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"476e\">Once the model has been instantiated all you have to do is call the <code class=\"cw qt qu qv qw b\">predict<\/code>method.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"f4fe\">This method operates on:<br>\n\u2733\ufe0f PIL Image<br>\n\ufe0f\ufe0f\u2733\ufe0f Numpy Image<br>\n\u2733\ufe0f A path to an image file<br>\n\u2733\ufe0f A path to video file<br>\n\u2733\ufe0f A path to folder with images<br>\n\u2733\ufe0f URL (Image only)<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"5bdb\"><strong class=\"be qx\">Note<\/strong>: Predict also has an argument called <code class=\"cw qt qu qv qw b\">conf<\/code>, the threshold for detection. You change this value as you like, for example: <code class=\"cw qt qu qv qw b\">model.predict(\u201cpath\/to\/asset\u201d,conf=0.25)<\/code>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"e38e\">Let\u2019s perform inference on the following image:<\/p>\n\n\n\n<figure class=\"mj mk ml mm mn mo mg mh paragraph-image\">\n<div class=\"mp mq eb mr bg ms\" tabindex=\"0\" role=\"button\">\n<div class=\"mg mh rg\">\n<picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*_VzWcwxi1JRmm5vIQIbsJw.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*_VzWcwxi1JRmm5vIQIbsJw.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*_VzWcwxi1JRmm5vIQIbsJw.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*_VzWcwxi1JRmm5vIQIbsJw.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*_VzWcwxi1JRmm5vIQIbsJw.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*_VzWcwxi1JRmm5vIQIbsJw.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*_VzWcwxi1JRmm5vIQIbsJw.png 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*_VzWcwxi1JRmm5vIQIbsJw.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*_VzWcwxi1JRmm5vIQIbsJw.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*_VzWcwxi1JRmm5vIQIbsJw.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*_VzWcwxi1JRmm5vIQIbsJw.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*_VzWcwxi1JRmm5vIQIbsJw.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*_VzWcwxi1JRmm5vIQIbsJw.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*_VzWcwxi1JRmm5vIQIbsJw.png 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture>\n<\/div><\/div><\/figure>\n\n\n\n<figure class=\"wp-block-image alignnone bg mt mu c\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*_VzWcwxi1JRmm5vIQIbsJw.png\" alt=\"An image of a group of friends in their twenties congregating around a coffee table with sodas and popcorn; some of the friends pose for a cell phone photo.\"\/><figcaption class=\"wp-element-caption\">An image for \ud83c\udfce\ufe0fYOLO-NAS to perform inference on<\/figcaption><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"a4a2\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\">url = <span class=\"hljs-string\">\"https:\/\/previews.123rf.com\/images\/freeograph\/freeograph2011\/freeograph201100150\/158301822-group-of-friends-gathering-around-table-at-home.jpg\"<\/span>\nyolo_nas_l.predict(url, conf=<span class=\"hljs-number\">0.25<\/span>).show()<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"28ac\"><strong class=\"be qx\">\ud83e\udd37\ud83c\udffd\u200d\u2642\ufe0f What\u2019s happening \u201cunder the hood\u201d<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Input image gets through the preprocessing pipeline, which includes image resizing, normalization, and permute operation to convert input RGB image to torch tensor.<\/li>\n\n\n\n<li>Model inference<\/li>\n\n\n\n<li>Postprocessing of the detection results (Non-maximum suppression, resizing bounding boxes to the size of the original image)<\/li>\n\n\n\n<li>Visualization of the results (Rendering of bounding boxes on top of the image)<\/li>\n<\/ol>\n\n\n\n<figure class=\"mj mk ml mm mn mo mg mh paragraph-image\">\n<div class=\"mp mq eb mr bg ms\" tabindex=\"0\" role=\"button\">\n<div class=\"mg mh rh\">\n<picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*R58RgRj5jihRgfDjm-XDhw.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*R58RgRj5jihRgfDjm-XDhw.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*R58RgRj5jihRgfDjm-XDhw.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*R58RgRj5jihRgfDjm-XDhw.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*R58RgRj5jihRgfDjm-XDhw.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*R58RgRj5jihRgfDjm-XDhw.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*R58RgRj5jihRgfDjm-XDhw.png 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*R58RgRj5jihRgfDjm-XDhw.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*R58RgRj5jihRgfDjm-XDhw.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*R58RgRj5jihRgfDjm-XDhw.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*R58RgRj5jihRgfDjm-XDhw.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*R58RgRj5jihRgfDjm-XDhw.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*R58RgRj5jihRgfDjm-XDhw.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*R58RgRj5jihRgfDjm-XDhw.png 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture>\n<\/div><\/div><\/figure>\n\n\n\n<figure class=\"wp-block-image alignnone bg mt mu c\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*R58RgRj5jihRgfDjm-XDhw.png\" alt=\"Example image of a group of friends, the the bounding box predictions of YOLO-NAS overlaid; predictions include \u201cperson,\u201d \u201ctv,\u201d \u201cbowl,\u201d \u201cdining table,\u201d \u201cbottle,\u201d and \u201cbowl.\u201d\"\/><figcaption class=\"wp-element-caption\">The detections from a pre-trained \ud83c\udfceYOLO-NAS model<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading oh oi fo be oj ok ol om on oo op oq or ni os ot ou nm ov ow ox nq oy oz pa pb bj\" id=\"6817\">\ud83c\udfcb\ud83c\udffd The Trainer<\/h3>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"ea3a\">The first thing you need to define in SuperGradients is the Trainer.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"6981\">The trainer oversees training, evaluation, saving checkpoints, etc. If you\u2019re interested in seeing the source code for the trainer, you can do so <a class=\"af og\" href=\"https:\/\/github.com\/Deci-AI\/super-gradients\/blob\/master\/src\/super_gradients\/training\/sg_trainer\/sg_trainer.py\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"b341\"><strong class=\"be qx\">\u270c\ud83c\udffc There are two important arguments for the trainer:<\/strong><\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"29c7\">1) <code class=\"cw qt qu qv qw b\">ckpt_root_dir <\/code>\u2014 this is the directory where results from all your experiments will be saved<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"679e\">2) <code class=\"cw qt qu qv qw b\">experiment_name<\/code> \u2014 all checkpoints, logs, and tensorboards will be saved in a directory with the name you specify here.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"b987\">SuperGradients supports <strong class=\"be qx\">Data Parallel<\/strong> and <strong class=\"be qx\">Distributed Data Parallel<\/strong>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"261c\">That\u2019s outside of the scope of this introduction to SuperGradients. But if you\u2019re fortunate enough to have multiple GPUs or want to learn more, you can do so <a class=\"af og\" href=\"https:\/\/github.com\/Deci-AI\/super-gradients\/blob\/0fe46cd39572db34eb83d68e343fed97b8886fe9\/documentation\/source\/device.md#3-dp---data-parallel\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"8a8d\">In the code below, you\u2019ll instantiate the trainer with just a single GPU (since that\u2019s what Google Colab provides)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"ba4f\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> super_gradients.training <span class=\"hljs-keyword\">import<\/span> Trainer\n\nCHECKPOINT_DIR = <span class=\"hljs-string\">'checkpoints'<\/span>\ntrainer = Trainer(experiment_name=<span class=\"hljs-string\">'my_first_yolonas_run'<\/span>, ckpt_root_dir=CHECKPOINT_DIR)<\/span><\/pre>\n\n\n\n<h3 class=\"wp-block-heading oh oi fo be oj ok ol om on oo op oq or ni os ot ou nm ov ow ox nq oy oz pa pb bj\" id=\"5128\">\ud83d\udcbe Datasets and DataLoaders<\/h3>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"5bc8\">SuperGradients is fully compatible with PyTorch Datasets and Dataloaders, so you can use your dataloaders as is.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"72ff\">There are several well-known datasets for object detection, for example:<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"6fc1\">\ud83d\udcbd COCO<br>\n\ud83d\udcbd Pascal<br>\n\ud83d\udcbd YOLODarkNet<br>\n\ud83d\udcbd YOLOv5<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"ac0e\">SuperGradients provides ready-to-use dataloaders for these datasets. If you\u2019re interested in learning more about working with <code class=\"cw qt qu qv qw b\">COCOFormatDetectionDataset<\/code> and the more general <code class=\"cw qt qu qv qw b\">DetectionDataset<\/code> <a class=\"af og\" href=\"https:\/\/docs.deci.ai\/super-gradients\/docstring\/training\/datasets\/#training.datasets.detection_datasets.coco_detection.COCODetectionDataset\" target=\"_blank\" rel=\"noopener ugc nofollow\">check out the SuperGradients documentation on this topic<\/a>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"f5f6\">You can learn more about working with SuperGradients datasets, dataloaders, and configuration files <a class=\"af og\" href=\"https:\/\/github.com\/Deci-AI\/super-gradients\/blob\/master\/documentation\/source\/Data.md\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"1158\">SuperGradients supports several dataset formats. You can learn more about that <a class=\"af og\" href=\"https:\/\/github.com\/Deci-AI\/super-gradients\/blob\/master\/documentation\/source\/ObjectDetection.md\" target=\"_blank\" rel=\"noopener ugc nofollow\">here.<\/a><\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"d1c4\">For this example, you\u2019ll use the <a class=\"af og\" href=\"https:\/\/universe.roboflow.com\/atathamuscoinsdataset\/u.s.-coins-dataset-a.tatham\/dataset\/5\" target=\"_blank\" rel=\"noopener ugc nofollow\">U.S. Coins Dataset<\/a> from <a class=\"af og\" href=\"https:\/\/app.roboflow.com\/login\" target=\"_blank\" rel=\"noopener ugc nofollow\">RoboFlow<\/a> with the dataset in YOLOv5 format.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"8e66\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> roboflow <span class=\"hljs-keyword\">import<\/span> Roboflow\nrf = Roboflow(api_key=<span class=\"hljs-string\">\"&lt;your-roboflow-key-here&gt;\"<\/span>)\nproject = rf.workspace(<span class=\"hljs-string\">\"atathamuscoinsdataset\"<\/span>).project(<span class=\"hljs-string\">\"u.s.-coins-dataset-a.tatham\"<\/span>)\ndataset = project.version(<span class=\"hljs-number\">5<\/span>).download(<span class=\"hljs-string\">\"yolov5\"<\/span>)<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"0be2\">Start by importing the required modules to help you create SuperGradients dataloaders.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"d431\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> super_gradients.training <span class=\"hljs-keyword\">import<\/span> dataloaders\n<span class=\"hljs-keyword\">from<\/span> super_gradients.training.dataloaders.dataloaders <span class=\"hljs-keyword\">import<\/span> coco_detection_yolo_format_train, coco_detection_yolo_format_val<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"205b\">You\u2019ll need to load your dataset parameters into a dictionary, specifically defining:<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"a626\">\u2733\ufe0f Path to the parent directory where your data lives<br>\n\ufe0f\ufe0f\u2733\ufe0f The child directory names for training, validation, and test (if you have test set) images and labels<br>\n\u2733\ufe0f Class names<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"bcbf\">You pass the values for <code class=\"cw qt qu qv qw b\">dataset_params<\/code> into the <code class=\"cw qt qu qv qw b\">dataset_params<\/code> argument, as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"3547\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\">dataset_params = {\n    <span class=\"hljs-string\">'data_dir'<\/span>:<span class=\"hljs-string\">'\/content\/U.S.-Coins-Dataset---A.Tatham-5'<\/span>,\n    <span class=\"hljs-string\">'train_images_dir'<\/span>:<span class=\"hljs-string\">'train\/images'<\/span>,\n    <span class=\"hljs-string\">'train_labels_dir'<\/span>:<span class=\"hljs-string\">'train\/labels'<\/span>,\n    <span class=\"hljs-string\">'val_images_dir'<\/span>:<span class=\"hljs-string\">'valid\/images'<\/span>,\n    <span class=\"hljs-string\">'val_labels_dir'<\/span>:<span class=\"hljs-string\">'valid\/labels'<\/span>,\n    <span class=\"hljs-string\">'test_images_dir'<\/span>:<span class=\"hljs-string\">'test\/images'<\/span>,\n    <span class=\"hljs-string\">'test_labels_dir'<\/span>:<span class=\"hljs-string\">'test\/labels'<\/span>,\n    <span class=\"hljs-string\">'classes'<\/span>: [<span class=\"hljs-string\">'Dime'<\/span>, <span class=\"hljs-string\">'Nickel'<\/span>, <span class=\"hljs-string\">'Penny'<\/span>, <span class=\"hljs-string\">'Quarter'<\/span>]<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"f12a\">You can also pass PyTorch DataLoaders arguments when instantiating your dataset. Here you\u2019ll set <code class=\"cw qt qu qv qw b\">batch_size=16<\/code> and <code class=\"cw qt qu qv qw b\">num_workers=2<\/code>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"bfb7\">Repeat this for the validation and testing datasets. Note that for training and testing data, we use <code class=\"cw qt qu qv qw b\">coco_detection_yolo_format_val<\/code> to instantiate the dataloader.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"f63c\">The dataloaders will print warnings when an annotation does not conform to the expected format. This dataset has many such annotations; thus, the warnings will be muted.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"7898\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> IPython.display <span class=\"hljs-keyword\">import<\/span> clear_output\n\ntrain_data = coco_detection_yolo_format_train(\n    dataset_params={\n        <span class=\"hljs-string\">'data_dir'<\/span>: dataset_params[<span class=\"hljs-string\">'data_dir'<\/span>],\n        <span class=\"hljs-string\">'images_dir'<\/span>: dataset_params[<span class=\"hljs-string\">'train_images_dir'<\/span>],\n        <span class=\"hljs-string\">'labels_dir'<\/span>: dataset_params[<span class=\"hljs-string\">'train_labels_dir'<\/span>],\n        <span class=\"hljs-string\">'classes'<\/span>: dataset_params[<span class=\"hljs-string\">'classes'<\/span>]\n    },\n    dataloader_params={\n        <span class=\"hljs-string\">'batch_size'<\/span>:<span class=\"hljs-number\">16<\/span>,\n        <span class=\"hljs-string\">'num_workers'<\/span>:<span class=\"hljs-number\">2<\/span>\n    }\n)\n\nval_data = coco_detection_yolo_format_val(\n    dataset_params={\n        <span class=\"hljs-string\">'data_dir'<\/span>: dataset_params[<span class=\"hljs-string\">'data_dir'<\/span>],\n        <span class=\"hljs-string\">'images_dir'<\/span>: dataset_params[<span class=\"hljs-string\">'val_images_dir'<\/span>],\n        <span class=\"hljs-string\">'labels_dir'<\/span>: dataset_params[<span class=\"hljs-string\">'val_labels_dir'<\/span>],\n        <span class=\"hljs-string\">'classes'<\/span>: dataset_params[<span class=\"hljs-string\">'classes'<\/span>]\n    },\n    dataloader_params={\n        <span class=\"hljs-string\">'batch_size'<\/span>:<span class=\"hljs-number\">16<\/span>,\n        <span class=\"hljs-string\">'num_workers'<\/span>:<span class=\"hljs-number\">2<\/span>\n    }\n)\n\ntest_data = coco_detection_yolo_format_val(\n    dataset_params={\n        <span class=\"hljs-string\">'data_dir'<\/span>: dataset_params[<span class=\"hljs-string\">'data_dir'<\/span>],\n        <span class=\"hljs-string\">'images_dir'<\/span>: dataset_params[<span class=\"hljs-string\">'test_images_dir'<\/span>],\n        <span class=\"hljs-string\">'labels_dir'<\/span>: dataset_params[<span class=\"hljs-string\">'test_labels_dir'<\/span>],\n        <span class=\"hljs-string\">'classes'<\/span>: dataset_params[<span class=\"hljs-string\">'classes'<\/span>]\n    },\n    dataloader_params={\n        <span class=\"hljs-string\">'batch_size'<\/span>:<span class=\"hljs-number\">16<\/span>,\n        <span class=\"hljs-string\">'num_workers'<\/span>:<span class=\"hljs-number\">2<\/span>\n    }\n)\n\nclear_output()<\/span><\/pre>\n\n\n\n<h3 class=\"wp-block-heading oh oi fo be oj ok ol om on oo op oq or ni os ot ou nm ov ow ox nq oy oz pa pb bj\" id=\"8434\">\ud83d\udc69\ud83c\udffd\u200d\ud83e\uddb3 Instantiating the model<\/h3>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"4e77\">You saw how to instantiate the model for inference earlier.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"15ac\">Below is how to instantiate the model for finetuning. Note you need to add the <code class=\"cw qt qu qv qw b\">num_classes<\/code> argument here.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"149f\">Note, for this tutorial, you\u2019re using <code class=\"cw qt qu qv qw b\">yolo_nas_l<\/code>, but SuperGradients has two other flavors of YOLONAS available to you: <code class=\"cw qt qu qv qw b\">yolo_nas_s<\/code> and <code class=\"cw qt qu qv qw b\">yolo_nas_m<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"afc4\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> super_gradients.training <span class=\"hljs-keyword\">import<\/span> models\nmodel = models.get(<span class=\"hljs-string\">'yolo_nas_l'<\/span>,\n                   num_classes=<span class=\"hljs-built_in\">len<\/span>(dataset_params[<span class=\"hljs-string\">'classes'<\/span>]),\n                   pretrained_weights=<span class=\"hljs-string\">\"coco\"<\/span>\n                   )<\/span><\/pre>\n\n\n\n<h3 class=\"wp-block-heading oh oi fo be oj ok ol om on oo op oq or ni os ot ou nm ov ow ox nq oy oz pa pb bj\" id=\"9e08\">\ud83c\udf9b\ufe0f Training parameters<\/h3>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"af98\">You need to define the training parameters for your training run.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"6f0d\"><a class=\"af og\" href=\"https:\/\/github.com\/Deci-AI\/super-gradients\/blob\/master\/src\/super_gradients\/recipes\/training_hyperparams\/default_train_params.yaml\" target=\"_blank\" rel=\"noopener ugc nofollow\">Full details about the training parameters can be found here.<\/a><\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"a87b\">\ud83d\udea8 There are a few <strong class=\"be qx\">mandatory<\/strong> arguments that you must define for training params \ud83d\udea8<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"8691\">\u2733\ufe0f <code class=\"cw qt qu qv qw b\">max_epochs<\/code> \u2014 Max number of training epochs<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"b173\">\u2733\ufe0f\ufe0f\ufe0f <code class=\"cw qt qu qv qw b\">loss<\/code>\u2014 the loss function you want to use<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"00ab\">\u2733\ufe0f <code class=\"cw qt qu qv qw b\">optimizer<\/code>\u2014 Optimizer you will be using<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"75db\">\u2733\ufe0f <code class=\"cw qt qu qv qw b\">train_metrics_list <\/code>\u2014 Metrics to log during training<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"23fc\">\u2733\ufe0f <code class=\"cw qt qu qv qw b\">valid_metrics_list <\/code>\u2014 Metrics to log during training<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"cfd4\">\u2733\ufe0f <code class=\"cw qt qu qv qw b\">metric_to_watch<\/code> \u2014 metric which the model checkpoint will be saved according to<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"df29\">You can choose from various <code class=\"cw qt qu qv qw b\">optimizer<\/code>s such as Adam, AdamW, SGD, Lion, or RMSProps. If you change the default parameters of these optimizers, you pass them into <code class=\"cw qt qu qv qw b\">optimizer_params<\/code>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"3783\"><strong class=\"be qx\">\ud83d\udd15 Note: I\u2019ve enabled <\/strong><code class=\"cw qt qu qv qw b\"><strong class=\"be qx\">silent_mode<\/strong><\/code><strong class=\"be qx\">, so the notebook doesn\u2019t get longer than it already is. You should disable it so you can see what SuperGradients outputs during training.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"29a3\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">from<\/span> super_gradients.training.losses <span class=\"hljs-keyword\">import<\/span> PPYoloELoss\n<span class=\"hljs-keyword\">from<\/span> super_gradients.training.metrics <span class=\"hljs-keyword\">import<\/span> DetectionMetrics_050\n<span class=\"hljs-keyword\">from<\/span> super_gradients.training.models.detection_models.pp_yolo_e <span class=\"hljs-keyword\">import<\/span> PPYoloEPostPredictionCallback\n\ntrain_params = {\n    <span class=\"hljs-comment\"># ENABLING SILENT MODE<\/span>\n    <span class=\"hljs-string\">'silent_mode'<\/span>: <span class=\"hljs-literal\">True<\/span>,\n    <span class=\"hljs-string\">\"average_best_models\"<\/span>:<span class=\"hljs-literal\">True<\/span>,\n    <span class=\"hljs-string\">\"warmup_mode\"<\/span>: <span class=\"hljs-string\">\"linear_epoch_step\"<\/span>,\n    <span class=\"hljs-string\">\"warmup_initial_lr\"<\/span>: <span class=\"hljs-number\">1e-6<\/span>,\n    <span class=\"hljs-string\">\"lr_warmup_epochs\"<\/span>: <span class=\"hljs-number\">3<\/span>,\n    <span class=\"hljs-string\">\"initial_lr\"<\/span>: <span class=\"hljs-number\">5e-4<\/span>,\n    <span class=\"hljs-string\">\"lr_mode\"<\/span>: <span class=\"hljs-string\">\"cosine\"<\/span>,\n    <span class=\"hljs-string\">\"cosine_final_lr_ratio\"<\/span>: <span class=\"hljs-number\">0.1<\/span>,\n    <span class=\"hljs-string\">\"optimizer\"<\/span>: <span class=\"hljs-string\">\"Adam\"<\/span>,\n    <span class=\"hljs-string\">\"optimizer_params\"<\/span>: {<span class=\"hljs-string\">\"weight_decay\"<\/span>: <span class=\"hljs-number\">0.0001<\/span>},\n    <span class=\"hljs-string\">\"zero_weight_decay_on_bias_and_bn\"<\/span>: <span class=\"hljs-literal\">True<\/span>,\n    <span class=\"hljs-string\">\"ema\"<\/span>: <span class=\"hljs-literal\">True<\/span>,\n    <span class=\"hljs-string\">\"ema_params\"<\/span>: {<span class=\"hljs-string\">\"decay\"<\/span>: <span class=\"hljs-number\">0.9<\/span>, <span class=\"hljs-string\">\"decay_type\"<\/span>: <span class=\"hljs-string\">\"threshold\"<\/span>},\n    <span class=\"hljs-comment\"># ONLY TRAINING FOR 10 EPOCHS FOR THIS EXAMPLE NOTEBOOK<\/span>\n    <span class=\"hljs-string\">\"max_epochs\"<\/span>: <span class=\"hljs-number\">10<\/span>,\n    <span class=\"hljs-string\">\"mixed_precision\"<\/span>: <span class=\"hljs-literal\">True<\/span>,\n    <span class=\"hljs-string\">\"loss\"<\/span>: PPYoloELoss(\n        use_static_assigner=<span class=\"hljs-literal\">False<\/span>,\n        <span class=\"hljs-comment\"># <span class=\"hljs-doctag\">NOTE:<\/span> num_classes needs to be defined here<\/span>\n        num_classes=<span class=\"hljs-built_in\">len<\/span>(dataset_params[<span class=\"hljs-string\">'classes'<\/span>]),\n        reg_max=<span class=\"hljs-number\">16<\/span>\n    ),\n    <span class=\"hljs-string\">\"valid_metrics_list\"<\/span>: [\n        DetectionMetrics_050(\n            score_thres=<span class=\"hljs-number\">0.1<\/span>,\n            top_k_predictions=<span class=\"hljs-number\">300<\/span>,\n            <span class=\"hljs-comment\"># <span class=\"hljs-doctag\">NOTE:<\/span> num_classes needs to be defined here<\/span>\n            num_cls=<span class=\"hljs-built_in\">len<\/span>(dataset_params[<span class=\"hljs-string\">'classes'<\/span>]),\n            normalize_targets=<span class=\"hljs-literal\">True<\/span>,\n            post_prediction_callback=PPYoloEPostPredictionCallback(\n                score_threshold=<span class=\"hljs-number\">0.01<\/span>,\n                nms_top_k=<span class=\"hljs-number\">1000<\/span>,\n                max_predictions=<span class=\"hljs-number\">300<\/span>,\n                nms_threshold=<span class=\"hljs-number\">0.7<\/span>\n            )\n        )\n    ],\n    <span class=\"hljs-string\">\"metric_to_watch\"<\/span>: <span class=\"hljs-string\">'mAP@0.50'<\/span>\n}<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"27bf\"><strong class=\"be qx\">\ud83e\ude84 SuperGradients offers several training tricks right out of the box, such as:<\/strong><\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"3d60\">\u2733\ufe0f Exponential moving average<br>\n\u2733\ufe0f Zero-weight decay on bias and batch normalization<br>\n\u2733\ufe0f Weight averaging<br>\n\u2733\ufe0f Batch accumulation<br>\n\u2733\ufe0f Precise BatchNorm<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"3903\">You can read more details about these training tricks <a class=\"af og\" href=\"https:\/\/heartbeat.comet.ml\/a-better-way-to-train-your-neural-networks-813b60a5bd6a\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"08ef\">If you want to build a custom metric with SuperGradients, you can learn how <a class=\"af og\" href=\"https:\/\/github.com\/Deci-AI\/super-gradients\/blob\/master\/documentation\/source\/Metrics.md\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"e28e\">Note that you must set the number of classes in two places below: <code class=\"cw qt qu qv qw b\">PPYoloELoss<\/code> and <code class=\"cw qt qu qv qw b\">DetectionMetrics_050<\/code>.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"9064\">You may notice that we use a post-prediction callback. For details on how phase callbacks work in SuperGradients <a class=\"af og\" href=\"https:\/\/github.com\/Deci-AI\/super-gradients\/blob\/master\/documentation\/source\/PhaseCallbacks.md\" target=\"_blank\" rel=\"noopener ugc nofollow\">check out our documentation<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading oh oi fo be oj ok ol om on oo op oq or ni os ot ou nm ov ow ox nq oy oz pa pb bj\" id=\"998d\">\ud83e\uddbe Training the model<\/h3>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"d70d\">You\u2019ve covered a lot of ground so far:<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"46c8\">\u2705 Instantiated the trainer<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"09f1\">\u2705 Defined your dataset parameters and dataloaders<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"cffb\">\u2705 Instantiated a model<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"7605\">\u2705 Set up your training parameters<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"3bb2\"><strong class=\"be qx\">\u23f3 Now, its time to train a model<\/strong><\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"8615\">Training a model using SuperGradients is done using the <code class=\"cw qt qu qv qw b\">trainer.<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"83bb\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\">trainer.train(model=model,\n              training_params=train_params,\n              train_loader=train_data,\n              valid_loader=val_data)<\/span><\/pre>\n\n\n\n<h3 class=\"wp-block-heading oh oi fo be oj ok ol om on oo op oq or ni os ot ou nm ov ow ox nq oy oz pa pb bj\" id=\"83e0\">\ud83c\udfc6 Get the best trained model<\/h3>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"a0a5\">Now that training is complete, you must get the best trained model.<\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"4e43\">You used checkpoint averaging, so the following code will use weights averaged across training runs.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"574e\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\">best_model = models.get(<span class=\"hljs-string\">'yolo_nas_l'<\/span>,\n                        num_classes=<span class=\"hljs-built_in\">len<\/span>(dataset_params[<span class=\"hljs-string\">'classes'<\/span>]),\n                        checkpoint_path=<span class=\"hljs-string\">\"checkpoints\/my_first_yolonas_run\/average_model.pth\"<\/span>)<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"f3c8\"><strong class=\"be qx\">If you want to use the best weights or weights from the last epoch, you\u2019d use one of the following in the code below:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"62b1\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\">best_weights = models.get(<span class=\"hljs-string\">'yolo_nas_l'<\/span>,\n                        num_classes=<span class=\"hljs-built_in\">len<\/span>(dataset_params[<span class=\"hljs-string\">'classes'<\/span>]),\n                        checkpoint_path=<span class=\"hljs-string\">\"checkpoints\/my_first_yolonas_run\/average_model.pth\"<\/span>)\n\nlast_weights = models.get(<span class=\"hljs-string\">'yolo_nas_l'<\/span>,\n                        num_classes=<span class=\"hljs-built_in\">len<\/span>(dataset_params[<span class=\"hljs-string\">'classes'<\/span>]),\n                        checkpoint_path=<span class=\"hljs-string\">\"checkpoints\/my_first_yolonas_run\/ckpt_latest.pth\"<\/span>)<\/span><\/pre>\n\n\n\n<h3 class=\"wp-block-heading oh oi fo be oj ok ol om on oo op oq or ni os ot ou nm ov ow ox nq oy oz pa pb bj\" id=\"502f\">\ud83e\uddd0 Evaluating the best trained model on the test set<\/h3>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"350b\">Once you have a trained model, you can evaluate its performance on unseen data like below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"0354\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\">trainer.test(model=best_model,\n            test_loader=test_data,\n            test_metrics_list=DetectionMetrics_050(score_thres=<span class=\"hljs-number\">0.1<\/span>,\n                                                   top_k_predictions=<span class=\"hljs-number\">300<\/span>,\n                                                   num_cls=<span class=\"hljs-built_in\">len<\/span>(dataset_params[<span class=\"hljs-string\">'classes'<\/span>]),\n                                                   normalize_targets=<span class=\"hljs-literal\">True<\/span>,\n                                                   post_prediction_callback=PPYoloEPostPredictionCallback(score_threshold=<span class=\"hljs-number\">0.01<\/span>,\n                                                                                                          nms_top_k=<span class=\"hljs-number\">1000<\/span>,\n                                                                                                          max_predictions=<span class=\"hljs-number\">300<\/span>,\n                                                                                                          nms_threshold=<span class=\"hljs-number\">0.7<\/span>)\n                                                  ))<\/span><\/pre>\n\n\n\n<h3 class=\"wp-block-heading oh oi fo be oj ok ol om on oo op oq or ni os ot ou nm ov ow ox nq oy oz pa pb bj\" id=\"26f1\">\ud83d\udd2e Predicting the best model<\/h3>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"bd5a\">The next line will perform detection on the following image.<\/p>\n\n\n\n<figure class=\"wp-block-image mj mk ml mm mn mo mg mh paragraph-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:500\/1*RaVJ0tLwyA9O4l8hlLlLcg.jpeg\" alt=\"A labeled image of the heads\u2019 side of an American penny, nickel, dime, quarter, half dollar, and the American flag.\"\/><\/figure>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"a931\">Note, we didn\u2019t have a class for the half-dollar coin. So it will likely get classified as something else.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><span id=\"1189\" class=\"rb oi fo qw b bf rc rd l re rf\" data-selectable-paragraph=\"\">img_url = <span class=\"hljs-string\">'https:\/\/www.mynumi.net\/media\/catalog\/product\/cache\/2\/image\/9df78eab33525d08d6e5fb8d27136e95\/s\/e\/serietta_usa_2_1\/www.mynumi.net-USASE5AD160-31.jpg'<\/span>\nbest_model.predict(img_url).show()<\/span><\/pre>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"97b5\">The results aren\u2019t too bad after just a few epochs!<\/p>\n\n\n\n<figure class=\"mj mk ml mm mn mo mg mh paragraph-image\">\n<div class=\"mp mq eb mr bg ms\" tabindex=\"0\" role=\"button\">\n<div class=\"mg mh rj\">\n<picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*A8J2njf5_Q0vGQtVenYjpQ.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*A8J2njf5_Q0vGQtVenYjpQ.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*A8J2njf5_Q0vGQtVenYjpQ.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*A8J2njf5_Q0vGQtVenYjpQ.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*A8J2njf5_Q0vGQtVenYjpQ.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*A8J2njf5_Q0vGQtVenYjpQ.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*A8J2njf5_Q0vGQtVenYjpQ.png 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*A8J2njf5_Q0vGQtVenYjpQ.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*A8J2njf5_Q0vGQtVenYjpQ.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*A8J2njf5_Q0vGQtVenYjpQ.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*A8J2njf5_Q0vGQtVenYjpQ.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*A8J2njf5_Q0vGQtVenYjpQ.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*A8J2njf5_Q0vGQtVenYjpQ.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*A8J2njf5_Q0vGQtVenYjpQ.png 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture>\n<\/div><\/div><\/figure>\n\n\n\n<figure class=\"wp-block-image alignnone bg mt mu c\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*A8J2njf5_Q0vGQtVenYjpQ.png\" alt=\"YOLO-NAS\u2019s prediction bounding boxes on the heads\u2019 and tails\u2019 sides of an American penny, nickel, dime, quarter, and half dollar.\"\/><figcaption class=\"wp-element-caption\">\ud83c\udfce\ufe0fYOLO-NAS detections after training<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading ph oi fo be oj pi pj go on pk pl gr or pm pn po pp pq pr ps pt pu pv pw px py bj\" id=\"eca6\">References<\/h2>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm pc nd ne gp pd ng nh ni pe nk nl nm pf no np nq pg ns nt nu fh bj\" id=\"7668\">\u21aa\ufe0f<a class=\"af og\" href=\"https:\/\/deci.ai\/blog\/YOLO-NAS-object-detection-foundation-model\/\" target=\"_blank\" rel=\"noopener ugc nofollow\"> \ud83c\udfce\ufe0fYOLO-NAS Technical Blog<\/a><\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"e281\">\u21aa\ufe0f \ud83c\udfce\ufe0f<a class=\"af og\" href=\"https:\/\/bit.ly\/yolo-nas-starter-notebook\" target=\"_blank\" rel=\"noopener ugc nofollow\">YOLO-NAS Starter Notebook<\/a><\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"c258\">\u21aa\ufe0f\ufe0f \ud83c\udfce\ufe0f<a class=\"af og\" href=\"https:\/\/colab.research.google.com\/drive\/10N6NmSMCiRnFlKV9kaIS_z3pk0OI1xKC#scrollTo=wFrDFfstc_6V\" target=\"_blank\" rel=\"noopener ugc nofollow\">YOLO-NAS Project Template<\/a><\/p>\n\n\n\n<p class=\"pw-post-body-paragraph na nb fo be b gm nc nd ne gp nf ng nh ni nj nk nl nm nn no np nq nr ns nt nu fh bj\" id=\"1aed\">\u21aa\ufe0f <a class=\"af og\" href=\"https:\/\/bit.ly\/yolo-nas-launch\" target=\"_blank\" rel=\"noopener ugc nofollow\">\ud83c\udfce\ufe0fYOLO-NAS ReadMe on GitHub<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>YOLO models are famous for two main reasons: The first version of YOLO was introduced in 2016 and changed how object detection was performed by treating object detection as a single regression problem. It divided images into a grid and simultaneously predicted bounding boxes and class probabilities. Though it was faster than previous object detection [&hellip;]<\/p>\n","protected":false},"author":68,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"customer_name":"","customer_description":"","customer_industry":"","customer_technologies":"","customer_logo":"","footnotes":""},"categories":[6],"tags":[],"coauthors":[166],"class_list":["post-7057","post","type-post","status-publish","format-standard","hentry","category-machine-learning"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Introducing YOLO-NAS: A New State-of-the-Art for Object Detection - Comet<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introducing YOLO-NAS: A New State-of-the-Art for Object Detection\" \/>\n<meta property=\"og:description\" content=\"YOLO models are famous for two main reasons: The first version of YOLO was introduced in 2016 and changed how object detection was performed by treating object detection as a single regression problem. It divided images into a grid and simultaneously predicted bounding boxes and class probabilities. Though it was faster than previous object detection [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/\" \/>\n<meta property=\"og:site_name\" content=\"Comet\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cometdotml\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-08T19:49:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-24T17:14:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*mR__xCOs_j8c5A0hMq3B5Q.gif\" \/>\n<meta name=\"author\" content=\"Harpreet Sahota\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Cometml\" \/>\n<meta name=\"twitter:site\" content=\"@Cometml\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Harpreet Sahota\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Introducing YOLO-NAS: A New State-of-the-Art for Object Detection - Comet","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/","og_locale":"en_US","og_type":"article","og_title":"Introducing YOLO-NAS: A New State-of-the-Art for Object Detection","og_description":"YOLO models are famous for two main reasons: The first version of YOLO was introduced in 2016 and changed how object detection was performed by treating object detection as a single regression problem. It divided images into a grid and simultaneously predicted bounding boxes and class probabilities. Though it was faster than previous object detection [&hellip;]","og_url":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/","og_site_name":"Comet","article_publisher":"https:\/\/www.facebook.com\/cometdotml","article_published_time":"2023-08-08T19:49:36+00:00","article_modified_time":"2025-04-24T17:14:55+00:00","og_image":[{"url":"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*mR__xCOs_j8c5A0hMq3B5Q.gif","type":"","width":"","height":""}],"author":"Harpreet Sahota","twitter_card":"summary_large_image","twitter_creator":"@Cometml","twitter_site":"@Cometml","twitter_misc":{"Written by":"Harpreet Sahota","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/#article","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/"},"author":{"name":"Harpreet Sahota","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/46036ab474aa916e2873daece26a28d6"},"headline":"Introducing YOLO-NAS: A New State-of-the-Art for Object Detection","datePublished":"2023-08-08T19:49:36+00:00","dateModified":"2025-04-24T17:14:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/"},"wordCount":1682,"publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*mR__xCOs_j8c5A0hMq3B5Q.gif","articleSection":["Machine Learning"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/","url":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/","name":"Introducing YOLO-NAS: A New State-of-the-Art for Object Detection - Comet","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/#primaryimage"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*mR__xCOs_j8c5A0hMq3B5Q.gif","datePublished":"2023-08-08T19:49:36+00:00","dateModified":"2025-04-24T17:14:55+00:00","breadcrumb":{"@id":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/#primaryimage","url":"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*mR__xCOs_j8c5A0hMq3B5Q.gif","contentUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*mR__xCOs_j8c5A0hMq3B5Q.gif"},{"@type":"BreadcrumbList","@id":"https:\/\/www.comet.com\/site\/blog\/introducing-yolo-nas-a-new-state-of-the-art-for-object-detection\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.comet.com\/site\/"},{"@type":"ListItem","position":2,"name":"Introducing YOLO-NAS: A New State-of-the-Art for Object Detection"}]},{"@type":"WebSite","@id":"https:\/\/www.comet.com\/site\/#website","url":"https:\/\/www.comet.com\/site\/","name":"Comet","description":"Build Better Models Faster","publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.comet.com\/site\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.comet.com\/site\/#organization","name":"Comet ML, Inc.","alternateName":"Comet","url":"https:\/\/www.comet.com\/site\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","width":310,"height":310,"caption":"Comet ML, Inc."},"image":{"@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cometdotml","https:\/\/x.com\/Cometml","https:\/\/www.youtube.com\/channel\/UCmN63HKvfXSCS-UwVwmK8Hw"]},{"@type":"Person","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/46036ab474aa916e2873daece26a28d6","name":"Harpreet Sahota","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/image\/2d21512be19ba7e19a71a803309e2a88","url":"https:\/\/secure.gravatar.com\/avatar\/a6ca5a533fc9f143a0a7428037ff652aa0633d66bf27e76ae89b955ae72a0f2d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a6ca5a533fc9f143a0a7428037ff652aa0633d66bf27e76ae89b955ae72a0f2d?s=96&d=mm&r=g","caption":"Harpreet Sahota"},"url":"https:\/\/www.comet.com\/site\/blog\/author\/theartistsofdatasciencegmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/7057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/comments?post=7057"}],"version-history":[{"count":1,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/7057\/revisions"}],"predecessor-version":[{"id":15588,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/7057\/revisions\/15588"}],"wp:attachment":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/media?parent=7057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/categories?post=7057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/tags?post=7057"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/coauthors?post=7057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}