import{s as xl,o as Wl,n as vl}from"../chunks/scheduler.25b97de1.js";import{S as Vl,i as Rl,g as p,s as e,r as o,A as Ql,h as d,f as a,c as n,j as Zl,u as i,x as c,k as Ks,y as kl,a as l,v as M,d as m,t as r,w as h}from"../chunks/index.d9030fc9.js";import{T as Yl}from"../chunks/Tip.baa67368.js";import{C as j}from"../chunks/CodeBlock.e6cd0d95.js";import{D as Al}from"../chunks/DocNotebookDropdown.5ea6cb78.js";import{H as Ls,E as Nl}from"../chunks/EditOnGithub.91d95064.js";function Xl(st){let y,w='To see all architectures and checkpoints compatible with this task, we recommend checking the <a href="https://huggingface.co/tasks/object-detection" rel="nofollow">task-page</a>';return{c(){y=p("p"),y.innerHTML=w},l(J){y=d(J,"P",{"data-svelte-h":!0}),c(y)!=="svelte-5wyiet"&&(y.innerHTML=w)},m(J,Ps){l(J,y,Ps)},p:vl,d(J){J&&a(y)}}}function El(st){let y,w,J,Ps,g,tt,I,at,C,xa=`Object detection is the computer vision task of detecting instances (such as humans, buildings, or cars) in an image. Object detection models receive an image as input and output
coordinates of the bounding boxes and associated labels of the detected objects. An image can contain multiple objects,
each with its own bounding box and a label (e.g. it can have a car and a building), and each object can
be present in different parts of an image (e.g. the image can have several cars).
This task is commonly used in autonomous driving for detecting things like pedestrians, road signs, and traffic lights.
Other applications include counting objects in images, image search, and more.`,lt,f,Wa="In this guide, you will learn how to:",et,B,va=`<li>Finetune <a href="https://huggingface.co/docs/transformers/model_doc/detr" rel="nofollow">DETR</a>, a model that combines a convolutional
backbone with an encoder-decoder Transformer, on the <a href="https://huggingface.co/datasets/cppe-5" rel="nofollow">CPPE-5</a>
dataset.</li> <li>Use your finetuned model for inference.</li>`,nt,T,pt,_,Va="Before you begin, make sure you have all the necessary libraries installed:",dt,G,ct,Z,Ra=`You’ll use 🤗 Datasets to load a dataset from the Hugging Face Hub, 🤗 Transformers to train your model,
and <code>albumentations</code> to augment the data.`,ot,x,Qa=`We encourage you to share your model with the community. Log in to your Hugging Face account to upload it to the Hub.
When prompted, enter your token to log in:`,it,W,Mt,v,ka="To get started, we’ll define global constants, namely the model name and image size. For this tutorial, we’ll use the conditional DETR model due to its faster convergence. Feel free to select any object detection model available in the <code>transformers</code> library.",mt,V,rt,R,ht,Q,Ya=`The <a href="https://huggingface.co/datasets/cppe-5" rel="nofollow">CPPE-5 dataset</a> contains images with
annotations identifying medical personal protective equipment (PPE) in the context of the COVID-19 pandemic.`,jt,k,Aa="Start by loading the dataset and creating a <code>validation</code> split from <code>train</code>:",yt,Y,Jt,A,Na="You’ll see that this dataset has 1000 images for train and validation sets and a test set with 29 images.",bt,N,Xa="To get familiar with the data, explore what the examples look like.",Tt,X,ut,E,Ea="The examples in the dataset have the following fields:",Ut,z,za='<li><code>image_id</code>: the example image id</li> <li><code>image</code>: a <code>PIL.Image.Image</code> object containing the image</li> <li><code>width</code>: width of the image</li> <li><code>height</code>: height of the image</li> <li><code>objects</code>: a dictionary containing bounding box metadata for the objects in the image:<ul><li><code>id</code>: the annotation id</li> <li><code>area</code>: the area of the bounding box</li> <li><code>bbox</code>: the object’s bounding box (in the <a href="https://albumentations.ai/docs/getting_started/bounding_boxes_augmentation/#coco" rel="nofollow">COCO format</a> )</li> <li><code>category</code>: the object’s category, with possible values including <code>Coverall (0)</code>, <code>Face_Shield (1)</code>, <code>Gloves (2)</code>, <code>Goggles (3)</code> and <code>Mask (4)</code></li></ul></li>',wt,H,Ha=`You may notice that the <code>bbox</code> field follows the COCO format, which is the format that the DETR model expects.
However, the grouping of the fields inside <code>objects</code> differs from the annotation format DETR requires. You will
need to apply some preprocessing transformations before using this data for training.`,gt,F,Fa="To get an even better understanding of the data, visualize an example in the dataset.",It,S,Ct,u,Sa='<img src="https://i.imgur.com/oVQb9SF.png" alt="CPPE-5 Image Example"/>',ft,$,$a=`To visualize the bounding boxes with associated labels, you can get the labels from the dataset’s metadata, specifically
the <code>category</code> field.
You’ll also want to create dictionaries that map a label id to a label class (<code>id2label</code>) and the other way around (<code>label2id</code>).
You can use them later when setting up the model. Including these maps will make your model reusable by others if you share
it on the Hugging Face Hub. Please note that, the part of above code that draws the bounding boxes assume that it is in <code>COCO</code> format <code>(x_min, y_min, width, height)</code>. It has to be adjusted to work for other formats like <code>(x_min, y_min, x_max, y_max)</code>.`,Bt,q,qa=`As a final step of getting familiar with the data, explore it for potential issues. One common problem with datasets for
object detection is bounding boxes that “stretch” beyond the edge of the image. Such “runaway” bounding boxes can raise
errors during training and should be addressed. There are a few examples with this issue in this dataset.
To keep things simple in this guide, we will set <code>clip=True</code> for <code>BboxParams</code> in transformations below.`,_t,D,Gt,L,Da=`To finetune a model, you must preprocess the data you plan to use to match precisely the approach used for the pre-trained model.
<a href="/docs/transformers/pr_31172/en/model_doc/auto#transformers.AutoImageProcessor">AutoImageProcessor</a> takes care of processing image data to create <code>pixel_values</code>, <code>pixel_mask</code>, and
<code>labels</code> that a DETR model can train with. The image processor has some attributes that you won’t have to worry about:`,Zt,P,La="<li><code>image_mean = [0.485, 0.456, 0.406 ]</code></li> <li><code>image_std = [0.229, 0.224, 0.225]</code></li>",xt,K,Pa=`These are the mean and standard deviation used to normalize images during the model pre-training. These values are crucial
to replicate when doing inference or finetuning a pre-trained image model.`,Wt,O,Ka="Instantiate the image processor from the same checkpoint as the model you want to finetune.",vt,ss,Vt,ts,Oa="Before passing the images to the <code>image_processor</code>, apply two preprocessing transformations to the dataset:",Rt,as,sl="<li>Augmenting images</li> <li>Reformatting annotations to meet DETR expectations</li>",Qt,ls,tl=`First, to make sure the model does not overfit on the training data, you can apply image augmentation with any data augmentation library. Here we use <a href="https://albumentations.ai/docs/" rel="nofollow">Albumentations</a>.
This library ensures that transformations affect the image and update the bounding boxes accordingly.
The 🤗 Datasets library documentation has a detailed <a href="https://huggingface.co/docs/datasets/object_detection" rel="nofollow">guide on how to augment images for object detection</a>,
and it uses the exact same dataset as an example. Apply some geometric and color transformations to the image. For additional augmentation options, explore the <a href="https://huggingface.co/spaces/qubvel-hf/albumentations-demo" rel="nofollow">Albumentations Demo Space</a>.`,kt,es,Yt,ns,al=`The <code>image_processor</code> expects the annotations to be in the following format: <code>{&#39;image_id&#39;: int, &#39;annotations&#39;: List[Dict]}</code>,
where each dictionary is a COCO object annotation. Let’s add a function to reformat annotations for a single example:`,At,ps,Nt,ds,ll="Now you can combine the image and annotation transformations to use on a batch of examples:",Xt,cs,Et,os,el=`Apply this preprocessing function to the entire dataset using 🤗 Datasets <a href="https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.with_transform" rel="nofollow">with_transform</a> method. This method applies
transformations on the fly when you load an element of the dataset.`,zt,is,nl=`At this point, you can check what an example from the dataset looks like after the transformations. You should see a tensor
with <code>pixel_values</code>, a tensor with <code>pixel_mask</code>, and <code>labels</code>.`,Ht,Ms,Ft,ms,pl=`You have successfully augmented the individual images and prepared their annotations. However, preprocessing isn’t
complete yet. In the final step, create a custom <code>collate_fn</code> to batch images together.
Pad images (which are now <code>pixel_values</code>) to the largest image in a batch, and create a corresponding <code>pixel_mask</code>
to indicate which pixels are real (1) and which are padding (0).`,St,rs,$t,hs,qt,js,dl='Object detection models are commonly evaluated with a set of <a href="https://cocodataset.org/#detection-eval">COCO-style metrics</a>. We are going to use <code>torchmetrics</code> to compute <code>mAP</code> (mean average precision) and <code>mAR</code> (mean average recall) metrics and will wrap it to <code>compute_metrics</code> function in order to use in <a href="/docs/transformers/pr_31172/en/main_classes/trainer#transformers.Trainer">Trainer</a> for evaluation.',Dt,ys,cl="Intermediate format of boxes used for training is <code>YOLO</code> (normalized) but we will compute metrics for boxes in <code>Pascal VOC</code> (absolute) format in order to correctly handle box areas. Let’s define a function that converts bounding boxes to <code>Pascal VOC</code> format:",Lt,Js,Pt,bs,ol="Then, in <code>compute_metrics</code> function we collect <code>predicted</code> and <code>target</code> bounding boxes, scores and labels from evaluation loop results and pass it to the scoring function.",Kt,Ts,Ot,us,sa,Us,il=`You have done most of the heavy lifting in the previous sections, so now you are ready to train your model!
The images in this dataset are still quite large, even after resizing. This means that finetuning this model will
require at least one GPU.`,ta,ws,Ml="Training involves the following steps:",aa,gs,ml='<li>Load the model with <a href="/docs/transformers/pr_31172/en/model_doc/auto#transformers.AutoModelForObjectDetection">AutoModelForObjectDetection</a> using the same checkpoint as in the preprocessing.</li> <li>Define your training hyperparameters in <a href="/docs/transformers/pr_31172/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a>.</li> <li>Pass the training arguments to <a href="/docs/transformers/pr_31172/en/main_classes/trainer#transformers.Trainer">Trainer</a> along with the model, dataset, image processor, and data collator.</li> <li>Call <a href="/docs/transformers/pr_31172/en/main_classes/trainer#transformers.Trainer.train">train()</a> to finetune your model.</li>',la,Is,rl=`When loading the model from the same checkpoint that you used for the preprocessing, remember to pass the <code>label2id</code>
and <code>id2label</code> maps that you created earlier from the dataset’s metadata. Additionally, we specify <code>ignore_mismatched_sizes=True</code> to replace the existing classification head with a new one.`,ea,Cs,na,fs,hl='In the <a href="/docs/transformers/pr_31172/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> use <code>output_dir</code> to specify where to save your model, then configure hyperparameters as you see fit. For <code>num_train_epochs=30</code> training will take about 35 minutes in Google Colab T4 GPU, increase the number of epoch to get better results.',pa,Bs,jl="Important notes:",da,_s,yl=`<li>Do not remove unused columns because this will drop the image column. Without the image column, you
can’t create <code>pixel_values</code>. For this reason, set <code>remove_unused_columns</code> to <code>False</code>.</li> <li>Set <code>eval_do_concat_batches=False</code> to get proper evaluation results. Images have different number of target boxes, if batches are concatenated we will not be able to determine which boxes belongs to particular image.</li>`,ca,Gs,Jl=`If you wish to share your model by pushing to the Hub, set <code>push_to_hub</code> to <code>True</code> (you must be signed in to Hugging
Face to upload your model).`,oa,Zs,ia,xs,bl='Finally, bring everything together, and call <a href="/docs/transformers/pr_31172/en/main_classes/trainer#transformers.Trainer.train">train()</a>:',Ma,Ws,ma,vs,Tl=`<progress value="3210" max="3210" style="width:300px; height:20px; vertical-align: middle;"></progress>
  [3210/3210 26:07, Epoch 30/30]`,ra,b,ul='<thead><tr style="text-align: left;"><th>Epoch</th> <th>Training Loss</th> <th>Validation Loss</th> <th>Map</th> <th>Map 50</th> <th>Map 75</th> <th>Map Small</th> <th>Map Medium</th> <th>Map Large</th> <th>Mar 1</th> <th>Mar 10</th> <th>Mar 100</th> <th>Mar Small</th> <th>Mar Medium</th> <th>Mar Large</th> <th>Map Coverall</th> <th>Mar 100 Coverall</th> <th>Map Face Shield</th> <th>Mar 100 Face Shield</th> <th>Map Gloves</th> <th>Mar 100 Gloves</th> <th>Map Goggles</th> <th>Mar 100 Goggles</th> <th>Map Mask</th> <th>Mar 100 Mask</th></tr></thead> <tbody><tr><td>1</td> <td>No log</td> <td>2.629903</td> <td>0.008900</td> <td>0.023200</td> <td>0.006500</td> <td>0.001300</td> <td>0.002800</td> <td>0.020500</td> <td>0.021500</td> <td>0.070400</td> <td>0.101400</td> <td>0.007600</td> <td>0.106200</td> <td>0.096100</td> <td>0.036700</td> <td>0.232000</td> <td>0.000300</td> <td>0.019000</td> <td>0.003900</td> <td>0.125400</td> <td>0.000100</td> <td>0.003100</td> <td>0.003500</td> <td>0.127600</td></tr> <tr><td>2</td> <td>No log</td> <td>3.479864</td> <td>0.014800</td> <td>0.034600</td> <td>0.010800</td> <td>0.008600</td> <td>0.011700</td> <td>0.012500</td> <td>0.041100</td> <td>0.098700</td> <td>0.130000</td> <td>0.056000</td> <td>0.062200</td> <td>0.111900</td> <td>0.053500</td> <td>0.447300</td> <td>0.010600</td> <td>0.100000</td> <td>0.000200</td> <td>0.022800</td> <td>0.000100</td> <td>0.015400</td> <td>0.009700</td> <td>0.064400</td></tr> <tr><td>3</td> <td>No log</td> <td>2.107622</td> <td>0.041700</td> <td>0.094000</td> <td>0.034300</td> <td>0.024100</td> <td>0.026400</td> <td>0.047400</td> <td>0.091500</td> <td>0.182800</td> <td>0.225800</td> <td>0.087200</td> <td>0.199400</td> <td>0.210600</td> <td>0.150900</td> <td>0.571200</td> <td>0.017300</td> <td>0.101300</td> <td>0.007300</td> <td>0.180400</td> <td>0.002100</td> <td>0.026200</td> <td>0.031000</td> <td>0.250200</td></tr> <tr><td>4</td> <td>No log</td> <td>2.031242</td> <td>0.055900</td> <td>0.120600</td> <td>0.046900</td> <td>0.013800</td> <td>0.038100</td> <td>0.090300</td> <td>0.105900</td> <td>0.225600</td> <td>0.266100</td> <td>0.130200</td> <td>0.228100</td> <td>0.330000</td> <td>0.191000</td> <td>0.572100</td> <td>0.010600</td> <td>0.157000</td> <td>0.014600</td> <td>0.235300</td> <td>0.001700</td> <td>0.052300</td> <td>0.061800</td> <td>0.313800</td></tr> <tr><td>5</td> <td>3.889400</td> <td>1.883433</td> <td>0.089700</td> <td>0.201800</td> <td>0.067300</td> <td>0.022800</td> <td>0.065300</td> <td>0.129500</td> <td>0.136000</td> <td>0.272200</td> <td>0.303700</td> <td>0.112900</td> <td>0.312500</td> <td>0.424600</td> <td>0.300200</td> <td>0.585100</td> <td>0.032700</td> <td>0.202500</td> <td>0.031300</td> <td>0.271000</td> <td>0.008700</td> <td>0.126200</td> <td>0.075500</td> <td>0.333800</td></tr> <tr><td>6</td> <td>3.889400</td> <td>1.807503</td> <td>0.118500</td> <td>0.270900</td> <td>0.090200</td> <td>0.034900</td> <td>0.076700</td> <td>0.152500</td> <td>0.146100</td> <td>0.297800</td> <td>0.325400</td> <td>0.171700</td> <td>0.283700</td> <td>0.545900</td> <td>0.396900</td> <td>0.554500</td> <td>0.043000</td> <td>0.262000</td> <td>0.054500</td> <td>0.271900</td> <td>0.020300</td> <td>0.230800</td> <td>0.077600</td> <td>0.308000</td></tr> <tr><td>7</td> <td>3.889400</td> <td>1.716169</td> <td>0.143500</td> <td>0.307700</td> <td>0.123200</td> <td>0.045800</td> <td>0.097800</td> <td>0.258300</td> <td>0.165300</td> <td>0.327700</td> <td>0.352600</td> <td>0.140900</td> <td>0.336700</td> <td>0.599400</td> <td>0.442900</td> <td>0.620700</td> <td>0.069400</td> <td>0.301300</td> <td>0.081600</td> <td>0.292000</td> <td>0.011000</td> <td>0.230800</td> <td>0.112700</td> <td>0.318200</td></tr> <tr><td>8</td> <td>3.889400</td> <td>1.679014</td> <td>0.153000</td> <td>0.355800</td> <td>0.127900</td> <td>0.038700</td> <td>0.115600</td> <td>0.291600</td> <td>0.176000</td> <td>0.322500</td> <td>0.349700</td> <td>0.135600</td> <td>0.326100</td> <td>0.643700</td> <td>0.431700</td> <td>0.582900</td> <td>0.069800</td> <td>0.265800</td> <td>0.088600</td> <td>0.274600</td> <td>0.028300</td> <td>0.280000</td> <td>0.146700</td> <td>0.345300</td></tr> <tr><td>9</td> <td>3.889400</td> <td>1.618239</td> <td>0.172100</td> <td>0.375300</td> <td>0.137600</td> <td>0.046100</td> <td>0.141700</td> <td>0.308500</td> <td>0.194000</td> <td>0.356200</td> <td>0.386200</td> <td>0.162400</td> <td>0.359200</td> <td>0.677700</td> <td>0.469800</td> <td>0.623900</td> <td>0.102100</td> <td>0.317700</td> <td>0.099100</td> <td>0.290200</td> <td>0.029300</td> <td>0.335400</td> <td>0.160200</td> <td>0.364000</td></tr> <tr><td>10</td> <td>1.599700</td> <td>1.572512</td> <td>0.179500</td> <td>0.400400</td> <td>0.147200</td> <td>0.056500</td> <td>0.141700</td> <td>0.316700</td> <td>0.213100</td> <td>0.357600</td> <td>0.381300</td> <td>0.197900</td> <td>0.344300</td> <td>0.638500</td> <td>0.466900</td> <td>0.623900</td> <td>0.101300</td> <td>0.311400</td> <td>0.104700</td> <td>0.279500</td> <td>0.051600</td> <td>0.338500</td> <td>0.173000</td> <td>0.353300</td></tr> <tr><td>11</td> <td>1.599700</td> <td>1.528889</td> <td>0.192200</td> <td>0.415000</td> <td>0.160800</td> <td>0.053700</td> <td>0.150500</td> <td>0.378000</td> <td>0.211500</td> <td>0.371700</td> <td>0.397800</td> <td>0.204900</td> <td>0.374600</td> <td>0.684800</td> <td>0.491900</td> <td>0.632400</td> <td>0.131200</td> <td>0.346800</td> <td>0.122000</td> <td>0.300900</td> <td>0.038400</td> <td>0.344600</td> <td>0.177500</td> <td>0.364400</td></tr> <tr><td>12</td> <td>1.599700</td> <td>1.517532</td> <td>0.198300</td> <td>0.429800</td> <td>0.159800</td> <td>0.066400</td> <td>0.162900</td> <td>0.383300</td> <td>0.220700</td> <td>0.382100</td> <td>0.405400</td> <td>0.214800</td> <td>0.383200</td> <td>0.672900</td> <td>0.469000</td> <td>0.610400</td> <td>0.167800</td> <td>0.379700</td> <td>0.119700</td> <td>0.307100</td> <td>0.038100</td> <td>0.335400</td> <td>0.196800</td> <td>0.394200</td></tr> <tr><td>13</td> <td>1.599700</td> <td>1.488849</td> <td>0.209800</td> <td>0.452300</td> <td>0.172300</td> <td>0.094900</td> <td>0.171100</td> <td>0.437800</td> <td>0.222000</td> <td>0.379800</td> <td>0.411500</td> <td>0.203800</td> <td>0.397300</td> <td>0.707500</td> <td>0.470700</td> <td>0.620700</td> <td>0.186900</td> <td>0.407600</td> <td>0.124200</td> <td>0.306700</td> <td>0.059300</td> <td>0.355400</td> <td>0.207700</td> <td>0.367100</td></tr> <tr><td>14</td> <td>1.599700</td> <td>1.482210</td> <td>0.228900</td> <td>0.482600</td> <td>0.187800</td> <td>0.083600</td> <td>0.191800</td> <td>0.444100</td> <td>0.225900</td> <td>0.376900</td> <td>0.407400</td> <td>0.182500</td> <td>0.384800</td> <td>0.700600</td> <td>0.512100</td> <td>0.640100</td> <td>0.175000</td> <td>0.363300</td> <td>0.144300</td> <td>0.300000</td> <td>0.083100</td> <td>0.363100</td> <td>0.229900</td> <td>0.370700</td></tr> <tr><td>15</td> <td>1.326800</td> <td>1.475198</td> <td>0.216300</td> <td>0.455600</td> <td>0.174900</td> <td>0.088500</td> <td>0.183500</td> <td>0.424400</td> <td>0.226900</td> <td>0.373400</td> <td>0.404300</td> <td>0.199200</td> <td>0.396400</td> <td>0.677800</td> <td>0.496300</td> <td>0.633800</td> <td>0.166300</td> <td>0.392400</td> <td>0.128900</td> <td>0.312900</td> <td>0.085200</td> <td>0.312300</td> <td>0.205000</td> <td>0.370200</td></tr> <tr><td>16</td> <td>1.326800</td> <td>1.459697</td> <td>0.233200</td> <td>0.504200</td> <td>0.192200</td> <td>0.096000</td> <td>0.202000</td> <td>0.430800</td> <td>0.239100</td> <td>0.382400</td> <td>0.412600</td> <td>0.219500</td> <td>0.403100</td> <td>0.670400</td> <td>0.485200</td> <td>0.625200</td> <td>0.196500</td> <td>0.410100</td> <td>0.135700</td> <td>0.299600</td> <td>0.123100</td> <td>0.356900</td> <td>0.225300</td> <td>0.371100</td></tr> <tr><td>17</td> <td>1.326800</td> <td>1.407340</td> <td>0.243400</td> <td>0.511900</td> <td>0.204500</td> <td>0.121000</td> <td>0.215700</td> <td>0.468000</td> <td>0.246200</td> <td>0.394600</td> <td>0.424200</td> <td>0.225900</td> <td>0.416100</td> <td>0.705200</td> <td>0.494900</td> <td>0.638300</td> <td>0.224900</td> <td>0.430400</td> <td>0.157200</td> <td>0.317900</td> <td>0.115700</td> <td>0.369200</td> <td>0.224200</td> <td>0.365300</td></tr> <tr><td>18</td> <td>1.326800</td> <td>1.419522</td> <td>0.245100</td> <td>0.521500</td> <td>0.210000</td> <td>0.116100</td> <td>0.211500</td> <td>0.489900</td> <td>0.255400</td> <td>0.391600</td> <td>0.419700</td> <td>0.198800</td> <td>0.421200</td> <td>0.701400</td> <td>0.501800</td> <td>0.634200</td> <td>0.226700</td> <td>0.410100</td> <td>0.154400</td> <td>0.321400</td> <td>0.105900</td> <td>0.352300</td> <td>0.236700</td> <td>0.380400</td></tr> <tr><td>19</td> <td>1.158600</td> <td>1.398764</td> <td>0.253600</td> <td>0.519200</td> <td>0.213600</td> <td>0.135200</td> <td>0.207700</td> <td>0.491900</td> <td>0.257300</td> <td>0.397300</td> <td>0.428000</td> <td>0.241400</td> <td>0.401800</td> <td>0.703500</td> <td>0.509700</td> <td>0.631100</td> <td>0.236700</td> <td>0.441800</td> <td>0.155900</td> <td>0.330800</td> <td>0.128100</td> <td>0.352300</td> <td>0.237500</td> <td>0.384000</td></tr> <tr><td>20</td> <td>1.158600</td> <td>1.390591</td> <td>0.248800</td> <td>0.520200</td> <td>0.216600</td> <td>0.127500</td> <td>0.211400</td> <td>0.471900</td> <td>0.258300</td> <td>0.407000</td> <td>0.429100</td> <td>0.240300</td> <td>0.407600</td> <td>0.708500</td> <td>0.505800</td> <td>0.623400</td> <td>0.235500</td> <td>0.431600</td> <td>0.150000</td> <td>0.325000</td> <td>0.125700</td> <td>0.375400</td> <td>0.227200</td> <td>0.390200</td></tr> <tr><td>21</td> <td>1.158600</td> <td>1.360608</td> <td>0.262700</td> <td>0.544800</td> <td>0.222100</td> <td>0.134700</td> <td>0.230000</td> <td>0.487500</td> <td>0.269500</td> <td>0.413300</td> <td>0.436300</td> <td>0.236200</td> <td>0.419100</td> <td>0.709300</td> <td>0.514100</td> <td>0.637400</td> <td>0.257200</td> <td>0.450600</td> <td>0.165100</td> <td>0.338400</td> <td>0.139400</td> <td>0.372300</td> <td>0.237700</td> <td>0.382700</td></tr> <tr><td>22</td> <td>1.158600</td> <td>1.368296</td> <td>0.262800</td> <td>0.542400</td> <td>0.236400</td> <td>0.137400</td> <td>0.228100</td> <td>0.498500</td> <td>0.266500</td> <td>0.409000</td> <td>0.433000</td> <td>0.239900</td> <td>0.418500</td> <td>0.697500</td> <td>0.520500</td> <td>0.641000</td> <td>0.257500</td> <td>0.455700</td> <td>0.162600</td> <td>0.334800</td> <td>0.140200</td> <td>0.353800</td> <td>0.233200</td> <td>0.379600</td></tr> <tr><td>23</td> <td>1.158600</td> <td>1.368176</td> <td>0.264800</td> <td>0.541100</td> <td>0.233100</td> <td>0.138200</td> <td>0.223900</td> <td>0.498700</td> <td>0.272300</td> <td>0.407400</td> <td>0.434400</td> <td>0.233100</td> <td>0.418300</td> <td>0.702000</td> <td>0.524400</td> <td>0.642300</td> <td>0.262300</td> <td>0.444300</td> <td>0.159700</td> <td>0.335300</td> <td>0.140500</td> <td>0.366200</td> <td>0.236900</td> <td>0.384000</td></tr> <tr><td>24</td> <td>1.049700</td> <td>1.355271</td> <td>0.269700</td> <td>0.549200</td> <td>0.239100</td> <td>0.134700</td> <td>0.229900</td> <td>0.519200</td> <td>0.274800</td> <td>0.412700</td> <td>0.437600</td> <td>0.245400</td> <td>0.417200</td> <td>0.711200</td> <td>0.523200</td> <td>0.644100</td> <td>0.272100</td> <td>0.440500</td> <td>0.166700</td> <td>0.341500</td> <td>0.137700</td> <td>0.373800</td> <td>0.249000</td> <td>0.388000</td></tr> <tr><td>25</td> <td>1.049700</td> <td>1.355180</td> <td>0.272500</td> <td>0.547900</td> <td>0.243800</td> <td>0.149700</td> <td>0.229900</td> <td>0.523100</td> <td>0.272500</td> <td>0.415700</td> <td>0.442200</td> <td>0.256200</td> <td>0.420200</td> <td>0.705800</td> <td>0.523900</td> <td>0.639600</td> <td>0.271700</td> <td>0.451900</td> <td>0.166300</td> <td>0.346900</td> <td>0.153700</td> <td>0.383100</td> <td>0.247000</td> <td>0.389300</td></tr> <tr><td>26</td> <td>1.049700</td> <td>1.349337</td> <td>0.275600</td> <td>0.556300</td> <td>0.246400</td> <td>0.146700</td> <td>0.234800</td> <td>0.516300</td> <td>0.274200</td> <td>0.418300</td> <td>0.440900</td> <td>0.248700</td> <td>0.418900</td> <td>0.705800</td> <td>0.523200</td> <td>0.636500</td> <td>0.274700</td> <td>0.440500</td> <td>0.172400</td> <td>0.349100</td> <td>0.155600</td> <td>0.384600</td> <td>0.252300</td> <td>0.393800</td></tr> <tr><td>27</td> <td>1.049700</td> <td>1.350782</td> <td>0.275200</td> <td>0.548700</td> <td>0.246800</td> <td>0.147300</td> <td>0.236400</td> <td>0.527200</td> <td>0.280100</td> <td>0.416200</td> <td>0.442600</td> <td>0.253400</td> <td>0.424000</td> <td>0.710300</td> <td>0.526600</td> <td>0.640100</td> <td>0.273200</td> <td>0.445600</td> <td>0.167000</td> <td>0.346900</td> <td>0.160100</td> <td>0.387700</td> <td>0.249200</td> <td>0.392900</td></tr> <tr><td>28</td> <td>1.049700</td> <td>1.346533</td> <td>0.277000</td> <td>0.552800</td> <td>0.252900</td> <td>0.147400</td> <td>0.240000</td> <td>0.527600</td> <td>0.280900</td> <td>0.420900</td> <td>0.444100</td> <td>0.255500</td> <td>0.424500</td> <td>0.711200</td> <td>0.530200</td> <td>0.646800</td> <td>0.277400</td> <td>0.441800</td> <td>0.170900</td> <td>0.346900</td> <td>0.156600</td> <td>0.389200</td> <td>0.249600</td> <td>0.396000</td></tr> <tr><td>29</td> <td>0.993700</td> <td>1.346575</td> <td>0.277100</td> <td>0.554800</td> <td>0.252900</td> <td>0.148400</td> <td>0.239700</td> <td>0.523600</td> <td>0.278400</td> <td>0.420000</td> <td>0.443300</td> <td>0.256300</td> <td>0.424000</td> <td>0.705600</td> <td>0.529600</td> <td>0.647300</td> <td>0.273900</td> <td>0.439200</td> <td>0.174300</td> <td>0.348700</td> <td>0.157600</td> <td>0.386200</td> <td>0.250100</td> <td>0.395100</td></tr> <tr><td>30</td> <td>0.993700</td> <td>1.346446</td> <td>0.277400</td> <td>0.554700</td> <td>0.252700</td> <td>0.147900</td> <td>0.240800</td> <td>0.523600</td> <td>0.278800</td> <td>0.420400</td> <td>0.443300</td> <td>0.256100</td> <td>0.424200</td> <td>0.705500</td> <td>0.530100</td> <td>0.646800</td> <td>0.275600</td> <td>0.440500</td> <td>0.174500</td> <td>0.348700</td> <td>0.157300</td> <td>0.386200</td> <td>0.249200</td> <td>0.394200</td></tr></tbody> ',Vs,Ul="",Rs,wl=`If you have set <code>push_to_hub</code> to <code>True</code> in the <code>training_args</code>, the training checkpoints are pushed to the
Hugging Face Hub. Upon training completion, push the final model to the Hub as well by calling the <a href="/docs/transformers/pr_31172/en/main_classes/trainer#transformers.Trainer.push_to_hub">push_to_hub()</a> method.`,ha,Qs,ja,ks,ya,Ys,Ja,As,gl='These results can be further improved by adjusting the hyperparameters in <a href="/docs/transformers/pr_31172/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a>. Give it a go!',ba,Ns,Ta,Xs,Il="Now that you have finetuned a model, evaluated it, and uploaded it to the Hugging Face Hub, you can use it for inference.",ua,Es,Ua,zs,Cl="Load model and image processor from the Hugging Face Hub (skip to use already trained in this session):",wa,Hs,ga,Fs,fl="And detect bounding boxes:",Ia,Ss,Ca,$s,Bl="Let’s plot the result:",fa,qs,Ba,U,_l='<img src="https://i.imgur.com/oDUqD0K.png" alt="Object detection result on a new image"/>',_a,Ds,Ga,Os,Za;return g=new Ls({props:{title:"Object detection",local:"object-detection",headingTag:"h1"}}),I=new Al({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/object_detection.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/object_detection.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/object_detection.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/object_detection.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/object_detection.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/object_detection.ipynb"}]}}),T=new Yl({props:{$$slots:{default:[Xl]},$$scope:{ctx:st}}}),G=new j({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1xJTIwZGF0YXNldHMlMjB0cmFuc2Zvcm1lcnMlMjBhY2NlbGVyYXRlJTIwdGltbSUwQXBpcCUyMGluc3RhbGwlMjAtcSUyMC1VJTIwYWxidW1lbnRhdGlvbnMlM0UlM0QxLjQuNSUyMHRvcmNobWV0cmljcyUyMHB5Y29jb3Rvb2xz",highlighted:`pip install -q datasets transformers accelerate timm
pip install -q -U albumentations&gt;=1.4.5 torchmetrics pycocotools`,wrap:!1}}),W=new j({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

<span class="hljs-meta">&gt;&gt;&gt; </span>notebook_login()`,wrap:!1}}),V=new j({props:{code:"TU9ERUxfTkFNRSUyMCUzRCUyMCUyMm1pY3Jvc29mdCUyRmNvbmRpdGlvbmFsLWRldHItcmVzbmV0LTUwJTIyJTIwJTIwJTIzJTIwb3IlMjAlMjJmYWNlYm9vayUyRmRldHItcmVzbmV0LTUwJTIyJTBBSU1BR0VfU0laRSUyMCUzRCUyMDQ4MA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>MODEL_NAME = <span class="hljs-string">&quot;microsoft/conditional-detr-resnet-50&quot;</span>  <span class="hljs-comment"># or &quot;facebook/detr-resnet-50&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>IMAGE_SIZE = <span class="hljs-number">480</span>`,wrap:!1}}),R=new Ls({props:{title:"Load the CPPE-5 dataset",local:"load-the-cppe-5-dataset",headingTag:"h2"}}),Y=new j({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBY3BwZTUlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIyY3BwZS01JTIyKSUwQSUwQWlmJTIwJTIydmFsaWRhdGlvbiUyMiUyMG5vdCUyMGluJTIwY3BwZTUlM0ElMEElMjAlMjAlMjAlMjBzcGxpdCUyMCUzRCUyMGNwcGU1JTVCJTIydHJhaW4lMjIlNUQudHJhaW5fdGVzdF9zcGxpdCgwLjE1JTJDJTIwc2VlZCUzRDEzMzcpJTBBJTIwJTIwJTIwJTIwY3BwZTUlNUIlMjJ0cmFpbiUyMiU1RCUyMCUzRCUyMHNwbGl0JTVCJTIydHJhaW4lMjIlNUQlMEElMjAlMjAlMjAlMjBjcHBlNSU1QiUyMnZhbGlkYXRpb24lMjIlNUQlMjAlM0QlMjBzcGxpdCU1QiUyMnRlc3QlMjIlNUQlMEElMEFjcHBlNQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-meta">&gt;&gt;&gt; </span>cppe5 = load_dataset(<span class="hljs-string">&quot;cppe-5&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">if</span> <span class="hljs-string">&quot;validation&quot;</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> cppe5:
<span class="hljs-meta">... </span>    split = cppe5[<span class="hljs-string">&quot;train&quot;</span>].train_test_split(<span class="hljs-number">0.15</span>, seed=<span class="hljs-number">1337</span>)
<span class="hljs-meta">... </span>    cppe5[<span class="hljs-string">&quot;train&quot;</span>] = split[<span class="hljs-string">&quot;train&quot;</span>]
<span class="hljs-meta">... </span>    cppe5[<span class="hljs-string">&quot;validation&quot;</span>] = split[<span class="hljs-string">&quot;test&quot;</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>cppe5
DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;image_id&#x27;</span>, <span class="hljs-string">&#x27;image&#x27;</span>, <span class="hljs-string">&#x27;width&#x27;</span>, <span class="hljs-string">&#x27;height&#x27;</span>, <span class="hljs-string">&#x27;objects&#x27;</span>],
        num_rows: <span class="hljs-number">850</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;image_id&#x27;</span>, <span class="hljs-string">&#x27;image&#x27;</span>, <span class="hljs-string">&#x27;width&#x27;</span>, <span class="hljs-string">&#x27;height&#x27;</span>, <span class="hljs-string">&#x27;objects&#x27;</span>],
        num_rows: <span class="hljs-number">29</span>
    })
    validation: Dataset({
        features: [<span class="hljs-string">&#x27;image_id&#x27;</span>, <span class="hljs-string">&#x27;image&#x27;</span>, <span class="hljs-string">&#x27;width&#x27;</span>, <span class="hljs-string">&#x27;height&#x27;</span>, <span class="hljs-string">&#x27;objects&#x27;</span>],
        num_rows: <span class="hljs-number">150</span>
    })
})`,wrap:!1}}),X=new j({props:{code:"Y3BwZTUlNUIlMjJ0cmFpbiUyMiU1RCU1QjAlNUQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>cppe5[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]
{
  <span class="hljs-string">&#x27;image_id&#x27;</span>: <span class="hljs-number">366</span>,
  <span class="hljs-string">&#x27;image&#x27;</span>: &lt;PIL.PngImagePlugin.PngImageFile image mode=RGBA size=500x290&gt;,
  <span class="hljs-string">&#x27;width&#x27;</span>: <span class="hljs-number">500</span>,
  <span class="hljs-string">&#x27;height&#x27;</span>: <span class="hljs-number">500</span>,
  <span class="hljs-string">&#x27;objects&#x27;</span>: {
    <span class="hljs-string">&#x27;id&#x27;</span>: [<span class="hljs-number">1932</span>, <span class="hljs-number">1933</span>, <span class="hljs-number">1934</span>],
    <span class="hljs-string">&#x27;area&#x27;</span>: [<span class="hljs-number">27063</span>, <span class="hljs-number">34200</span>, <span class="hljs-number">32431</span>],
    <span class="hljs-string">&#x27;bbox&#x27;</span>: [[<span class="hljs-number">29.0</span>, <span class="hljs-number">11.0</span>, <span class="hljs-number">97.0</span>, <span class="hljs-number">279.0</span>],
      [<span class="hljs-number">201.0</span>, <span class="hljs-number">1.0</span>, <span class="hljs-number">120.0</span>, <span class="hljs-number">285.0</span>],
      [<span class="hljs-number">382.0</span>, <span class="hljs-number">0.0</span>, <span class="hljs-number">113.0</span>, <span class="hljs-number">287.0</span>]],
    <span class="hljs-string">&#x27;category&#x27;</span>: [<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>]
  }
}`,wrap:!1}}),S=new j({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBaW1wb3J0JTIwb3MlMEFmcm9tJTIwUElMJTIwaW1wb3J0JTIwSW1hZ2UlMkMlMjBJbWFnZURyYXclMEElMEFpbWFnZSUyMCUzRCUyMGNwcGU1JTVCJTIydHJhaW4lMjIlNUQlNUIyJTVEJTVCJTIyaW1hZ2UlMjIlNUQlMEFhbm5vdGF0aW9ucyUyMCUzRCUyMGNwcGU1JTVCJTIydHJhaW4lMjIlNUQlNUIyJTVEJTVCJTIyb2JqZWN0cyUyMiU1RCUwQWRyYXclMjAlM0QlMjBJbWFnZURyYXcuRHJhdyhpbWFnZSklMEElMEFjYXRlZ29yaWVzJTIwJTNEJTIwY3BwZTUlNUIlMjJ0cmFpbiUyMiU1RC5mZWF0dXJlcyU1QiUyMm9iamVjdHMlMjIlNUQuZmVhdHVyZSU1QiUyMmNhdGVnb3J5JTIyJTVELm5hbWVzJTBBJTBBaWQybGFiZWwlMjAlM0QlMjAlN0JpbmRleCUzQSUyMHglMjBmb3IlMjBpbmRleCUyQyUyMHglMjBpbiUyMGVudW1lcmF0ZShjYXRlZ29yaWVzJTJDJTIwc3RhcnQlM0QwKSU3RCUwQWxhYmVsMmlkJTIwJTNEJTIwJTdCdiUzQSUyMGslMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwaWQybGFiZWwuaXRlbXMoKSU3RCUwQSUwQWZvciUyMGklMjBpbiUyMHJhbmdlKGxlbihhbm5vdGF0aW9ucyU1QiUyMmlkJTIyJTVEKSklM0ElMEElMjAlMjAlMjAlMjBib3glMjAlM0QlMjBhbm5vdGF0aW9ucyU1QiUyMmJib3glMjIlNUQlNUJpJTVEJTBBJTIwJTIwJTIwJTIwY2xhc3NfaWR4JTIwJTNEJTIwYW5ub3RhdGlvbnMlNUIlMjJjYXRlZ29yeSUyMiU1RCU1QmklNUQlMEElMjAlMjAlMjAlMjB4JTJDJTIweSUyQyUyMHclMkMlMjBoJTIwJTNEJTIwdHVwbGUoYm94KSUwQSUyMCUyMCUyMCUyMCUyMyUyMENoZWNrJTIwaWYlMjBjb29yZGluYXRlcyUyMGFyZSUyMG5vcm1hbGl6ZWQlMjBvciUyMG5vdCUwQSUyMCUyMCUyMCUyMGlmJTIwbWF4KGJveCklMjAlM0UlMjAxLjAlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBDb29yZGluYXRlcyUyMGFyZSUyMHVuLW5vcm1hbGl6ZWQlMkMlMjBubyUyMG5lZWQlMjB0byUyMHJlLXNjYWxlJTIwdGhlbSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHgxJTJDJTIweTElMjAlM0QlMjBpbnQoeCklMkMlMjBpbnQoeSklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB4MiUyQyUyMHkyJTIwJTNEJTIwaW50KHglMjAlMkIlMjB3KSUyQyUyMGludCh5JTIwJTJCJTIwaCklMEElMjAlMjAlMjAlMjBlbHNlJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwQ29vcmRpbmF0ZXMlMjBhcmUlMjBub3JtYWxpemVkJTJDJTIwcmUtc2NhbGUlMjB0aGVtJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIweDElMjAlM0QlMjBpbnQoeCUyMColMjB3aWR0aCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB5MSUyMCUzRCUyMGludCh5JTIwKiUyMGhlaWdodCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB4MiUyMCUzRCUyMGludCgoeCUyMCUyQiUyMHcpJTIwKiUyMHdpZHRoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHkyJTIwJTNEJTIwaW50KCh5JTIwJTJCJTIwaCklMjAqJTIwaGVpZ2h0KSUwQSUyMCUyMCUyMCUyMGRyYXcucmVjdGFuZ2xlKCh4JTJDJTIweSUyQyUyMHglMjAlMkIlMjB3JTJDJTIweSUyMCUyQiUyMGgpJTJDJTIwb3V0bGluZSUzRCUyMnJlZCUyMiUyQyUyMHdpZHRoJTNEMSklMEElMjAlMjAlMjAlMjBkcmF3LnRleHQoKHglMkMlMjB5KSUyQyUyMGlkMmxhYmVsJTVCY2xhc3NfaWR4JTVEJTJDJTIwZmlsbCUzRCUyMndoaXRlJTIyKSUwQSUwQWltYWdl",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> os
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image, ImageDraw

<span class="hljs-meta">&gt;&gt;&gt; </span>image = cppe5[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">2</span>][<span class="hljs-string">&quot;image&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>annotations = cppe5[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">2</span>][<span class="hljs-string">&quot;objects&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>draw = ImageDraw.Draw(image)

<span class="hljs-meta">&gt;&gt;&gt; </span>categories = cppe5[<span class="hljs-string">&quot;train&quot;</span>].features[<span class="hljs-string">&quot;objects&quot;</span>].feature[<span class="hljs-string">&quot;category&quot;</span>].names

<span class="hljs-meta">&gt;&gt;&gt; </span>id2label = {index: x <span class="hljs-keyword">for</span> index, x <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(categories, start=<span class="hljs-number">0</span>)}
<span class="hljs-meta">&gt;&gt;&gt; </span>label2id = {v: k <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> id2label.items()}

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(annotations[<span class="hljs-string">&quot;id&quot;</span>])):
<span class="hljs-meta">... </span>    box = annotations[<span class="hljs-string">&quot;bbox&quot;</span>][i]
<span class="hljs-meta">... </span>    class_idx = annotations[<span class="hljs-string">&quot;category&quot;</span>][i]
<span class="hljs-meta">... </span>    x, y, w, h = <span class="hljs-built_in">tuple</span>(box)
<span class="hljs-meta">... </span>    <span class="hljs-comment"># Check if coordinates are normalized or not</span>
<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> <span class="hljs-built_in">max</span>(box) &gt; <span class="hljs-number">1.0</span>:
<span class="hljs-meta">... </span>        <span class="hljs-comment"># Coordinates are un-normalized, no need to re-scale them</span>
<span class="hljs-meta">... </span>        x1, y1 = <span class="hljs-built_in">int</span>(x), <span class="hljs-built_in">int</span>(y)
<span class="hljs-meta">... </span>        x2, y2 = <span class="hljs-built_in">int</span>(x + w), <span class="hljs-built_in">int</span>(y + h)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">else</span>:
<span class="hljs-meta">... </span>        <span class="hljs-comment"># Coordinates are normalized, re-scale them</span>
<span class="hljs-meta">... </span>        x1 = <span class="hljs-built_in">int</span>(x * width)
<span class="hljs-meta">... </span>        y1 = <span class="hljs-built_in">int</span>(y * height)
<span class="hljs-meta">... </span>        x2 = <span class="hljs-built_in">int</span>((x + w) * width)
<span class="hljs-meta">... </span>        y2 = <span class="hljs-built_in">int</span>((y + h) * height)
<span class="hljs-meta">... </span>    draw.rectangle((x, y, x + w, y + h), outline=<span class="hljs-string">&quot;red&quot;</span>, width=<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    draw.text((x, y), id2label[class_idx], fill=<span class="hljs-string">&quot;white&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>image`,wrap:!1}}),D=new Ls({props:{title:"Preprocess the data",local:"preprocess-the-data",headingTag:"h2"}}),ss=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUwQSUwQWltYWdlX3Byb2Nlc3NvciUyMCUzRCUyMEF1dG9JbWFnZVByb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwTU9ERUxfTkFNRSUyQyUwQSUyMCUyMCUyMCUyMGRvX3Jlc2l6ZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBzaXplJTNEJTdCJTIybWF4X2hlaWdodCUyMiUzQSUyME1BWF9TSVpFJTJDJTIwJTIybWF4X3dpZHRoJTIyJTNBJTIwTUFYX1NJWkUlN0QlMkMlMEElMjAlMjAlMjAlMjBkb19wYWQlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwcGFkX3NpemUlM0QlN0IlMjJoZWlnaHQlMjIlM0ElMjBNQVhfU0laRSUyQyUyMCUyMndpZHRoJTIyJTNBJTIwTUFYX1NJWkUlN0QlMkMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor

<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(
<span class="hljs-meta">... </span>    MODEL_NAME,
<span class="hljs-meta">... </span>    do_resize=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    size={<span class="hljs-string">&quot;max_height&quot;</span>: MAX_SIZE, <span class="hljs-string">&quot;max_width&quot;</span>: MAX_SIZE},
<span class="hljs-meta">... </span>    do_pad=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    pad_size={<span class="hljs-string">&quot;height&quot;</span>: MAX_SIZE, <span class="hljs-string">&quot;width&quot;</span>: MAX_SIZE},
<span class="hljs-meta">... </span>)`,wrap:!1}}),es=new j({props:{code:"aW1wb3J0JTIwYWxidW1lbnRhdGlvbnMlMjBhcyUyMEElMEElMEFtYXhfc2l6ZSUyMCUzRCUyMElNQUdFX1NJWkUlMEElMEF0cmFpbl9hdWdtZW50X2FuZF90cmFuc2Zvcm0lMjAlM0QlMjBBLkNvbXBvc2UoJTBBJTIwJTIwJTIwJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwQS5QZXJzcGVjdGl2ZShwJTNEMC4xKSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMEEuSG9yaXpvbnRhbEZsaXAocCUzRDAuNSklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBBLlJhbmRvbUJyaWdodG5lc3NDb250cmFzdChwJTNEMC41KSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMEEuSHVlU2F0dXJhdGlvblZhbHVlKHAlM0QwLjEpJTJDJTBBJTIwJTIwJTIwJTIwJTVEJTJDJTBBJTIwJTIwJTIwJTIwYmJveF9wYXJhbXMlM0RBLkJib3hQYXJhbXMoZm9ybWF0JTNEJTIyY29jbyUyMiUyQyUyMGxhYmVsX2ZpZWxkcyUzRCU1QiUyMmNhdGVnb3J5JTIyJTVEJTJDJTIwY2xpcCUzRFRydWUlMkMlMjBtaW5fYXJlYSUzRDI1KSUyQyUwQSklMEElMEF2YWxpZGF0aW9uX3RyYW5zZm9ybSUyMCUzRCUyMEEuQ29tcG9zZSglMEElMjAlMjAlMjAlMjAlNUJBLk5vT3AoKSU1RCUyQyUwQSUyMCUyMCUyMCUyMGJib3hfcGFyYW1zJTNEQS5CYm94UGFyYW1zKGZvcm1hdCUzRCUyMmNvY28lMjIlMkMlMjBsYWJlbF9maWVsZHMlM0QlNUIlMjJjYXRlZ29yeSUyMiU1RCUyQyUyMGNsaXAlM0RUcnVlKSUyQyUwQSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> albumentations <span class="hljs-keyword">as</span> A

<span class="hljs-meta">&gt;&gt;&gt; </span>max_size = IMAGE_SIZE

<span class="hljs-meta">&gt;&gt;&gt; </span>train_augment_and_transform = A.Compose(
<span class="hljs-meta">... </span>    [
<span class="hljs-meta">... </span>        A.Perspective(p=<span class="hljs-number">0.1</span>),
<span class="hljs-meta">... </span>        A.HorizontalFlip(p=<span class="hljs-number">0.5</span>),
<span class="hljs-meta">... </span>        A.RandomBrightnessContrast(p=<span class="hljs-number">0.5</span>),
<span class="hljs-meta">... </span>        A.HueSaturationValue(p=<span class="hljs-number">0.1</span>),
<span class="hljs-meta">... </span>    ],
<span class="hljs-meta">... </span>    bbox_params=A.BboxParams(<span class="hljs-built_in">format</span>=<span class="hljs-string">&quot;coco&quot;</span>, label_fields=[<span class="hljs-string">&quot;category&quot;</span>], clip=<span class="hljs-literal">True</span>, min_area=<span class="hljs-number">25</span>),
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>validation_transform = A.Compose(
<span class="hljs-meta">... </span>    [A.NoOp()],
<span class="hljs-meta">... </span>    bbox_params=A.BboxParams(<span class="hljs-built_in">format</span>=<span class="hljs-string">&quot;coco&quot;</span>, label_fields=[<span class="hljs-string">&quot;category&quot;</span>], clip=<span class="hljs-literal">True</span>),
<span class="hljs-meta">... </span>)`,wrap:!1}}),ps=new j({props:{code:"ZGVmJTIwZm9ybWF0X2ltYWdlX2Fubm90YXRpb25zX2FzX2NvY28oaW1hZ2VfaWQlMkMlMjBjYXRlZ29yaWVzJTJDJTIwYXJlYXMlMkMlMjBiYm94ZXMpJTNBJTBBJTIwJTIwJTIwJTIwJTIyJTIyJTIyRm9ybWF0JTIwb25lJTIwc2V0JTIwb2YlMjBpbWFnZSUyMGFubm90YXRpb25zJTIwdG8lMjB0aGUlMjBDT0NPJTIwZm9ybWF0JTBBJTBBJTIwJTIwJTIwJTIwQXJncyUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGltYWdlX2lkJTIwKHN0ciklM0ElMjBpbWFnZSUyMGlkLiUyMGUuZy4lMjAlMjIwMDAxJTIyJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY2F0ZWdvcmllcyUyMChMaXN0JTVCaW50JTVEKSUzQSUyMGxpc3QlMjBvZiUyMGNhdGVnb3JpZXMlMkZjbGFzcyUyMGxhYmVscyUyMGNvcnJlc3BvbmRpbmclMjB0byUyMHByb3ZpZGVkJTIwYm91bmRpbmclMjBib3hlcyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGFyZWFzJTIwKExpc3QlNUJmbG9hdCU1RCklM0ElMjBsaXN0JTIwb2YlMjBjb3JyZXNwb25kaW5nJTIwYXJlYXMlMjB0byUyMHByb3ZpZGVkJTIwYm91bmRpbmclMjBib3hlcyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGJib3hlcyUyMChMaXN0JTVCVHVwbGUlNUJmbG9hdCU1RCU1RCklM0ElMjBsaXN0JTIwb2YlMjBib3VuZGluZyUyMGJveGVzJTIwcHJvdmlkZWQlMjBpbiUyMENPQ08lMjBmb3JtYXQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAoJTVCY2VudGVyX3glMkMlMjBjZW50ZXJfeSUyQyUyMHdpZHRoJTJDJTIwaGVpZ2h0JTVEJTIwaW4lMjBhYnNvbHV0ZSUyMGNvb3JkaW5hdGVzKSUwQSUwQSUyMCUyMCUyMCUyMFJldHVybnMlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBkaWN0JTNBJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyaW1hZ2VfaWQlMjIlM0ElMjBpbWFnZSUyMGlkJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyYW5ub3RhdGlvbnMlMjIlM0ElMjBsaXN0JTIwb2YlMjBmb3JtYXR0ZWQlMjBhbm5vdGF0aW9ucyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3RCUwQSUyMCUyMCUyMCUyMCUyMiUyMiUyMiUwQSUyMCUyMCUyMCUyMGFubm90YXRpb25zJTIwJTNEJTIwJTVCJTVEJTBBJTIwJTIwJTIwJTIwZm9yJTIwY2F0ZWdvcnklMkMlMjBhcmVhJTJDJTIwYmJveCUyMGluJTIwemlwKGNhdGVnb3JpZXMlMkMlMjBhcmVhcyUyQyUyMGJib3hlcyklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmb3JtYXR0ZWRfYW5ub3RhdGlvbiUyMCUzRCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmltYWdlX2lkJTIyJTNBJTIwaW1hZ2VfaWQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJjYXRlZ29yeV9pZCUyMiUzQSUyMGNhdGVnb3J5JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyaXNjcm93ZCUyMiUzQSUyMDAlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJhcmVhJTIyJTNBJTIwYXJlYSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmJib3glMjIlM0ElMjBsaXN0KGJib3gpJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYW5ub3RhdGlvbnMuYXBwZW5kKGZvcm1hdHRlZF9hbm5vdGF0aW9uKSUwQSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmltYWdlX2lkJTIyJTNBJTIwaW1hZ2VfaWQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJhbm5vdGF0aW9ucyUyMiUzQSUyMGFubm90YXRpb25zJTJDJTBBJTIwJTIwJTIwJTIwJTdEJTBB",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">format_image_annotations_as_coco</span>(<span class="hljs-params">image_id, categories, areas, bboxes</span>):
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;&quot;&quot;Format one set of image annotations to the COCO format

<span class="hljs-meta">... </span>    Args:
<span class="hljs-meta">... </span>        image_id (str): image id. e.g. &quot;0001&quot;
<span class="hljs-meta">... </span>        categories (List[int]): list of categories/class labels corresponding to provided bounding boxes
<span class="hljs-meta">... </span>        areas (List[float]): list of corresponding areas to provided bounding boxes
<span class="hljs-meta">... </span>        bboxes (List[Tuple[float]]): list of bounding boxes provided in COCO format
<span class="hljs-meta">... </span>            ([center_x, center_y, width, height] in absolute coordinates)

<span class="hljs-meta">... </span>    Returns:
<span class="hljs-meta">... </span>        dict: {
<span class="hljs-meta">... </span>            &quot;image_id&quot;: image id,
<span class="hljs-meta">... </span>            &quot;annotations&quot;: list of formatted annotations
<span class="hljs-meta">... </span>        }
<span class="hljs-meta">... </span>    &quot;&quot;&quot;</span>
<span class="hljs-meta">... </span>    annotations = []
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> category, area, bbox <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(categories, areas, bboxes):
<span class="hljs-meta">... </span>        formatted_annotation = {
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;image_id&quot;</span>: image_id,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;category_id&quot;</span>: category,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;iscrowd&quot;</span>: <span class="hljs-number">0</span>,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;area&quot;</span>: area,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;bbox&quot;</span>: <span class="hljs-built_in">list</span>(bbox),
<span class="hljs-meta">... </span>        }
<span class="hljs-meta">... </span>        annotations.append(formatted_annotation)

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> {
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;image_id&quot;</span>: image_id,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;annotations&quot;</span>: annotations,
<span class="hljs-meta">... </span>    }
`,wrap:!1}}),cs=new j({props:{code:"ZGVmJTIwYXVnbWVudF9hbmRfdHJhbnNmb3JtX2JhdGNoKGV4YW1wbGVzJTJDJTIwdHJhbnNmb3JtJTJDJTIwaW1hZ2VfcHJvY2Vzc29yJTJDJTIwcmV0dXJuX3BpeGVsX21hc2slM0RGYWxzZSklM0ElMEElMjAlMjAlMjAlMjAlMjIlMjIlMjJBcHBseSUyMGF1Z21lbnRhdGlvbnMlMjBhbmQlMjBmb3JtYXQlMjBhbm5vdGF0aW9ucyUyMGluJTIwQ09DTyUyMGZvcm1hdCUyMGZvciUyMG9iamVjdCUyMGRldGVjdGlvbiUyMHRhc2slMjIlMjIlMjIlMEElMEElMjAlMjAlMjAlMjBpbWFnZXMlMjAlM0QlMjAlNUIlNUQlMEElMjAlMjAlMjAlMjBhbm5vdGF0aW9ucyUyMCUzRCUyMCU1QiU1RCUwQSUyMCUyMCUyMCUyMGZvciUyMGltYWdlX2lkJTJDJTIwaW1hZ2UlMkMlMjBvYmplY3RzJTIwaW4lMjB6aXAoZXhhbXBsZXMlNUIlMjJpbWFnZV9pZCUyMiU1RCUyQyUyMGV4YW1wbGVzJTVCJTIyaW1hZ2UlMjIlNUQlMkMlMjBleGFtcGxlcyU1QiUyMm9iamVjdHMlMjIlNUQpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW1hZ2UlMjAlM0QlMjBucC5hcnJheShpbWFnZS5jb252ZXJ0KCUyMlJHQiUyMikpJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwYXBwbHklMjBhdWdtZW50YXRpb25zJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwb3V0cHV0JTIwJTNEJTIwdHJhbnNmb3JtKGltYWdlJTNEaW1hZ2UlMkMlMjBiYm94ZXMlM0RvYmplY3RzJTVCJTIyYmJveCUyMiU1RCUyQyUyMGNhdGVnb3J5JTNEb2JqZWN0cyU1QiUyMmNhdGVnb3J5JTIyJTVEKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGltYWdlcy5hcHBlbmQob3V0cHV0JTVCJTIyaW1hZ2UlMjIlNUQpJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwZm9ybWF0JTIwYW5ub3RhdGlvbnMlMjBpbiUyMENPQ08lMjBmb3JtYXQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmb3JtYXR0ZWRfYW5ub3RhdGlvbnMlMjAlM0QlMjBmb3JtYXRfaW1hZ2VfYW5ub3RhdGlvbnNfYXNfY29jbyglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpbWFnZV9pZCUyQyUyMG91dHB1dCU1QiUyMmNhdGVnb3J5JTIyJTVEJTJDJTIwb2JqZWN0cyU1QiUyMmFyZWElMjIlNUQlMkMlMjBvdXRwdXQlNUIlMjJiYm94ZXMlMjIlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjApJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYW5ub3RhdGlvbnMuYXBwZW5kKGZvcm1hdHRlZF9hbm5vdGF0aW9ucyklMEElMEElMjAlMjAlMjAlMjAlMjMlMjBBcHBseSUyMHRoZSUyMGltYWdlJTIwcHJvY2Vzc29yJTIwdHJhbnNmb3JtYXRpb25zJTNBJTIwcmVzaXppbmclMkMlMjByZXNjYWxpbmclMkMlMjBub3JtYWxpemF0aW9uJTBBJTIwJTIwJTIwJTIwcmVzdWx0JTIwJTNEJTIwaW1hZ2VfcHJvY2Vzc29yKGltYWdlcyUzRGltYWdlcyUyQyUyMGFubm90YXRpb25zJTNEYW5ub3RhdGlvbnMlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQSUwQSUyMCUyMCUyMCUyMGlmJTIwbm90JTIwcmV0dXJuX3BpeGVsX21hc2slM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXN1bHQucG9wKCUyMnBpeGVsX21hc2slMjIlMkMlMjBOb25lKSUwQSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMHJlc3VsdA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">augment_and_transform_batch</span>(<span class="hljs-params">examples, transform, image_processor, return_pixel_mask=<span class="hljs-literal">False</span></span>):
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;&quot;&quot;Apply augmentations and format annotations in COCO format for object detection task&quot;&quot;&quot;</span>

<span class="hljs-meta">... </span>    images = []
<span class="hljs-meta">... </span>    annotations = []
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> image_id, image, objects <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(examples[<span class="hljs-string">&quot;image_id&quot;</span>], examples[<span class="hljs-string">&quot;image&quot;</span>], examples[<span class="hljs-string">&quot;objects&quot;</span>]):
<span class="hljs-meta">... </span>        image = np.array(image.convert(<span class="hljs-string">&quot;RGB&quot;</span>))

<span class="hljs-meta">... </span>        <span class="hljs-comment"># apply augmentations</span>
<span class="hljs-meta">... </span>        output = transform(image=image, bboxes=objects[<span class="hljs-string">&quot;bbox&quot;</span>], category=objects[<span class="hljs-string">&quot;category&quot;</span>])
<span class="hljs-meta">... </span>        images.append(output[<span class="hljs-string">&quot;image&quot;</span>])

<span class="hljs-meta">... </span>        <span class="hljs-comment"># format annotations in COCO format</span>
<span class="hljs-meta">... </span>        formatted_annotations = format_image_annotations_as_coco(
<span class="hljs-meta">... </span>            image_id, output[<span class="hljs-string">&quot;category&quot;</span>], objects[<span class="hljs-string">&quot;area&quot;</span>], output[<span class="hljs-string">&quot;bboxes&quot;</span>]
<span class="hljs-meta">... </span>        )
<span class="hljs-meta">... </span>        annotations.append(formatted_annotations)

<span class="hljs-meta">... </span>    <span class="hljs-comment"># Apply the image processor transformations: resizing, rescaling, normalization</span>
<span class="hljs-meta">... </span>    result = image_processor(images=images, annotations=annotations, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> return_pixel_mask:
<span class="hljs-meta">... </span>        result.pop(<span class="hljs-string">&quot;pixel_mask&quot;</span>, <span class="hljs-literal">None</span>)

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> result`,wrap:!1}}),Ms=new j({props:{code:"ZnJvbSUyMGZ1bmN0b29scyUyMGltcG9ydCUyMHBhcnRpYWwlMEElMEElMjMlMjBNYWtlJTIwdHJhbnNmb3JtJTIwZnVuY3Rpb25zJTIwZm9yJTIwYmF0Y2glMjBhbmQlMjBhcHBseSUyMGZvciUyMGRhdGFzZXQlMjBzcGxpdHMlMEF0cmFpbl90cmFuc2Zvcm1fYmF0Y2glMjAlM0QlMjBwYXJ0aWFsKCUwQSUyMCUyMCUyMCUyMGF1Z21lbnRfYW5kX3RyYW5zZm9ybV9iYXRjaCUyQyUyMHRyYW5zZm9ybSUzRHRyYWluX2F1Z21lbnRfYW5kX3RyYW5zZm9ybSUyQyUyMGltYWdlX3Byb2Nlc3NvciUzRGltYWdlX3Byb2Nlc3NvciUwQSklMEF2YWxpZGF0aW9uX3RyYW5zZm9ybV9iYXRjaCUyMCUzRCUyMHBhcnRpYWwoJTBBJTIwJTIwJTIwJTIwYXVnbWVudF9hbmRfdHJhbnNmb3JtX2JhdGNoJTJDJTIwdHJhbnNmb3JtJTNEdmFsaWRhdGlvbl90cmFuc2Zvcm0lMkMlMjBpbWFnZV9wcm9jZXNzb3IlM0RpbWFnZV9wcm9jZXNzb3IlMEEpJTBBJTBBY3BwZTUlNUIlMjJ0cmFpbiUyMiU1RCUyMCUzRCUyMGNwcGU1JTVCJTIydHJhaW4lMjIlNUQud2l0aF90cmFuc2Zvcm0odHJhaW5fdHJhbnNmb3JtX2JhdGNoKSUwQWNwcGU1JTVCJTIydmFsaWRhdGlvbiUyMiU1RCUyMCUzRCUyMGNwcGU1JTVCJTIydmFsaWRhdGlvbiUyMiU1RC53aXRoX3RyYW5zZm9ybSh2YWxpZGF0aW9uX3RyYW5zZm9ybV9iYXRjaCklMEFjcHBlNSU1QiUyMnRlc3QlMjIlNUQlMjAlM0QlMjBjcHBlNSU1QiUyMnRlc3QlMjIlNUQud2l0aF90cmFuc2Zvcm0odmFsaWRhdGlvbl90cmFuc2Zvcm1fYmF0Y2gpJTBBJTBBY3BwZTUlNUIlMjJ0cmFpbiUyMiU1RCU1QjE1JTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> partial

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Make transform functions for batch and apply for dataset splits</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>train_transform_batch = partial(
<span class="hljs-meta">... </span>    augment_and_transform_batch, transform=train_augment_and_transform, image_processor=image_processor
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>validation_transform_batch = partial(
<span class="hljs-meta">... </span>    augment_and_transform_batch, transform=validation_transform, image_processor=image_processor
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>cppe5[<span class="hljs-string">&quot;train&quot;</span>] = cppe5[<span class="hljs-string">&quot;train&quot;</span>].with_transform(train_transform_batch)
<span class="hljs-meta">&gt;&gt;&gt; </span>cppe5[<span class="hljs-string">&quot;validation&quot;</span>] = cppe5[<span class="hljs-string">&quot;validation&quot;</span>].with_transform(validation_transform_batch)
<span class="hljs-meta">&gt;&gt;&gt; </span>cppe5[<span class="hljs-string">&quot;test&quot;</span>] = cppe5[<span class="hljs-string">&quot;test&quot;</span>].with_transform(validation_transform_batch)

<span class="hljs-meta">&gt;&gt;&gt; </span>cppe5[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">15</span>]
{<span class="hljs-string">&#x27;pixel_values&#x27;</span>: tensor([[[ <span class="hljs-number">1.9235</span>,  <span class="hljs-number">1.9407</span>,  <span class="hljs-number">1.9749</span>,  ..., -<span class="hljs-number">0.7822</span>, -<span class="hljs-number">0.7479</span>, -<span class="hljs-number">0.6965</span>],
          [ <span class="hljs-number">1.9578</span>,  <span class="hljs-number">1.9749</span>,  <span class="hljs-number">1.9920</span>,  ..., -<span class="hljs-number">0.7993</span>, -<span class="hljs-number">0.7650</span>, -<span class="hljs-number">0.7308</span>],
          [ <span class="hljs-number">2.0092</span>,  <span class="hljs-number">2.0092</span>,  <span class="hljs-number">2.0263</span>,  ..., -<span class="hljs-number">0.8507</span>, -<span class="hljs-number">0.8164</span>, -<span class="hljs-number">0.7822</span>],
          ...,
          [ <span class="hljs-number">0.0741</span>,  <span class="hljs-number">0.0741</span>,  <span class="hljs-number">0.0741</span>,  ...,  <span class="hljs-number">0.0741</span>,  <span class="hljs-number">0.0741</span>,  <span class="hljs-number">0.0741</span>],
          [ <span class="hljs-number">0.0741</span>,  <span class="hljs-number">0.0741</span>,  <span class="hljs-number">0.0741</span>,  ...,  <span class="hljs-number">0.0741</span>,  <span class="hljs-number">0.0741</span>,  <span class="hljs-number">0.0741</span>],
          [ <span class="hljs-number">0.0741</span>,  <span class="hljs-number">0.0741</span>,  <span class="hljs-number">0.0741</span>,  ...,  <span class="hljs-number">0.0741</span>,  <span class="hljs-number">0.0741</span>,  <span class="hljs-number">0.0741</span>]],
  
          [[ <span class="hljs-number">1.6232</span>,  <span class="hljs-number">1.6408</span>,  <span class="hljs-number">1.6583</span>,  ...,  <span class="hljs-number">0.8704</span>,  <span class="hljs-number">1.0105</span>,  <span class="hljs-number">1.1331</span>],
          [ <span class="hljs-number">1.6408</span>,  <span class="hljs-number">1.6583</span>,  <span class="hljs-number">1.6758</span>,  ...,  <span class="hljs-number">0.8529</span>,  <span class="hljs-number">0.9930</span>,  <span class="hljs-number">1.0980</span>],
          [ <span class="hljs-number">1.6933</span>,  <span class="hljs-number">1.6933</span>,  <span class="hljs-number">1.7108</span>,  ...,  <span class="hljs-number">0.8179</span>,  <span class="hljs-number">0.9580</span>,  <span class="hljs-number">1.0630</span>],
          ...,
          [ <span class="hljs-number">0.2052</span>,  <span class="hljs-number">0.2052</span>,  <span class="hljs-number">0.2052</span>,  ...,  <span class="hljs-number">0.2052</span>,  <span class="hljs-number">0.2052</span>,  <span class="hljs-number">0.2052</span>],
          [ <span class="hljs-number">0.2052</span>,  <span class="hljs-number">0.2052</span>,  <span class="hljs-number">0.2052</span>,  ...,  <span class="hljs-number">0.2052</span>,  <span class="hljs-number">0.2052</span>,  <span class="hljs-number">0.2052</span>],
          [ <span class="hljs-number">0.2052</span>,  <span class="hljs-number">0.2052</span>,  <span class="hljs-number">0.2052</span>,  ...,  <span class="hljs-number">0.2052</span>,  <span class="hljs-number">0.2052</span>,  <span class="hljs-number">0.2052</span>]],
  
          [[ <span class="hljs-number">1.8905</span>,  <span class="hljs-number">1.9080</span>,  <span class="hljs-number">1.9428</span>,  ..., -<span class="hljs-number">0.1487</span>, -<span class="hljs-number">0.0964</span>, -<span class="hljs-number">0.0615</span>],
          [ <span class="hljs-number">1.9254</span>,  <span class="hljs-number">1.9428</span>,  <span class="hljs-number">1.9603</span>,  ..., -<span class="hljs-number">0.1661</span>, -<span class="hljs-number">0.1138</span>, -<span class="hljs-number">0.0790</span>],
          [ <span class="hljs-number">1.9777</span>,  <span class="hljs-number">1.9777</span>,  <span class="hljs-number">1.9951</span>,  ..., -<span class="hljs-number">0.2010</span>, -<span class="hljs-number">0.1138</span>, -<span class="hljs-number">0.0790</span>],
          ...,
          [ <span class="hljs-number">0.4265</span>,  <span class="hljs-number">0.4265</span>,  <span class="hljs-number">0.4265</span>,  ...,  <span class="hljs-number">0.4265</span>,  <span class="hljs-number">0.4265</span>,  <span class="hljs-number">0.4265</span>],
          [ <span class="hljs-number">0.4265</span>,  <span class="hljs-number">0.4265</span>,  <span class="hljs-number">0.4265</span>,  ...,  <span class="hljs-number">0.4265</span>,  <span class="hljs-number">0.4265</span>,  <span class="hljs-number">0.4265</span>],
          [ <span class="hljs-number">0.4265</span>,  <span class="hljs-number">0.4265</span>,  <span class="hljs-number">0.4265</span>,  ...,  <span class="hljs-number">0.4265</span>,  <span class="hljs-number">0.4265</span>,  <span class="hljs-number">0.4265</span>]]]),
  <span class="hljs-string">&#x27;labels&#x27;</span>: {<span class="hljs-string">&#x27;image_id&#x27;</span>: tensor([<span class="hljs-number">688</span>]), <span class="hljs-string">&#x27;class_labels&#x27;</span>: tensor([<span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">2</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>]), <span class="hljs-string">&#x27;boxes&#x27;</span>: tensor([[<span class="hljs-number">0.4700</span>, <span class="hljs-number">0.1933</span>, <span class="hljs-number">0.1467</span>, <span class="hljs-number">0.0767</span>],
          [<span class="hljs-number">0.4858</span>, <span class="hljs-number">0.2600</span>, <span class="hljs-number">0.1150</span>, <span class="hljs-number">0.1000</span>],
          [<span class="hljs-number">0.4042</span>, <span class="hljs-number">0.4517</span>, <span class="hljs-number">0.1217</span>, <span class="hljs-number">0.1300</span>],
          [<span class="hljs-number">0.4242</span>, <span class="hljs-number">0.3217</span>, <span class="hljs-number">0.3617</span>, <span class="hljs-number">0.5567</span>],
          [<span class="hljs-number">0.6617</span>, <span class="hljs-number">0.4033</span>, <span class="hljs-number">0.5400</span>, <span class="hljs-number">0.4533</span>]]), <span class="hljs-string">&#x27;area&#x27;</span>: tensor([ <span class="hljs-number">4048.</span>,  <span class="hljs-number">4140.</span>,  <span class="hljs-number">5694.</span>, <span class="hljs-number">72478.</span>, <span class="hljs-number">88128.</span>]), <span class="hljs-string">&#x27;iscrowd&#x27;</span>: tensor([<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>]), <span class="hljs-string">&#x27;orig_size&#x27;</span>: tensor([<span class="hljs-number">480</span>, <span class="hljs-number">480</span>])}}`,wrap:!1}}),rs=new j({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFkZWYlMjBjb2xsYXRlX2ZuKGJhdGNoKSUzQSUwQSUyMCUyMCUyMCUyMGRhdGElMjAlM0QlMjAlN0IlN0QlMEElMjAlMjAlMjAlMjBkYXRhJTVCJTIycGl4ZWxfdmFsdWVzJTIyJTVEJTIwJTNEJTIwdG9yY2guc3RhY2soJTVCeCU1QiUyMnBpeGVsX3ZhbHVlcyUyMiU1RCUyMGZvciUyMHglMjBpbiUyMGJhdGNoJTVEKSUwQSUyMCUyMCUyMCUyMGRhdGElNUIlMjJsYWJlbHMlMjIlNUQlMjAlM0QlMjAlNUJ4JTVCJTIybGFiZWxzJTIyJTVEJTIwZm9yJTIweCUyMGluJTIwYmF0Y2glNUQlMEElMjAlMjAlMjAlMjBpZiUyMCUyMnBpeGVsX21hc2slMjIlMjBpbiUyMGJhdGNoJTVCMCU1RCUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGRhdGElNUIlMjJwaXhlbF9tYXNrJTIyJTVEJTIwJTNEJTIwdG9yY2guc3RhY2soJTVCeCU1QiUyMnBpeGVsX21hc2slMjIlNUQlMjBmb3IlMjB4JTIwaW4lMjBiYXRjaCU1RCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBkYXRhJTBB",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">collate_fn</span>(<span class="hljs-params">batch</span>):
<span class="hljs-meta">... </span>    data = {}
<span class="hljs-meta">... </span>    data[<span class="hljs-string">&quot;pixel_values&quot;</span>] = torch.stack([x[<span class="hljs-string">&quot;pixel_values&quot;</span>] <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> batch])
<span class="hljs-meta">... </span>    data[<span class="hljs-string">&quot;labels&quot;</span>] = [x[<span class="hljs-string">&quot;labels&quot;</span>] <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> batch]
<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> <span class="hljs-string">&quot;pixel_mask&quot;</span> <span class="hljs-keyword">in</span> batch[<span class="hljs-number">0</span>]:
<span class="hljs-meta">... </span>        data[<span class="hljs-string">&quot;pixel_mask&quot;</span>] = torch.stack([x[<span class="hljs-string">&quot;pixel_mask&quot;</span>] <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> batch])
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> data
`,wrap:!1}}),hs=new Ls({props:{title:"Preparing function to compute mAP",local:"preparing-function-to-compute-map",headingTag:"h2"}}),Js=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5pbWFnZV90cmFuc2Zvcm1zJTIwaW1wb3J0JTIwY2VudGVyX3RvX2Nvcm5lcnNfZm9ybWF0JTBBJTBBZGVmJTIwY29udmVydF9iYm94X3lvbG9fdG9fcGFzY2FsKGJveGVzJTJDJTIwaW1hZ2Vfc2l6ZSklM0ElMEElMjAlMjAlMjAlMjAlMjIlMjIlMjIlMEElMjAlMjAlMjAlMjBDb252ZXJ0JTIwYm91bmRpbmclMjBib3hlcyUyMGZyb20lMjBZT0xPJTIwZm9ybWF0JTIwKHhfY2VudGVyJTJDJTIweV9jZW50ZXIlMkMlMjB3aWR0aCUyQyUyMGhlaWdodCklMjBpbiUyMHJhbmdlJTIwJTVCMCUyQyUyMDElNUQlMEElMjAlMjAlMjAlMjB0byUyMFBhc2NhbCUyMFZPQyUyMGZvcm1hdCUyMCh4X21pbiUyQyUyMHlfbWluJTJDJTIweF9tYXglMkMlMjB5X21heCklMjBpbiUyMGFic29sdXRlJTIwY29vcmRpbmF0ZXMuJTBBJTBBJTIwJTIwJTIwJTIwQXJncyUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGJveGVzJTIwKHRvcmNoLlRlbnNvciklM0ElMjBCb3VuZGluZyUyMGJveGVzJTIwaW4lMjBZT0xPJTIwZm9ybWF0JTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW1hZ2Vfc2l6ZSUyMChUdXBsZSU1QmludCUyQyUyMGludCU1RCklM0ElMjBJbWFnZSUyMHNpemUlMjBpbiUyMGZvcm1hdCUyMChoZWlnaHQlMkMlMjB3aWR0aCklMEElMEElMjAlMjAlMjAlMjBSZXR1cm5zJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdG9yY2guVGVuc29yJTNBJTIwQm91bmRpbmclMjBib3hlcyUyMGluJTIwUGFzY2FsJTIwVk9DJTIwZm9ybWF0JTIwKHhfbWluJTJDJTIweV9taW4lMkMlMjB4X21heCUyQyUyMHlfbWF4KSUwQSUyMCUyMCUyMCUyMCUyMiUyMiUyMiUwQSUyMCUyMCUyMCUyMCUyMyUyMGNvbnZlcnQlMjBjZW50ZXIlMjB0byUyMGNvcm5lcnMlMjBmb3JtYXQlMEElMjAlMjAlMjAlMjBib3hlcyUyMCUzRCUyMGNlbnRlcl90b19jb3JuZXJzX2Zvcm1hdChib3hlcyklMEElMEElMjAlMjAlMjAlMjAlMjMlMjBjb252ZXJ0JTIwdG8lMjBhYnNvbHV0ZSUyMGNvb3JkaW5hdGVzJTBBJTIwJTIwJTIwJTIwaGVpZ2h0JTJDJTIwd2lkdGglMjAlM0QlMjBpbWFnZV9zaXplJTBBJTIwJTIwJTIwJTIwYm94ZXMlMjAlM0QlMjBib3hlcyUyMColMjB0b3JjaC50ZW5zb3IoJTVCJTVCd2lkdGglMkMlMjBoZWlnaHQlMkMlMjB3aWR0aCUyQyUyMGhlaWdodCU1RCU1RCklMEElMEElMjAlMjAlMjAlMjByZXR1cm4lMjBib3hlcw==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers.image_transforms <span class="hljs-keyword">import</span> center_to_corners_format

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">convert_bbox_yolo_to_pascal</span>(<span class="hljs-params">boxes, image_size</span>):
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;&quot;&quot;
<span class="hljs-meta">... </span>    Convert bounding boxes from YOLO format (x_center, y_center, width, height) in range [0, 1]
<span class="hljs-meta">... </span>    to Pascal VOC format (x_min, y_min, x_max, y_max) in absolute coordinates.

<span class="hljs-meta">... </span>    Args:
<span class="hljs-meta">... </span>        boxes (torch.Tensor): Bounding boxes in YOLO format
<span class="hljs-meta">... </span>        image_size (Tuple[int, int]): Image size in format (height, width)

<span class="hljs-meta">... </span>    Returns:
<span class="hljs-meta">... </span>        torch.Tensor: Bounding boxes in Pascal VOC format (x_min, y_min, x_max, y_max)
<span class="hljs-meta">... </span>    &quot;&quot;&quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-comment"># convert center to corners format</span>
<span class="hljs-meta">... </span>    boxes = center_to_corners_format(boxes)

<span class="hljs-meta">... </span>    <span class="hljs-comment"># convert to absolute coordinates</span>
<span class="hljs-meta">... </span>    height, width = image_size
<span class="hljs-meta">... </span>    boxes = boxes * torch.tensor([[width, height, width, height]])

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> boxes`,wrap:!1}}),Ts=new j({props:{code:" ",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> dataclass
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> torchmetrics.detection.mean_ap <span class="hljs-keyword">import</span> MeanAveragePrecision


<span class="hljs-meta">&gt;&gt;&gt; </span>@dataclass
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">class</span> <span class="hljs-title class_">ModelOutput</span>:
<span class="hljs-meta">... </span>    logits: torch.Tensor
<span class="hljs-meta">... </span>    pred_boxes: torch.Tensor


<span class="hljs-meta">&gt;&gt;&gt; </span>@torch.no_grad()
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">evaluation_results, image_processor, threshold=<span class="hljs-number">0.0</span>, id2label=<span class="hljs-literal">None</span></span>):
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;&quot;&quot;
<span class="hljs-meta">... </span>    Compute mean average mAP, mAR and their variants for the object detection task.

<span class="hljs-meta">... </span>    Args:
<span class="hljs-meta">... </span>        evaluation_results (EvalPrediction): Predictions and targets from evaluation.
<span class="hljs-meta">... </span>        threshold (float, optional): Threshold to filter predicted boxes by confidence. Defaults to 0.0.
<span class="hljs-meta">... </span>        id2label (Optional[dict], optional): Mapping from class id to class name. Defaults to None.

<span class="hljs-meta">... </span>    Returns:
<span class="hljs-meta">... </span>        Mapping[str, float]: Metrics in a form of dictionary {&lt;metric_name&gt;: &lt;metric_value&gt;}
<span class="hljs-meta">... </span>    &quot;&quot;&quot;</span>

<span class="hljs-meta">... </span>    predictions, targets = evaluation_results.predictions, evaluation_results.label_ids

<span class="hljs-meta">... </span>    <span class="hljs-comment"># For metric computation we need to provide:</span>
<span class="hljs-meta">... </span>    <span class="hljs-comment">#  - targets in a form of list of dictionaries with keys &quot;boxes&quot;, &quot;labels&quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-comment">#  - predictions in a form of list of dictionaries with keys &quot;boxes&quot;, &quot;scores&quot;, &quot;labels&quot;</span>

<span class="hljs-meta">... </span>    image_sizes = []
<span class="hljs-meta">... </span>    post_processed_targets = []
<span class="hljs-meta">... </span>    post_processed_predictions = []

<span class="hljs-meta">... </span>    <span class="hljs-comment"># Collect targets in the required format for metric computation</span>
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> targets:
<span class="hljs-meta">... </span>        <span class="hljs-comment"># collect image sizes, we will need them for predictions post processing</span>
<span class="hljs-meta">... </span>        batch_image_sizes = torch.tensor(np.array([x[<span class="hljs-string">&quot;orig_size&quot;</span>] <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> batch]))
<span class="hljs-meta">... </span>        image_sizes.append(batch_image_sizes)
<span class="hljs-meta">... </span>        <span class="hljs-comment"># collect targets in the required format for metric computation</span>
<span class="hljs-meta">... </span>        <span class="hljs-comment"># boxes were converted to YOLO format needed for model training</span>
<span class="hljs-meta">... </span>        <span class="hljs-comment"># here we will convert them to Pascal VOC format (x_min, y_min, x_max, y_max)</span>
<span class="hljs-meta">... </span>        <span class="hljs-keyword">for</span> image_target <span class="hljs-keyword">in</span> batch:
<span class="hljs-meta">... </span>            boxes = torch.tensor(image_target[<span class="hljs-string">&quot;boxes&quot;</span>])
<span class="hljs-meta">... </span>            boxes = convert_bbox_yolo_to_pascal(boxes, image_target[<span class="hljs-string">&quot;orig_size&quot;</span>])
<span class="hljs-meta">... </span>            labels = torch.tensor(image_target[<span class="hljs-string">&quot;class_labels&quot;</span>])
<span class="hljs-meta">... </span>            post_processed_targets.append({<span class="hljs-string">&quot;boxes&quot;</span>: boxes, <span class="hljs-string">&quot;labels&quot;</span>: labels})

<span class="hljs-meta">... </span>    <span class="hljs-comment"># Collect predictions in the required format for metric computation,</span>
<span class="hljs-meta">... </span>    <span class="hljs-comment"># model produce boxes in YOLO format, then image_processor convert them to Pascal VOC format</span>
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> batch, target_sizes <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(predictions, image_sizes):
<span class="hljs-meta">... </span>        batch_logits, batch_boxes = batch[<span class="hljs-number">1</span>], batch[<span class="hljs-number">2</span>]
<span class="hljs-meta">... </span>        output = ModelOutput(logits=torch.tensor(batch_logits), pred_boxes=torch.tensor(batch_boxes))
<span class="hljs-meta">... </span>        post_processed_output = image_processor.post_process_object_detection(
<span class="hljs-meta">... </span>            output, threshold=threshold, target_sizes=target_sizes
<span class="hljs-meta">... </span>        )
<span class="hljs-meta">... </span>        post_processed_predictions.extend(post_processed_output)

<span class="hljs-meta">... </span>    <span class="hljs-comment"># Compute metrics</span>
<span class="hljs-meta">... </span>    metric = MeanAveragePrecision(box_format=<span class="hljs-string">&quot;xyxy&quot;</span>, class_metrics=<span class="hljs-literal">True</span>)
<span class="hljs-meta">... </span>    metric.update(post_processed_predictions, post_processed_targets)
<span class="hljs-meta">... </span>    metrics = metric.compute()

<span class="hljs-meta">... </span>    <span class="hljs-comment"># Replace list of per class metrics with separate metric for each class</span>
<span class="hljs-meta">... </span>    classes = metrics.pop(<span class="hljs-string">&quot;classes&quot;</span>)
<span class="hljs-meta">... </span>    map_per_class = metrics.pop(<span class="hljs-string">&quot;map_per_class&quot;</span>)
<span class="hljs-meta">... </span>    mar_100_per_class = metrics.pop(<span class="hljs-string">&quot;mar_100_per_class&quot;</span>)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> class_id, class_map, class_mar <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(classes, map_per_class, mar_100_per_class):
<span class="hljs-meta">... </span>        class_name = id2label[class_id.item()] <span class="hljs-keyword">if</span> id2label <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span> <span class="hljs-keyword">else</span> class_id.item()
<span class="hljs-meta">... </span>        metrics[<span class="hljs-string">f&quot;map_<span class="hljs-subst">{class_name}</span>&quot;</span>] = class_map
<span class="hljs-meta">... </span>        metrics[<span class="hljs-string">f&quot;mar_100_<span class="hljs-subst">{class_name}</span>&quot;</span>] = class_mar

<span class="hljs-meta">... </span>    metrics = {k: <span class="hljs-built_in">round</span>(v.item(), <span class="hljs-number">4</span>) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> metrics.items()}

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> metrics


<span class="hljs-meta">&gt;&gt;&gt; </span>eval_compute_metrics_fn = partial(
<span class="hljs-meta">... </span>    compute_metrics, image_processor=image_processor, id2label=id2label, threshold=<span class="hljs-number">0.0</span>
<span class="hljs-meta">... </span>)`,wrap:!1}}),us=new Ls({props:{title:"Training the detection model",local:"training-the-detection-model",headingTag:"h2"}}),Cs=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvck9iamVjdERldGVjdGlvbiUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yT2JqZWN0RGV0ZWN0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBNT0RFTF9OQU1FJTJDJTBBJTIwJTIwJTIwJTIwaWQybGFiZWwlM0RpZDJsYWJlbCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsMmlkJTNEbGFiZWwyaWQlMkMlMEElMjAlMjAlMjAlMjBpZ25vcmVfbWlzbWF0Y2hlZF9zaXplcyUzRFRydWUlMkMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForObjectDetection

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForObjectDetection.from_pretrained(
<span class="hljs-meta">... </span>    MODEL_NAME,
<span class="hljs-meta">... </span>    id2label=id2label,
<span class="hljs-meta">... </span>    label2id=label2id,
<span class="hljs-meta">... </span>    ignore_mismatched_sizes=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>)`,wrap:!1}}),Zs=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTBBJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0QlMjJkZXRyX2ZpbmV0dW5lZF9jcHBlNSUyMiUyQyUwQSUyMCUyMCUyMCUyMG51bV90cmFpbl9lcG9jaHMlM0QzMCUyQyUwQSUyMCUyMCUyMCUyMGZwMTYlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUzRDglMkMlMEElMjAlMjAlMjAlMjBkYXRhbG9hZGVyX251bV93b3JrZXJzJTNENCUyQyUwQSUyMCUyMCUyMCUyMGxlYXJuaW5nX3JhdGUlM0Q1ZS01JTJDJTBBJTIwJTIwJTIwJTIwbHJfc2NoZWR1bGVyX3R5cGUlM0QlMjJjb3NpbmUlMjIlMkMlMEElMjAlMjAlMjAlMjB3ZWlnaHRfZGVjYXklM0QxZS00JTJDJTBBJTIwJTIwJTIwJTIwbWF4X2dyYWRfbm9ybSUzRDAuMDElMkMlMEElMjAlMjAlMjAlMjBtZXRyaWNfZm9yX2Jlc3RfbW9kZWwlM0QlMjJldmFsX21hcCUyMiUyQyUwQSUyMCUyMCUyMCUyMGdyZWF0ZXJfaXNfYmV0dGVyJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGxvYWRfYmVzdF9tb2RlbF9hdF9lbmQlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwZXZhbF9zdHJhdGVneSUzRCUyMmVwb2NoJTIyJTJDJTBBJTIwJTIwJTIwJTIwc2F2ZV9zdHJhdGVneSUzRCUyMmVwb2NoJTIyJTJDJTBBJTIwJTIwJTIwJTIwc2F2ZV90b3RhbF9saW1pdCUzRDIlMkMlMEElMjAlMjAlMjAlMjByZW1vdmVfdW51c2VkX2NvbHVtbnMlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfZG9fY29uY2F0X2JhdGNoZXMlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMHB1c2hfdG9faHViJTNEVHJ1ZSUyQyUwQSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments

<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;detr_finetuned_cppe5&quot;</span>,
<span class="hljs-meta">... </span>    num_train_epochs=<span class="hljs-number">30</span>,
<span class="hljs-meta">... </span>    fp16=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>    per_device_train_batch_size=<span class="hljs-number">8</span>,
<span class="hljs-meta">... </span>    dataloader_num_workers=<span class="hljs-number">4</span>,
<span class="hljs-meta">... </span>    learning_rate=<span class="hljs-number">5e-5</span>,
<span class="hljs-meta">... </span>    lr_scheduler_type=<span class="hljs-string">&quot;cosine&quot;</span>,
<span class="hljs-meta">... </span>    weight_decay=<span class="hljs-number">1e-4</span>,
<span class="hljs-meta">... </span>    max_grad_norm=<span class="hljs-number">0.01</span>,
<span class="hljs-meta">... </span>    metric_for_best_model=<span class="hljs-string">&quot;eval_map&quot;</span>,
<span class="hljs-meta">... </span>    greater_is_better=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    load_best_model_at_end=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    eval_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
<span class="hljs-meta">... </span>    save_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
<span class="hljs-meta">... </span>    save_total_limit=<span class="hljs-number">2</span>,
<span class="hljs-meta">... </span>    remove_unused_columns=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>    eval_do_concat_batches=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>    push_to_hub=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>)`,wrap:!1}}),Ws=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXIlMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRHRyYWluaW5nX2FyZ3MlMkMlMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTNEY3BwZTUlNUIlMjJ0cmFpbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfZGF0YXNldCUzRGNwcGU1JTVCJTIydmFsaWRhdGlvbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRGltYWdlX3Byb2Nlc3NvciUyQyUwQSUyMCUyMCUyMCUyMGRhdGFfY29sbGF0b3IlM0Rjb2xsYXRlX2ZuJTJDJTBBJTIwJTIwJTIwJTIwY29tcHV0ZV9tZXRyaWNzJTNEZXZhbF9jb21wdXRlX21ldHJpY3NfZm4lMkMlMEEpJTBBJTBBdHJhaW5lci50cmFpbigp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer = Trainer(
<span class="hljs-meta">... </span>    model=model,
<span class="hljs-meta">... </span>    args=training_args,
<span class="hljs-meta">... </span>    train_dataset=cppe5[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    eval_dataset=cppe5[<span class="hljs-string">&quot;validation&quot;</span>],
<span class="hljs-meta">... </span>    tokenizer=image_processor,
<span class="hljs-meta">... </span>    data_collator=collate_fn,
<span class="hljs-meta">... </span>    compute_metrics=eval_compute_metrics_fn,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()`,wrap:!1}}),Qs=new j({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()',wrap:!1}}),ks=new Ls({props:{title:"Evaluate",local:"evaluate",headingTag:"h2"}}),Ys=new j({props:{code:"ZnJvbSUyMHBwcmludCUyMGltcG9ydCUyMHBwcmludCUwQSUwQW1ldHJpY3MlMjAlM0QlMjB0cmFpbmVyLmV2YWx1YXRlKGV2YWxfZGF0YXNldCUzRGNwcGU1JTVCJTIydGVzdCUyMiU1RCUyQyUyMG1ldHJpY19rZXlfcHJlZml4JTNEJTIydGVzdCUyMiklMEFwcHJpbnQobWV0cmljcyk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> pprint <span class="hljs-keyword">import</span> pprint

<span class="hljs-meta">&gt;&gt;&gt; </span>metrics = trainer.evaluate(eval_dataset=cppe5[<span class="hljs-string">&quot;test&quot;</span>], metric_key_prefix=<span class="hljs-string">&quot;test&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>pprint(metrics)
{<span class="hljs-string">&#x27;epoch&#x27;</span>: <span class="hljs-number">30.0</span>,
  <span class="hljs-string">&#x27;test_loss&#x27;</span>: <span class="hljs-number">1.0877351760864258</span>,
  <span class="hljs-string">&#x27;test_map&#x27;</span>: <span class="hljs-number">0.4116</span>,
  <span class="hljs-string">&#x27;test_map_50&#x27;</span>: <span class="hljs-number">0.741</span>,
  <span class="hljs-string">&#x27;test_map_75&#x27;</span>: <span class="hljs-number">0.3663</span>,
  <span class="hljs-string">&#x27;test_map_Coverall&#x27;</span>: <span class="hljs-number">0.5937</span>,
  <span class="hljs-string">&#x27;test_map_Face_Shield&#x27;</span>: <span class="hljs-number">0.5863</span>,
  <span class="hljs-string">&#x27;test_map_Gloves&#x27;</span>: <span class="hljs-number">0.3416</span>,
  <span class="hljs-string">&#x27;test_map_Goggles&#x27;</span>: <span class="hljs-number">0.1468</span>,
  <span class="hljs-string">&#x27;test_map_Mask&#x27;</span>: <span class="hljs-number">0.3894</span>,
  <span class="hljs-string">&#x27;test_map_large&#x27;</span>: <span class="hljs-number">0.5637</span>,
  <span class="hljs-string">&#x27;test_map_medium&#x27;</span>: <span class="hljs-number">0.3257</span>,
  <span class="hljs-string">&#x27;test_map_small&#x27;</span>: <span class="hljs-number">0.3589</span>,
  <span class="hljs-string">&#x27;test_mar_1&#x27;</span>: <span class="hljs-number">0.323</span>,
  <span class="hljs-string">&#x27;test_mar_10&#x27;</span>: <span class="hljs-number">0.5237</span>,
  <span class="hljs-string">&#x27;test_mar_100&#x27;</span>: <span class="hljs-number">0.5587</span>,
  <span class="hljs-string">&#x27;test_mar_100_Coverall&#x27;</span>: <span class="hljs-number">0.6756</span>,
  <span class="hljs-string">&#x27;test_mar_100_Face_Shield&#x27;</span>: <span class="hljs-number">0.7294</span>,
  <span class="hljs-string">&#x27;test_mar_100_Gloves&#x27;</span>: <span class="hljs-number">0.4721</span>,
  <span class="hljs-string">&#x27;test_mar_100_Goggles&#x27;</span>: <span class="hljs-number">0.4125</span>,
  <span class="hljs-string">&#x27;test_mar_100_Mask&#x27;</span>: <span class="hljs-number">0.5038</span>,
  <span class="hljs-string">&#x27;test_mar_large&#x27;</span>: <span class="hljs-number">0.7283</span>,
  <span class="hljs-string">&#x27;test_mar_medium&#x27;</span>: <span class="hljs-number">0.4901</span>,
  <span class="hljs-string">&#x27;test_mar_small&#x27;</span>: <span class="hljs-number">0.4469</span>,
  <span class="hljs-string">&#x27;test_runtime&#x27;</span>: <span class="hljs-number">1.6526</span>,
  <span class="hljs-string">&#x27;test_samples_per_second&#x27;</span>: <span class="hljs-number">17.548</span>,
  <span class="hljs-string">&#x27;test_steps_per_second&#x27;</span>: <span class="hljs-number">2.42</span>}`,wrap:!1}}),Ns=new Ls({props:{title:"Inference",local:"inference",headingTag:"h2"}}),Es=new j({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjByZXF1ZXN0cyUwQSUwQWZyb20lMjBQSUwlMjBpbXBvcnQlMjBJbWFnZSUyQyUyMEltYWdlRHJhdyUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBBdXRvSW1hZ2VQcm9jZXNzb3IlMkMlMjBBdXRvTW9kZWxGb3JPYmplY3REZXRlY3Rpb24lMEElMEF1cmwlMjAlM0QlMjAlMjJodHRwcyUzQSUyRiUyRmltYWdlcy5wZXhlbHMuY29tJTJGcGhvdG9zJTJGODQxMzI5OSUyRnBleGVscy1waG90by04NDEzMjk5LmpwZWclM0ZhdXRvJTNEY29tcHJlc3MlMjZjcyUzRHRpbnlzcmdiJTI2dyUzRDYzMCUyNmglM0QzNzUlMjZkcHIlM0QyJTIyJTBBaW1hZ2UlMjAlM0QlMjBJbWFnZS5vcGVuKHJlcXVlc3RzLmdldCh1cmwlMkMlMjBzdHJlYW0lM0RUcnVlKS5yYXcp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image, ImageDraw
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, AutoModelForObjectDetection

<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;https://images.pexels.com/photos/8413299/pexels-photo-8413299.jpeg?auto=compress&amp;cs=tinysrgb&amp;w=630&amp;h=375&amp;dpr=2&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)`,wrap:!1}}),Hs=new j({props:{code:"ZGV2aWNlJTIwJTNEJTIwJTIyY3VkYSUyMiUwQW1vZGVsX3JlcG8lMjAlM0QlMjAlMjJxdWJ2ZWwtaGYlMkZkZXRyX2ZpbmV0dW5lZF9jcHBlNSUyMiUwQSUwQWltYWdlX3Byb2Nlc3NvciUyMCUzRCUyMEF1dG9JbWFnZVByb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQobW9kZWxfcmVwbyklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvck9iamVjdERldGVjdGlvbi5mcm9tX3ByZXRyYWluZWQobW9kZWxfcmVwbyklMEFtb2RlbCUyMCUzRCUyMG1vZGVsLnRvKGRldmljZSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>device = <span class="hljs-string">&quot;cuda&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model_repo = <span class="hljs-string">&quot;qubvel-hf/detr_finetuned_cppe5&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(model_repo)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForObjectDetection.from_pretrained(model_repo)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = model.to(device)`,wrap:!1}}),Ss=new j({props:{code:"JTBBd2l0aCUyMHRvcmNoLm5vX2dyYWQoKSUzQSUwQSUyMCUyMCUyMCUyMGlucHV0cyUyMCUzRCUyMGltYWdlX3Byb2Nlc3NvcihpbWFnZXMlM0QlNUJpbWFnZSU1RCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBJTIwJTIwJTIwJTIwb3V0cHV0cyUyMCUzRCUyMG1vZGVsKCoqaW5wdXRzLnRvKGRldmljZSkpJTBBJTIwJTIwJTIwJTIwdGFyZ2V0X3NpemVzJTIwJTNEJTIwdG9yY2gudGVuc29yKCU1QiU1QmltYWdlLnNpemUlNUIxJTVEJTJDJTIwaW1hZ2Uuc2l6ZSU1QjAlNUQlNUQlNUQpJTBBJTIwJTIwJTIwJTIwcmVzdWx0cyUyMCUzRCUyMGltYWdlX3Byb2Nlc3Nvci5wb3N0X3Byb2Nlc3Nfb2JqZWN0X2RldGVjdGlvbihvdXRwdXRzJTJDJTIwdGhyZXNob2xkJTNEMC4zJTJDJTIwdGFyZ2V0X3NpemVzJTNEdGFyZ2V0X3NpemVzKSU1QjAlNUQlMEElMEFmb3IlMjBzY29yZSUyQyUyMGxhYmVsJTJDJTIwYm94JTIwaW4lMjB6aXAocmVzdWx0cyU1QiUyMnNjb3JlcyUyMiU1RCUyQyUyMHJlc3VsdHMlNUIlMjJsYWJlbHMlMjIlNUQlMkMlMjByZXN1bHRzJTVCJTIyYm94ZXMlMjIlNUQpJTNBJTBBJTIwJTIwJTIwJTIwYm94JTIwJTNEJTIwJTVCcm91bmQoaSUyQyUyMDIpJTIwZm9yJTIwaSUyMGluJTIwYm94LnRvbGlzdCgpJTVEJTBBJTIwJTIwJTIwJTIwcHJpbnQoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZiUyMkRldGVjdGVkJTIwJTdCbW9kZWwuY29uZmlnLmlkMmxhYmVsJTVCbGFiZWwuaXRlbSgpJTVEJTdEJTIwd2l0aCUyMGNvbmZpZGVuY2UlMjAlMjIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmJTIyJTdCcm91bmQoc2NvcmUuaXRlbSgpJTJDJTIwMyklN0QlMjBhdCUyMGxvY2F0aW9uJTIwJTdCYm94JTdEJTIyJTBBJTIwJTIwJTIwJTIwKQ==",highlighted:`
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    inputs = image_processor(images=[image], return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">... </span>    outputs = model(**inputs.to(device))
<span class="hljs-meta">... </span>    target_sizes = torch.tensor([[image.size[<span class="hljs-number">1</span>], image.size[<span class="hljs-number">0</span>]]])
<span class="hljs-meta">... </span>    results = image_processor.post_process_object_detection(outputs, threshold=<span class="hljs-number">0.3</span>, target_sizes=target_sizes)[<span class="hljs-number">0</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> score, label, box <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(results[<span class="hljs-string">&quot;scores&quot;</span>], results[<span class="hljs-string">&quot;labels&quot;</span>], results[<span class="hljs-string">&quot;boxes&quot;</span>]):
<span class="hljs-meta">... </span>    box = [<span class="hljs-built_in">round</span>(i, <span class="hljs-number">2</span>) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> box.tolist()]
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(
<span class="hljs-meta">... </span>        <span class="hljs-string">f&quot;Detected <span class="hljs-subst">{model.config.id2label[label.item()]}</span> with confidence &quot;</span>
<span class="hljs-meta">... </span>        <span class="hljs-string">f&quot;<span class="hljs-subst">{<span class="hljs-built_in">round</span>(score.item(), <span class="hljs-number">3</span>)}</span> at location <span class="hljs-subst">{box}</span>&quot;</span>
<span class="hljs-meta">... </span>    )
Detected Gloves <span class="hljs-keyword">with</span> confidence <span class="hljs-number">0.683</span> at location [<span class="hljs-number">244.58</span>, <span class="hljs-number">124.33</span>, <span class="hljs-number">300.35</span>, <span class="hljs-number">185.13</span>]
Detected Mask <span class="hljs-keyword">with</span> confidence <span class="hljs-number">0.517</span> at location [<span class="hljs-number">143.73</span>, <span class="hljs-number">64.58</span>, <span class="hljs-number">219.57</span>, <span class="hljs-number">125.89</span>]
Detected Gloves <span class="hljs-keyword">with</span> confidence <span class="hljs-number">0.425</span> at location [<span class="hljs-number">179.15</span>, <span class="hljs-number">155.57</span>, <span class="hljs-number">262.4</span>, <span class="hljs-number">226.35</span>]
Detected Coverall <span class="hljs-keyword">with</span> confidence <span class="hljs-number">0.407</span> at location [<span class="hljs-number">307.13</span>, -<span class="hljs-number">1.18</span>, <span class="hljs-number">477.82</span>, <span class="hljs-number">318.06</span>]
Detected Coverall <span class="hljs-keyword">with</span> confidence <span class="hljs-number">0.391</span> at location [<span class="hljs-number">68.61</span>, <span class="hljs-number">126.66</span>, <span class="hljs-number">309.03</span>, <span class="hljs-number">318.89</span>]`,wrap:!1}}),qs=new j({props:{code:"ZHJhdyUyMCUzRCUyMEltYWdlRHJhdy5EcmF3KGltYWdlKSUwQSUwQWZvciUyMHNjb3JlJTJDJTIwbGFiZWwlMkMlMjBib3glMjBpbiUyMHppcChyZXN1bHRzJTVCJTIyc2NvcmVzJTIyJTVEJTJDJTIwcmVzdWx0cyU1QiUyMmxhYmVscyUyMiU1RCUyQyUyMHJlc3VsdHMlNUIlMjJib3hlcyUyMiU1RCklM0ElMEElMjAlMjAlMjAlMjBib3glMjAlM0QlMjAlNUJyb3VuZChpJTJDJTIwMiklMjBmb3IlMjBpJTIwaW4lMjBib3gudG9saXN0KCklNUQlMEElMjAlMjAlMjAlMjB4JTJDJTIweSUyQyUyMHgyJTJDJTIweTIlMjAlM0QlMjB0dXBsZShib3gpJTBBJTIwJTIwJTIwJTIwZHJhdy5yZWN0YW5nbGUoKHglMkMlMjB5JTJDJTIweDIlMkMlMjB5MiklMkMlMjBvdXRsaW5lJTNEJTIycmVkJTIyJTJDJTIwd2lkdGglM0QxKSUwQSUyMCUyMCUyMCUyMGRyYXcudGV4dCgoeCUyQyUyMHkpJTJDJTIwbW9kZWwuY29uZmlnLmlkMmxhYmVsJTVCbGFiZWwuaXRlbSgpJTVEJTJDJTIwZmlsbCUzRCUyMndoaXRlJTIyKSUwQSUwQWltYWdl",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>draw = ImageDraw.Draw(image)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> score, label, box <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(results[<span class="hljs-string">&quot;scores&quot;</span>], results[<span class="hljs-string">&quot;labels&quot;</span>], results[<span class="hljs-string">&quot;boxes&quot;</span>]):
<span class="hljs-meta">... </span>    box = [<span class="hljs-built_in">round</span>(i, <span class="hljs-number">2</span>) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> box.tolist()]
<span class="hljs-meta">... </span>    x, y, x2, y2 = <span class="hljs-built_in">tuple</span>(box)
<span class="hljs-meta">... </span>    draw.rectangle((x, y, x2, y2), outline=<span class="hljs-string">&quot;red&quot;</span>, width=<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    draw.text((x, y), model.config.id2label[label.item()], fill=<span class="hljs-string">&quot;white&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>image`,wrap:!1}}),Ds=new Nl({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/tasks/object_detection.md"}}),{c(){y=p("meta"),w=e(),J=p("p"),Ps=e(),o(g.$$.fragment),tt=e(),o(I.$$.fragment),at=e(),C=p("p"),C.textContent=xa,lt=e(),f=p("p"),f.textContent=Wa,et=e(),B=p("ol"),B.innerHTML=va,nt=e(),o(T.$$.fragment),pt=e(),_=p("p"),_.textContent=Va,dt=e(),o(G.$$.fragment),ct=e(),Z=p("p"),Z.innerHTML=Ra,ot=e(),x=p("p"),x.textContent=Qa,it=e(),o(W.$$.fragment),Mt=e(),v=p("p"),v.innerHTML=ka,mt=e(),o(V.$$.fragment),rt=e(),o(R.$$.fragment),ht=e(),Q=p("p"),Q.innerHTML=Ya,jt=e(),k=p("p"),k.innerHTML=Aa,yt=e(),o(Y.$$.fragment),Jt=e(),A=p("p"),A.textContent=Na,bt=e(),N=p("p"),N.textContent=Xa,Tt=e(),o(X.$$.fragment),ut=e(),E=p("p"),E.textContent=Ea,Ut=e(),z=p("ul"),z.innerHTML=za,wt=e(),H=p("p"),H.innerHTML=Ha,gt=e(),F=p("p"),F.textContent=Fa,It=e(),o(S.$$.fragment),Ct=e(),u=p("div"),u.innerHTML=Sa,ft=e(),$=p("p"),$.innerHTML=$a,Bt=e(),q=p("p"),q.innerHTML=qa,_t=e(),o(D.$$.fragment),Gt=e(),L=p("p"),L.innerHTML=Da,Zt=e(),P=p("ul"),P.innerHTML=La,xt=e(),K=p("p"),K.textContent=Pa,Wt=e(),O=p("p"),O.textContent=Ka,vt=e(),o(ss.$$.fragment),Vt=e(),ts=p("p"),ts.innerHTML=Oa,Rt=e(),as=p("ul"),as.innerHTML=sl,Qt=e(),ls=p("p"),ls.innerHTML=tl,kt=e(),o(es.$$.fragment),Yt=e(),ns=p("p"),ns.innerHTML=al,At=e(),o(ps.$$.fragment),Nt=e(),ds=p("p"),ds.textContent=ll,Xt=e(),o(cs.$$.fragment),Et=e(),os=p("p"),os.innerHTML=el,zt=e(),is=p("p"),is.innerHTML=nl,Ht=e(),o(Ms.$$.fragment),Ft=e(),ms=p("p"),ms.innerHTML=pl,St=e(),o(rs.$$.fragment),$t=e(),o(hs.$$.fragment),qt=e(),js=p("p"),js.innerHTML=dl,Dt=e(),ys=p("p"),ys.innerHTML=cl,Lt=e(),o(Js.$$.fragment),Pt=e(),bs=p("p"),bs.innerHTML=ol,Kt=e(),o(Ts.$$.fragment),Ot=e(),o(us.$$.fragment),sa=e(),Us=p("p"),Us.textContent=il,ta=e(),ws=p("p"),ws.textContent=Ml,aa=e(),gs=p("ol"),gs.innerHTML=ml,la=e(),Is=p("p"),Is.innerHTML=rl,ea=e(),o(Cs.$$.fragment),na=e(),fs=p("p"),fs.innerHTML=hl,pa=e(),Bs=p("p"),Bs.textContent=jl,da=e(),_s=p("ul"),_s.innerHTML=yl,ca=e(),Gs=p("p"),Gs.innerHTML=Jl,oa=e(),o(Zs.$$.fragment),ia=e(),xs=p("p"),xs.innerHTML=bl,Ma=e(),o(Ws.$$.fragment),ma=e(),vs=p("div"),vs.innerHTML=Tl,ra=e(),b=p("table"),b.innerHTML=ul,Vs=p("p"),Vs.innerHTML=Ul,Rs=p("p"),Rs.innerHTML=wl,ha=e(),o(Qs.$$.fragment),ja=e(),o(ks.$$.fragment),ya=e(),o(Ys.$$.fragment),Ja=e(),As=p("p"),As.innerHTML=gl,ba=e(),o(Ns.$$.fragment),Ta=e(),Xs=p("p"),Xs.textContent=Il,ua=e(),o(Es.$$.fragment),Ua=e(),zs=p("p"),zs.textContent=Cl,wa=e(),o(Hs.$$.fragment),ga=e(),Fs=p("p"),Fs.textContent=fl,Ia=e(),o(Ss.$$.fragment),Ca=e(),$s=p("p"),$s.textContent=Bl,fa=e(),o(qs.$$.fragment),Ba=e(),U=p("div"),U.innerHTML=_l,_a=e(),o(Ds.$$.fragment),Ga=e(),Os=p("p"),this.h()},l(s){const t=Ql("svelte-u9bgzb",document.head);y=d(t,"META",{name:!0,content:!0}),t.forEach(a),w=n(s),J=d(s,"P",{}),Zl(J).forEach(a),Ps=n(s),i(g.$$.fragment,s),tt=n(s),i(I.$$.fragment,s),at=n(s),C=d(s,"P",{"data-svelte-h":!0}),c(C)!=="svelte-18pt6j0"&&(C.textContent=xa),lt=n(s),f=d(s,"P",{"data-svelte-h":!0}),c(f)!=="svelte-1xy9go1"&&(f.textContent=Wa),et=n(s),B=d(s,"OL",{"data-svelte-h":!0}),c(B)!=="svelte-6qcuz8"&&(B.innerHTML=va),nt=n(s),i(T.$$.fragment,s),pt=n(s),_=d(s,"P",{"data-svelte-h":!0}),c(_)!=="svelte-1c9nexd"&&(_.textContent=Va),dt=n(s),i(G.$$.fragment,s),ct=n(s),Z=d(s,"P",{"data-svelte-h":!0}),c(Z)!=="svelte-1hao5fk"&&(Z.innerHTML=Ra),ot=n(s),x=d(s,"P",{"data-svelte-h":!0}),c(x)!=="svelte-1oee7b1"&&(x.textContent=Qa),it=n(s),i(W.$$.fragment,s),Mt=n(s),v=d(s,"P",{"data-svelte-h":!0}),c(v)!=="svelte-ip202a"&&(v.innerHTML=ka),mt=n(s),i(V.$$.fragment,s),rt=n(s),i(R.$$.fragment,s),ht=n(s),Q=d(s,"P",{"data-svelte-h":!0}),c(Q)!=="svelte-9es7uf"&&(Q.innerHTML=Ya),jt=n(s),k=d(s,"P",{"data-svelte-h":!0}),c(k)!=="svelte-11vhiu"&&(k.innerHTML=Aa),yt=n(s),i(Y.$$.fragment,s),Jt=n(s),A=d(s,"P",{"data-svelte-h":!0}),c(A)!=="svelte-rvn8y2"&&(A.textContent=Na),bt=n(s),N=d(s,"P",{"data-svelte-h":!0}),c(N)!=="svelte-4bevpw"&&(N.textContent=Xa),Tt=n(s),i(X.$$.fragment,s),ut=n(s),E=d(s,"P",{"data-svelte-h":!0}),c(E)!=="svelte-m0t76z"&&(E.textContent=Ea),Ut=n(s),z=d(s,"UL",{"data-svelte-h":!0}),c(z)!=="svelte-1tn0avh"&&(z.innerHTML=za),wt=n(s),H=d(s,"P",{"data-svelte-h":!0}),c(H)!=="svelte-edp0uk"&&(H.innerHTML=Ha),gt=n(s),F=d(s,"P",{"data-svelte-h":!0}),c(F)!=="svelte-1o4zzv7"&&(F.textContent=Fa),It=n(s),i(S.$$.fragment,s),Ct=n(s),u=d(s,"DIV",{class:!0,"data-svelte-h":!0}),c(u)!=="svelte-7wscra"&&(u.innerHTML=Sa),ft=n(s),$=d(s,"P",{"data-svelte-h":!0}),c($)!=="svelte-s62j5i"&&($.innerHTML=$a),Bt=n(s),q=d(s,"P",{"data-svelte-h":!0}),c(q)!=="svelte-1p1sy04"&&(q.innerHTML=qa),_t=n(s),i(D.$$.fragment,s),Gt=n(s),L=d(s,"P",{"data-svelte-h":!0}),c(L)!=="svelte-yxrwup"&&(L.innerHTML=Da),Zt=n(s),P=d(s,"UL",{"data-svelte-h":!0}),c(P)!=="svelte-9xz2l6"&&(P.innerHTML=La),xt=n(s),K=d(s,"P",{"data-svelte-h":!0}),c(K)!=="svelte-1uiy3io"&&(K.textContent=Pa),Wt=n(s),O=d(s,"P",{"data-svelte-h":!0}),c(O)!=="svelte-1ipxopl"&&(O.textContent=Ka),vt=n(s),i(ss.$$.fragment,s),Vt=n(s),ts=d(s,"P",{"data-svelte-h":!0}),c(ts)!=="svelte-16qnm9y"&&(ts.innerHTML=Oa),Rt=n(s),as=d(s,"UL",{"data-svelte-h":!0}),c(as)!=="svelte-pqfhzt"&&(as.innerHTML=sl),Qt=n(s),ls=d(s,"P",{"data-svelte-h":!0}),c(ls)!=="svelte-1ekhp6u"&&(ls.innerHTML=tl),kt=n(s),i(es.$$.fragment,s),Yt=n(s),ns=d(s,"P",{"data-svelte-h":!0}),c(ns)!=="svelte-bsjzql"&&(ns.innerHTML=al),At=n(s),i(ps.$$.fragment,s),Nt=n(s),ds=d(s,"P",{"data-svelte-h":!0}),c(ds)!=="svelte-16yruro"&&(ds.textContent=ll),Xt=n(s),i(cs.$$.fragment,s),Et=n(s),os=d(s,"P",{"data-svelte-h":!0}),c(os)!=="svelte-gv4k4k"&&(os.innerHTML=el),zt=n(s),is=d(s,"P",{"data-svelte-h":!0}),c(is)!=="svelte-1o4lbgk"&&(is.innerHTML=nl),Ht=n(s),i(Ms.$$.fragment,s),Ft=n(s),ms=d(s,"P",{"data-svelte-h":!0}),c(ms)!=="svelte-1ghsv74"&&(ms.innerHTML=pl),St=n(s),i(rs.$$.fragment,s),$t=n(s),i(hs.$$.fragment,s),qt=n(s),js=d(s,"P",{"data-svelte-h":!0}),c(js)!=="svelte-xes93z"&&(js.innerHTML=dl),Dt=n(s),ys=d(s,"P",{"data-svelte-h":!0}),c(ys)!=="svelte-ceh07m"&&(ys.innerHTML=cl),Lt=n(s),i(Js.$$.fragment,s),Pt=n(s),bs=d(s,"P",{"data-svelte-h":!0}),c(bs)!=="svelte-izy56o"&&(bs.innerHTML=ol),Kt=n(s),i(Ts.$$.fragment,s),Ot=n(s),i(us.$$.fragment,s),sa=n(s),Us=d(s,"P",{"data-svelte-h":!0}),c(Us)!=="svelte-1970dhn"&&(Us.textContent=il),ta=n(s),ws=d(s,"P",{"data-svelte-h":!0}),c(ws)!=="svelte-qp7n2l"&&(ws.textContent=Ml),aa=n(s),gs=d(s,"OL",{"data-svelte-h":!0}),c(gs)!=="svelte-13hlg9x"&&(gs.innerHTML=ml),la=n(s),Is=d(s,"P",{"data-svelte-h":!0}),c(Is)!=="svelte-3tgt16"&&(Is.innerHTML=rl),ea=n(s),i(Cs.$$.fragment,s),na=n(s),fs=d(s,"P",{"data-svelte-h":!0}),c(fs)!=="svelte-axhj27"&&(fs.innerHTML=hl),pa=n(s),Bs=d(s,"P",{"data-svelte-h":!0}),c(Bs)!=="svelte-1z0bxll"&&(Bs.textContent=jl),da=n(s),_s=d(s,"UL",{"data-svelte-h":!0}),c(_s)!=="svelte-18syxls"&&(_s.innerHTML=yl),ca=n(s),Gs=d(s,"P",{"data-svelte-h":!0}),c(Gs)!=="svelte-m8o45s"&&(Gs.innerHTML=Jl),oa=n(s),i(Zs.$$.fragment,s),ia=n(s),xs=d(s,"P",{"data-svelte-h":!0}),c(xs)!=="svelte-11x86dl"&&(xs.innerHTML=bl),Ma=n(s),i(Ws.$$.fragment,s),ma=n(s),vs=d(s,"DIV",{"data-svelte-h":!0}),c(vs)!=="svelte-z5zay"&&(vs.innerHTML=Tl),ra=n(s),b=d(s,"TABLE",{border:!0,class:!0,"data-svelte-h":!0}),c(b)!=="svelte-186gcvq"&&(b.innerHTML=ul),Vs=d(s,"P",{"data-svelte-h":!0}),c(Vs)!=="svelte-b5f4e5"&&(Vs.innerHTML=Ul),Rs=d(s,"P",{"data-svelte-h":!0}),c(Rs)!=="svelte-1x0eij8"&&(Rs.innerHTML=wl),ha=n(s),i(Qs.$$.fragment,s),ja=n(s),i(ks.$$.fragment,s),ya=n(s),i(Ys.$$.fragment,s),Ja=n(s),As=d(s,"P",{"data-svelte-h":!0}),c(As)!=="svelte-1khrzgi"&&(As.innerHTML=gl),ba=n(s),i(Ns.$$.fragment,s),Ta=n(s),Xs=d(s,"P",{"data-svelte-h":!0}),c(Xs)!=="svelte-1awi77u"&&(Xs.textContent=Il),ua=n(s),i(Es.$$.fragment,s),Ua=n(s),zs=d(s,"P",{"data-svelte-h":!0}),c(zs)!=="svelte-f44t9b"&&(zs.textContent=Cl),wa=n(s),i(Hs.$$.fragment,s),ga=n(s),Fs=d(s,"P",{"data-svelte-h":!0}),c(Fs)!=="svelte-m3ccz3"&&(Fs.textContent=fl),Ia=n(s),i(Ss.$$.fragment,s),Ca=n(s),$s=d(s,"P",{"data-svelte-h":!0}),c($s)!=="svelte-7zeucu"&&($s.textContent=Bl),fa=n(s),i(qs.$$.fragment,s),Ba=n(s),U=d(s,"DIV",{class:!0,"data-svelte-h":!0}),c(U)!=="svelte-bozw7r"&&(U.innerHTML=_l),_a=n(s),i(Ds.$$.fragment,s),Ga=n(s),Os=d(s,"P",{}),Zl(Os).forEach(a),this.h()},h(){Ks(y,"name","hf:doc:metadata"),Ks(y,"content",zl),Ks(u,"class","flex justify-center"),Ks(b,"border","1"),Ks(b,"class","dataframe"),Ks(U,"class","flex justify-center")},m(s,t){kl(document.head,y),l(s,w,t),l(s,J,t),l(s,Ps,t),M(g,s,t),l(s,tt,t),M(I,s,t),l(s,at,t),l(s,C,t),l(s,lt,t),l(s,f,t),l(s,et,t),l(s,B,t),l(s,nt,t),M(T,s,t),l(s,pt,t),l(s,_,t),l(s,dt,t),M(G,s,t),l(s,ct,t),l(s,Z,t),l(s,ot,t),l(s,x,t),l(s,it,t),M(W,s,t),l(s,Mt,t),l(s,v,t),l(s,mt,t),M(V,s,t),l(s,rt,t),M(R,s,t),l(s,ht,t),l(s,Q,t),l(s,jt,t),l(s,k,t),l(s,yt,t),M(Y,s,t),l(s,Jt,t),l(s,A,t),l(s,bt,t),l(s,N,t),l(s,Tt,t),M(X,s,t),l(s,ut,t),l(s,E,t),l(s,Ut,t),l(s,z,t),l(s,wt,t),l(s,H,t),l(s,gt,t),l(s,F,t),l(s,It,t),M(S,s,t),l(s,Ct,t),l(s,u,t),l(s,ft,t),l(s,$,t),l(s,Bt,t),l(s,q,t),l(s,_t,t),M(D,s,t),l(s,Gt,t),l(s,L,t),l(s,Zt,t),l(s,P,t),l(s,xt,t),l(s,K,t),l(s,Wt,t),l(s,O,t),l(s,vt,t),M(ss,s,t),l(s,Vt,t),l(s,ts,t),l(s,Rt,t),l(s,as,t),l(s,Qt,t),l(s,ls,t),l(s,kt,t),M(es,s,t),l(s,Yt,t),l(s,ns,t),l(s,At,t),M(ps,s,t),l(s,Nt,t),l(s,ds,t),l(s,Xt,t),M(cs,s,t),l(s,Et,t),l(s,os,t),l(s,zt,t),l(s,is,t),l(s,Ht,t),M(Ms,s,t),l(s,Ft,t),l(s,ms,t),l(s,St,t),M(rs,s,t),l(s,$t,t),M(hs,s,t),l(s,qt,t),l(s,js,t),l(s,Dt,t),l(s,ys,t),l(s,Lt,t),M(Js,s,t),l(s,Pt,t),l(s,bs,t),l(s,Kt,t),M(Ts,s,t),l(s,Ot,t),M(us,s,t),l(s,sa,t),l(s,Us,t),l(s,ta,t),l(s,ws,t),l(s,aa,t),l(s,gs,t),l(s,la,t),l(s,Is,t),l(s,ea,t),M(Cs,s,t),l(s,na,t),l(s,fs,t),l(s,pa,t),l(s,Bs,t),l(s,da,t),l(s,_s,t),l(s,ca,t),l(s,Gs,t),l(s,oa,t),M(Zs,s,t),l(s,ia,t),l(s,xs,t),l(s,Ma,t),M(Ws,s,t),l(s,ma,t),l(s,vs,t),l(s,ra,t),l(s,b,t),l(s,Vs,t),l(s,Rs,t),l(s,ha,t),M(Qs,s,t),l(s,ja,t),M(ks,s,t),l(s,ya,t),M(Ys,s,t),l(s,Ja,t),l(s,As,t),l(s,ba,t),M(Ns,s,t),l(s,Ta,t),l(s,Xs,t),l(s,ua,t),M(Es,s,t),l(s,Ua,t),l(s,zs,t),l(s,wa,t),M(Hs,s,t),l(s,ga,t),l(s,Fs,t),l(s,Ia,t),M(Ss,s,t),l(s,Ca,t),l(s,$s,t),l(s,fa,t),M(qs,s,t),l(s,Ba,t),l(s,U,t),l(s,_a,t),M(Ds,s,t),l(s,Ga,t),l(s,Os,t),Za=!0},p(s,[t]){const Gl={};t&2&&(Gl.$$scope={dirty:t,ctx:s}),T.$set(Gl)},i(s){Za||(m(g.$$.fragment,s),m(I.$$.fragment,s),m(T.$$.fragment,s),m(G.$$.fragment,s),m(W.$$.fragment,s),m(V.$$.fragment,s),m(R.$$.fragment,s),m(Y.$$.fragment,s),m(X.$$.fragment,s),m(S.$$.fragment,s),m(D.$$.fragment,s),m(ss.$$.fragment,s),m(es.$$.fragment,s),m(ps.$$.fragment,s),m(cs.$$.fragment,s),m(Ms.$$.fragment,s),m(rs.$$.fragment,s),m(hs.$$.fragment,s),m(Js.$$.fragment,s),m(Ts.$$.fragment,s),m(us.$$.fragment,s),m(Cs.$$.fragment,s),m(Zs.$$.fragment,s),m(Ws.$$.fragment,s),m(Qs.$$.fragment,s),m(ks.$$.fragment,s),m(Ys.$$.fragment,s),m(Ns.$$.fragment,s),m(Es.$$.fragment,s),m(Hs.$$.fragment,s),m(Ss.$$.fragment,s),m(qs.$$.fragment,s),m(Ds.$$.fragment,s),Za=!0)},o(s){r(g.$$.fragment,s),r(I.$$.fragment,s),r(T.$$.fragment,s),r(G.$$.fragment,s),r(W.$$.fragment,s),r(V.$$.fragment,s),r(R.$$.fragment,s),r(Y.$$.fragment,s),r(X.$$.fragment,s),r(S.$$.fragment,s),r(D.$$.fragment,s),r(ss.$$.fragment,s),r(es.$$.fragment,s),r(ps.$$.fragment,s),r(cs.$$.fragment,s),r(Ms.$$.fragment,s),r(rs.$$.fragment,s),r(hs.$$.fragment,s),r(Js.$$.fragment,s),r(Ts.$$.fragment,s),r(us.$$.fragment,s),r(Cs.$$.fragment,s),r(Zs.$$.fragment,s),r(Ws.$$.fragment,s),r(Qs.$$.fragment,s),r(ks.$$.fragment,s),r(Ys.$$.fragment,s),r(Ns.$$.fragment,s),r(Es.$$.fragment,s),r(Hs.$$.fragment,s),r(Ss.$$.fragment,s),r(qs.$$.fragment,s),r(Ds.$$.fragment,s),Za=!1},d(s){s&&(a(w),a(J),a(Ps),a(tt),a(at),a(C),a(lt),a(f),a(et),a(B),a(nt),a(pt),a(_),a(dt),a(ct),a(Z),a(ot),a(x),a(it),a(Mt),a(v),a(mt),a(rt),a(ht),a(Q),a(jt),a(k),a(yt),a(Jt),a(A),a(bt),a(N),a(Tt),a(ut),a(E),a(Ut),a(z),a(wt),a(H),a(gt),a(F),a(It),a(Ct),a(u),a(ft),a($),a(Bt),a(q),a(_t),a(Gt),a(L),a(Zt),a(P),a(xt),a(K),a(Wt),a(O),a(vt),a(Vt),a(ts),a(Rt),a(as),a(Qt),a(ls),a(kt),a(Yt),a(ns),a(At),a(Nt),a(ds),a(Xt),a(Et),a(os),a(zt),a(is),a(Ht),a(Ft),a(ms),a(St),a($t),a(qt),a(js),a(Dt),a(ys),a(Lt),a(Pt),a(bs),a(Kt),a(Ot),a(sa),a(Us),a(ta),a(ws),a(aa),a(gs),a(la),a(Is),a(ea),a(na),a(fs),a(pa),a(Bs),a(da),a(_s),a(ca),a(Gs),a(oa),a(ia),a(xs),a(Ma),a(ma),a(vs),a(ra),a(b),a(Vs),a(Rs),a(ha),a(ja),a(ya),a(Ja),a(As),a(ba),a(Ta),a(Xs),a(ua),a(Ua),a(zs),a(wa),a(ga),a(Fs),a(Ia),a(Ca),a($s),a(fa),a(Ba),a(U),a(_a),a(Ga),a(Os)),a(y),h(g,s),h(I,s),h(T,s),h(G,s),h(W,s),h(V,s),h(R,s),h(Y,s),h(X,s),h(S,s),h(D,s),h(ss,s),h(es,s),h(ps,s),h(cs,s),h(Ms,s),h(rs,s),h(hs,s),h(Js,s),h(Ts,s),h(us,s),h(Cs,s),h(Zs,s),h(Ws,s),h(Qs,s),h(ks,s),h(Ys,s),h(Ns,s),h(Es,s),h(Hs,s),h(Ss,s),h(qs,s),h(Ds,s)}}}const zl='{"title":"Object detection","local":"object-detection","sections":[{"title":"Load the CPPE-5 dataset","local":"load-the-cppe-5-dataset","sections":[],"depth":2},{"title":"Preprocess the data","local":"preprocess-the-data","sections":[],"depth":2},{"title":"Preparing function to compute mAP","local":"preparing-function-to-compute-map","sections":[],"depth":2},{"title":"Training the detection model","local":"training-the-detection-model","sections":[],"depth":2},{"title":"Evaluate","local":"evaluate","sections":[],"depth":2},{"title":"Inference","local":"inference","sections":[],"depth":2}],"depth":1}';function Hl(st){return Wl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Pl extends Vl{constructor(y){super(),Rl(this,y,Hl,El,xl,{})}}export{Pl as component};
