import{S as Nt,i as St,s as Mt,e as l,k as c,w as I,t,M as Ft,c as o,d as e,m,a as p,x as C,h as n,b as h,N as Xe,G as a,g as i,y as O,q as D,o as P,B as T,v as Ut}from"../chunks/vendor-hf-doc-builder.js";import{T as Yt}from"../chunks/Tip-hf-doc-builder.js";import{I as Vt}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as M}from"../chunks/CodeBlock-hf-doc-builder.js";function Ht(Ws){let f,z,g,j,L;return{c(){f=l("p"),z=t(`Now that you know how to process a dataset for object detection, learn
`),g=l("a"),j=t("how to train an object detection model"),L=t(`
and use it for inference.`),this.h()},l(u){f=o(u,"P",{});var y=p(f);z=n(y,`Now that you know how to process a dataset for object detection, learn
`),g=o(y,"A",{href:!0,rel:!0});var G=p(g);j=n(G,"how to train an object detection model"),G.forEach(e),L=n(y,`
and use it for inference.`),y.forEach(e),this.h()},h(){h(g,"href","https://colab.research.google.com/github/NielsRogge/Transformers-Tutorials/blob/master/YOLOS/Fine_tuning_YOLOS_for_object_detection_on_custom_dataset_(balloon).ipynb"),h(g,"rel","nofollow")},m(u,y){i(u,f,y),a(f,z),a(f,g),a(g,j),a(f,L)},d(u){u&&e(f)}}}function Jt(Ws){let f,z,g,j,L,u,y,G,ka,Ks,v,Ia,F,Ca,Oa,U,Da,Pa,Qs,w,Ta,ws,La,za,$s,Ga,Ba,Xs,Y,Zs,B,Ra,V,Es,Aa,qa,sa,ps,Na,aa,H,ea,rs,Sa,ta,b,is,ks,Ma,Fa,Ua,cs,Is,Ya,Va,Ha,ms,Cs,Ja,Wa,Ka,hs,Os,Qa,Xa,Za,J,Ds,se,ae,_,fs,Ps,ee,te,ne,gs,Ts,le,oe,pe,R,Ls,re,ie,W,ce,me,he,d,zs,fe,ge,Gs,de,be,Bs,ue,xe,Rs,je,_e,As,ye,ve,qs,we,$e,na,$,Ee,Ns,ke,Ie,ds,Ce,Oe,la,K,oa,Q,Ss,Ze,pa,E,De,Ms,Pe,Te,Fs,Le,ze,ra,X,Us,Ge,Be,ia,Z,ca,A,Re,Ys,Ae,qe,ma,ss,ha,as,Vs,st,fa,bs,Ne,ga,es,da,q,Se,us,Me,Fe,ba,ts,ua,xs,Ue,xa,ns,ja,ls,Hs,at,_a,N,ya;return u=new Vt({}),Y=new M({props:{code:"pip install -U albumentations opencv-python",highlighted:'pip <span class="hljs-keyword">install</span> -U albumentations opencv-python'}}),H=new M({props:{code:`
ds = load_dataset("cppe-5")
example = ds['train'][0]
example`,highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-meta">&gt;&gt;&gt; </span>ds = load_dataset(<span class="hljs-string">&quot;cppe-5&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>example = ds[<span class="hljs-string">&#x27;train&#x27;</span>][<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>example
{<span class="hljs-string">&#x27;height&#x27;</span>: <span class="hljs-number">663</span>,
 <span class="hljs-string">&#x27;image&#x27;</span>: &lt;PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=943x663 at <span class="hljs-number">0x7FC3DC756250</span>&gt;,
 <span class="hljs-string">&#x27;image_id&#x27;</span>: <span class="hljs-number">15</span>,
 <span class="hljs-string">&#x27;objects&#x27;</span>: {<span class="hljs-string">&#x27;area&#x27;</span>: [<span class="hljs-number">3796</span>, <span class="hljs-number">1596</span>, <span class="hljs-number">152768</span>, <span class="hljs-number">81002</span>],
  <span class="hljs-string">&#x27;bbox&#x27;</span>: [[<span class="hljs-number">302.0</span>, <span class="hljs-number">109.0</span>, <span class="hljs-number">73.0</span>, <span class="hljs-number">52.0</span>],
   [<span class="hljs-number">810.0</span>, <span class="hljs-number">100.0</span>, <span class="hljs-number">57.0</span>, <span class="hljs-number">28.0</span>],
   [<span class="hljs-number">160.0</span>, <span class="hljs-number">31.0</span>, <span class="hljs-number">248.0</span>, <span class="hljs-number">616.0</span>],
   [<span class="hljs-number">741.0</span>, <span class="hljs-number">68.0</span>, <span class="hljs-number">202.0</span>, <span class="hljs-number">401.0</span>]],
  <span class="hljs-string">&#x27;category&#x27;</span>: [<span class="hljs-number">4</span>, <span class="hljs-number">4</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>],
  <span class="hljs-string">&#x27;id&#x27;</span>: [<span class="hljs-number">114</span>, <span class="hljs-number">115</span>, <span class="hljs-number">116</span>, <span class="hljs-number">117</span>]},
 <span class="hljs-string">&#x27;width&#x27;</span>: <span class="hljs-number">943</span>}`}}),K=new M({props:{code:`import torch
from torchvision.ops import box_convert
from torchvision.utils import draw_bounding_boxes
from torchvision.transforms.functional import pil_to_tensor, to_pil_image

categories = ds['train'].features['objects'].feature['category']

boxes_xywh = torch.tensor(example['objects']['bbox'])
boxes_xyxy = box_convert(boxes_xywh, 'xywh', 'xyxy')
labels = [categories.int2str(x) for x in example['objects']['category']]
to_pil_image(
    draw_bounding_boxes(
        pil_to_tensor(example['image']),
        boxes_xyxy,
        colors="red",
        labels=labels,
    )
)`,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">from</span> torchvision.ops <span class="hljs-keyword">import</span> box_convert
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> torchvision.utils <span class="hljs-keyword">import</span> draw_bounding_boxes
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> torchvision.transforms.functional <span class="hljs-keyword">import</span> pil_to_tensor, to_pil_image

<span class="hljs-meta">&gt;&gt;&gt; </span>categories = ds[<span class="hljs-string">&#x27;train&#x27;</span>].features[<span class="hljs-string">&#x27;objects&#x27;</span>].feature[<span class="hljs-string">&#x27;category&#x27;</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>boxes_xywh = torch.tensor(example[<span class="hljs-string">&#x27;objects&#x27;</span>][<span class="hljs-string">&#x27;bbox&#x27;</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>boxes_xyxy = box_convert(boxes_xywh, <span class="hljs-string">&#x27;xywh&#x27;</span>, <span class="hljs-string">&#x27;xyxy&#x27;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>labels = [categories.int2str(x) <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example[<span class="hljs-string">&#x27;objects&#x27;</span>][<span class="hljs-string">&#x27;category&#x27;</span>]]
<span class="hljs-meta">&gt;&gt;&gt; </span>to_pil_image(
<span class="hljs-meta">... </span>    draw_bounding_boxes(
<span class="hljs-meta">... </span>        pil_to_tensor(example[<span class="hljs-string">&#x27;image&#x27;</span>]),
<span class="hljs-meta">... </span>        boxes_xyxy,
<span class="hljs-meta">... </span>        colors=<span class="hljs-string">&quot;red&quot;</span>,
<span class="hljs-meta">... </span>        labels=labels,
<span class="hljs-meta">... </span>    )
<span class="hljs-meta">... </span>)`}}),Z=new M({props:{code:`import albumentations
import numpy as np

transform = albumentations.Compose([
    albumentations.Resize(480, 480),
    albumentations.HorizontalFlip(p=1.0),
    albumentations.RandomBrightnessContrast(p=1.0),
], bbox_params=albumentations.BboxParams(format='coco',  label_fields=['category']))

# RGB PIL Image -> BGR Numpy array
image = np.flip(np.array(example['image']), -1)
out = transform(
    image=image,
    bboxes=example['objects']['bbox'],
    category=example['objects']['category'],
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> albumentations
<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>transform = albumentations.Compose([
<span class="hljs-meta">... </span>    albumentations.Resize(<span class="hljs-number">480</span>, <span class="hljs-number">480</span>),
<span class="hljs-meta">... </span>    albumentations.HorizontalFlip(p=<span class="hljs-number">1.0</span>),
<span class="hljs-meta">... </span>    albumentations.RandomBrightnessContrast(p=<span class="hljs-number">1.0</span>),
<span class="hljs-meta">... </span>], bbox_params=albumentations.BboxParams(<span class="hljs-built_in">format</span>=<span class="hljs-string">&#x27;coco&#x27;</span>,  label_fields=[<span class="hljs-string">&#x27;category&#x27;</span>]))

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># RGB PIL Image -&gt; BGR Numpy array</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = np.flip(np.array(example[<span class="hljs-string">&#x27;image&#x27;</span>]), -<span class="hljs-number">1</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>out = transform(
<span class="hljs-meta">... </span>    image=image,
<span class="hljs-meta">... </span>    bboxes=example[<span class="hljs-string">&#x27;objects&#x27;</span>][<span class="hljs-string">&#x27;bbox&#x27;</span>],
<span class="hljs-meta">... </span>    category=example[<span class="hljs-string">&#x27;objects&#x27;</span>][<span class="hljs-string">&#x27;category&#x27;</span>],
<span class="hljs-meta">... </span>)`}}),ss=new M({props:{code:`image = torch.tensor(out['image']).flip(-1).permute(2, 0, 1)
boxes_xywh = torch.stack([torch.tensor(x) for x in out['bboxes']])
boxes_xyxy = box_convert(boxes_xywh, 'xywh', 'xyxy')
labels = [categories.int2str(x) for x in out['category']]
to_pil_image(
    draw_bounding_boxes(
        image,
        boxes_xyxy,
        colors='red',
        labels=labels
    )
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>image = torch.tensor(out[<span class="hljs-string">&#x27;image&#x27;</span>]).flip(-<span class="hljs-number">1</span>).permute(<span class="hljs-number">2</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>boxes_xywh = torch.stack([torch.tensor(x) <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> out[<span class="hljs-string">&#x27;bboxes&#x27;</span>]])
<span class="hljs-meta">&gt;&gt;&gt; </span>boxes_xyxy = box_convert(boxes_xywh, <span class="hljs-string">&#x27;xywh&#x27;</span>, <span class="hljs-string">&#x27;xyxy&#x27;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>labels = [categories.int2str(x) <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> out[<span class="hljs-string">&#x27;category&#x27;</span>]]
<span class="hljs-meta">&gt;&gt;&gt; </span>to_pil_image(
<span class="hljs-meta">... </span>    draw_bounding_boxes(
<span class="hljs-meta">... </span>        image,
<span class="hljs-meta">... </span>        boxes_xyxy,
<span class="hljs-meta">... </span>        colors=<span class="hljs-string">&#x27;red&#x27;</span>,
<span class="hljs-meta">... </span>        labels=labels
<span class="hljs-meta">... </span>    )
<span class="hljs-meta">... </span>)`}}),es=new M({props:{code:`def transforms(examples):
    images, bboxes, categories = [], [], []
    for image, objects in zip(examples['image'], examples['objects']):
        image = np.array(image.convert("RGB"))[:, :, ::-1]
        out = transform(
            image=image,
            bboxes=objects['bbox'],
            category=objects['category']
        )
        images.append(torch.tensor(out['image']).flip(-1).permute(2, 0, 1))
        bboxes.append(torch.tensor(out['bboxes']))
        categories.append(out['category'])
    return {'image': images, 'bbox': bboxes, 'category': categories}`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">transforms</span>(<span class="hljs-params">examples</span>):
<span class="hljs-meta">... </span>    images, bboxes, categories = [], [], []
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> image, objects <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(examples[<span class="hljs-string">&#x27;image&#x27;</span>], examples[<span class="hljs-string">&#x27;objects&#x27;</span>]):
<span class="hljs-meta">... </span>        image = np.array(image.convert(<span class="hljs-string">&quot;RGB&quot;</span>))[:, :, ::-<span class="hljs-number">1</span>]
<span class="hljs-meta">... </span>        out = transform(
<span class="hljs-meta">... </span>            image=image,
<span class="hljs-meta">... </span>            bboxes=objects[<span class="hljs-string">&#x27;bbox&#x27;</span>],
<span class="hljs-meta">... </span>            category=objects[<span class="hljs-string">&#x27;category&#x27;</span>]
<span class="hljs-meta">... </span>        )
<span class="hljs-meta">... </span>        images.append(torch.tensor(out[<span class="hljs-string">&#x27;image&#x27;</span>]).flip(-<span class="hljs-number">1</span>).permute(<span class="hljs-number">2</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>))
<span class="hljs-meta">... </span>        bboxes.append(torch.tensor(out[<span class="hljs-string">&#x27;bboxes&#x27;</span>]))
<span class="hljs-meta">... </span>        categories.append(out[<span class="hljs-string">&#x27;category&#x27;</span>])
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> {<span class="hljs-string">&#x27;image&#x27;</span>: images, <span class="hljs-string">&#x27;bbox&#x27;</span>: bboxes, <span class="hljs-string">&#x27;category&#x27;</span>: categories}`}}),ts=new M({props:{code:"ds['train'].set_transform(transforms)",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>ds[<span class="hljs-string">&#x27;train&#x27;</span>].set_transform(transforms)'}}),ns=new M({props:{code:`example = ds['train'][10]
to_pil_image(
    draw_bounding_boxes(
        example['image'],
        box_convert(example['bbox'], 'xywh', 'xyxy'),
        colors='red',
        labels=[categories.int2str(x) for x in example['category']]
    )
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>example = ds[<span class="hljs-string">&#x27;train&#x27;</span>][<span class="hljs-number">10</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>to_pil_image(
<span class="hljs-meta">... </span>    draw_bounding_boxes(
<span class="hljs-meta">... </span>        example[<span class="hljs-string">&#x27;image&#x27;</span>],
<span class="hljs-meta">... </span>        box_convert(example[<span class="hljs-string">&#x27;bbox&#x27;</span>], <span class="hljs-string">&#x27;xywh&#x27;</span>, <span class="hljs-string">&#x27;xyxy&#x27;</span>),
<span class="hljs-meta">... </span>        colors=<span class="hljs-string">&#x27;red&#x27;</span>,
<span class="hljs-meta">... </span>        labels=[categories.int2str(x) <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example[<span class="hljs-string">&#x27;category&#x27;</span>]]
<span class="hljs-meta">... </span>    )
<span class="hljs-meta">... </span>)`}}),N=new Yt({props:{$$slots:{default:[Ht]},$$scope:{ctx:Ws}}}),{c(){f=l("meta"),z=c(),g=l("h1"),j=l("a"),L=l("span"),I(u.$$.fragment),y=c(),G=l("span"),ka=t("Object detection"),Ks=c(),v=l("p"),Ia=t("Object detection models identify something in an image, and object detection datasets are used for applications such as autonomous driving and detecting natural hazards like wildfire. This guide will show you how to apply transformations to an object detection dataset following the "),F=l("a"),Ca=t("tutorial"),Oa=t(" from "),U=l("a"),Da=t("Albumentations"),Pa=t("."),Qs=c(),w=l("p"),Ta=t("To run these examples, make sure you have up-to-date versions of "),ws=l("code"),La=t("albumentations"),za=t(" and "),$s=l("code"),Ga=t("cv2"),Ba=t(" installed:"),Xs=c(),I(Y.$$.fragment),Zs=c(),B=l("p"),Ra=t("In this example, you\u2019ll use the "),V=l("a"),Es=l("code"),Aa=t("cppe-5"),qa=t(" dataset for identifying medical personal protective equipment (PPE) in the context of the COVID-19 pandemic."),sa=c(),ps=l("p"),Na=t("Load the dataset and take a look at an example:"),aa=c(),I(H.$$.fragment),ea=c(),rs=l("p"),Sa=t("The dataset has the following fields:"),ta=c(),b=l("ul"),is=l("li"),ks=l("code"),Ma=t("image"),Fa=t(": PIL.Image.Image object containing the image."),Ua=c(),cs=l("li"),Is=l("code"),Ya=t("image_id"),Va=t(": The image ID."),Ha=c(),ms=l("li"),Cs=l("code"),Ja=t("height"),Wa=t(": The image height."),Ka=c(),hs=l("li"),Os=l("code"),Qa=t("width"),Xa=t(": The image width."),Za=c(),J=l("li"),Ds=l("code"),se=t("objects"),ae=t(": A dictionary containing bounding box metadata for the objects in the image:"),_=l("ul"),fs=l("li"),Ps=l("code"),ee=t("id"),te=t(": The annotation id."),ne=c(),gs=l("li"),Ts=l("code"),le=t("area"),oe=t(": The area of the bounding box."),pe=c(),R=l("li"),Ls=l("code"),re=t("bbox"),ie=t(": The object\u2019s bounding box (in the "),W=l("a"),ce=t("coco"),me=t(" format)."),he=c(),d=l("li"),zs=l("code"),fe=t("category"),ge=t(": The object\u2019s category, with possible values including "),Gs=l("code"),de=t("Coverall (0)"),be=t(", "),Bs=l("code"),ue=t("Face_Shield (1)"),xe=t(", "),Rs=l("code"),je=t("Gloves (2)"),_e=t(", "),As=l("code"),ye=t("Goggles (3)"),ve=t(" and "),qs=l("code"),we=t("Mask (4)"),$e=t("."),na=c(),$=l("p"),Ee=t("You can visualize the "),Ns=l("code"),ke=t("bboxes"),Ie=t(" on the image using some internal torch utilities. To do that, you will need to reference the "),ds=l("a"),Ce=t("ClassLabel"),Oe=t(" feature associated with the category IDs so you can look up the string labels:"),la=c(),I(K.$$.fragment),oa=c(),Q=l("div"),Ss=l("img"),pa=c(),E=l("p"),De=t("With "),Ms=l("code"),Pe=t("albumentations"),Te=t(", you can apply transforms that will affect the image while also updating the "),Fs=l("code"),Le=t("bboxes"),ze=t(" accordingly. In this case, the image is resized to (480, 480), flipped horizontally, and brightened."),ra=c(),X=l("p"),Us=l("code"),Ge=t("albumentations"),Be=t(" expects the image to be in BGR format, not RGB, so you\u2019ll have to convert the image before applying the transform."),ia=c(),I(Z.$$.fragment),ca=c(),A=l("p"),Re=t("Now when you visualize the result, the image should be flipped, but the "),Ys=l("code"),Ae=t("bboxes"),qe=t(" should still be in the right places."),ma=c(),I(ss.$$.fragment),ha=c(),as=l("div"),Vs=l("img"),fa=c(),bs=l("p"),Ne=t("Create a function to apply the transform to a batch of examples:"),ga=c(),I(es.$$.fragment),da=c(),q=l("p"),Se=t("Use the "),us=l("a"),Me=t("set_transform()"),Fe=t(" function to apply the transform on-the-fly which consumes less disk space. The randomness of data augmentation may return a different image if you access the same example twice. It is especially useful when training a model for several epochs."),ba=c(),I(ts.$$.fragment),ua=c(),xs=l("p"),Ue=t("You can verify the transform works by visualizing the 10th example:"),xa=c(),I(ns.$$.fragment),ja=c(),ls=l("div"),Hs=l("img"),_a=c(),I(N.$$.fragment),this.h()},l(s){const r=Ft('[data-svelte="svelte-1phssyn"]',document.head);f=o(r,"META",{name:!0,content:!0}),r.forEach(e),z=m(s),g=o(s,"H1",{class:!0});var os=p(g);j=o(os,"A",{id:!0,class:!0,href:!0});var et=p(j);L=o(et,"SPAN",{});var tt=p(L);C(u.$$.fragment,tt),tt.forEach(e),et.forEach(e),y=m(os),G=o(os,"SPAN",{});var nt=p(G);ka=n(nt,"Object detection"),nt.forEach(e),os.forEach(e),Ks=m(s),v=o(s,"P",{});var js=p(v);Ia=n(js,"Object detection models identify something in an image, and object detection datasets are used for applications such as autonomous driving and detecting natural hazards like wildfire. This guide will show you how to apply transformations to an object detection dataset following the "),F=o(js,"A",{href:!0,rel:!0});var lt=p(F);Ca=n(lt,"tutorial"),lt.forEach(e),Oa=n(js," from "),U=o(js,"A",{href:!0,rel:!0});var ot=p(U);Da=n(ot,"Albumentations"),ot.forEach(e),Pa=n(js,"."),js.forEach(e),Qs=m(s),w=o(s,"P",{});var _s=p(w);Ta=n(_s,"To run these examples, make sure you have up-to-date versions of "),ws=o(_s,"CODE",{});var pt=p(ws);La=n(pt,"albumentations"),pt.forEach(e),za=n(_s," and "),$s=o(_s,"CODE",{});var rt=p($s);Ga=n(rt,"cv2"),rt.forEach(e),Ba=n(_s," installed:"),_s.forEach(e),Xs=m(s),C(Y.$$.fragment,s),Zs=m(s),B=o(s,"P",{});var va=p(B);Ra=n(va,"In this example, you\u2019ll use the "),V=o(va,"A",{href:!0,rel:!0});var it=p(V);Es=o(it,"CODE",{});var ct=p(Es);Aa=n(ct,"cppe-5"),ct.forEach(e),it.forEach(e),qa=n(va," dataset for identifying medical personal protective equipment (PPE) in the context of the COVID-19 pandemic."),va.forEach(e),sa=m(s),ps=o(s,"P",{});var mt=p(ps);Na=n(mt,"Load the dataset and take a look at an example:"),mt.forEach(e),aa=m(s),C(H.$$.fragment,s),ea=m(s),rs=o(s,"P",{});var ht=p(rs);Sa=n(ht,"The dataset has the following fields:"),ht.forEach(e),ta=m(s),b=o(s,"UL",{});var k=p(b);is=o(k,"LI",{});var Ye=p(is);ks=o(Ye,"CODE",{});var ft=p(ks);Ma=n(ft,"image"),ft.forEach(e),Fa=n(Ye,": PIL.Image.Image object containing the image."),Ye.forEach(e),Ua=m(k),cs=o(k,"LI",{});var Ve=p(cs);Is=o(Ve,"CODE",{});var gt=p(Is);Ya=n(gt,"image_id"),gt.forEach(e),Va=n(Ve,": The image ID."),Ve.forEach(e),Ha=m(k),ms=o(k,"LI",{});var He=p(ms);Cs=o(He,"CODE",{});var dt=p(Cs);Ja=n(dt,"height"),dt.forEach(e),Wa=n(He,": The image height."),He.forEach(e),Ka=m(k),hs=o(k,"LI",{});var Je=p(hs);Os=o(Je,"CODE",{});var bt=p(Os);Qa=n(bt,"width"),bt.forEach(e),Xa=n(Je,": The image width."),Je.forEach(e),Za=m(k),J=o(k,"LI",{});var wa=p(J);Ds=o(wa,"CODE",{});var ut=p(Ds);se=n(ut,"objects"),ut.forEach(e),ae=n(wa,": A dictionary containing bounding box metadata for the objects in the image:"),_=o(wa,"UL",{});var S=p(_);fs=o(S,"LI",{});var We=p(fs);Ps=o(We,"CODE",{});var xt=p(Ps);ee=n(xt,"id"),xt.forEach(e),te=n(We,": The annotation id."),We.forEach(e),ne=m(S),gs=o(S,"LI",{});var Ke=p(gs);Ts=o(Ke,"CODE",{});var jt=p(Ts);le=n(jt,"area"),jt.forEach(e),oe=n(Ke,": The area of the bounding box."),Ke.forEach(e),pe=m(S),R=o(S,"LI",{});var Js=p(R);Ls=o(Js,"CODE",{});var _t=p(Ls);re=n(_t,"bbox"),_t.forEach(e),ie=n(Js,": The object\u2019s bounding box (in the "),W=o(Js,"A",{href:!0,rel:!0});var yt=p(W);ce=n(yt,"coco"),yt.forEach(e),me=n(Js," format)."),Js.forEach(e),he=m(S),d=o(S,"LI",{});var x=p(d);zs=o(x,"CODE",{});var vt=p(zs);fe=n(vt,"category"),vt.forEach(e),ge=n(x,": The object\u2019s category, with possible values including "),Gs=o(x,"CODE",{});var wt=p(Gs);de=n(wt,"Coverall (0)"),wt.forEach(e),be=n(x,", "),Bs=o(x,"CODE",{});var $t=p(Bs);ue=n($t,"Face_Shield (1)"),$t.forEach(e),xe=n(x,", "),Rs=o(x,"CODE",{});var Et=p(Rs);je=n(Et,"Gloves (2)"),Et.forEach(e),_e=n(x,", "),As=o(x,"CODE",{});var kt=p(As);ye=n(kt,"Goggles (3)"),kt.forEach(e),ve=n(x," and "),qs=o(x,"CODE",{});var It=p(qs);we=n(It,"Mask (4)"),It.forEach(e),$e=n(x,"."),x.forEach(e),S.forEach(e),wa.forEach(e),k.forEach(e),na=m(s),$=o(s,"P",{});var ys=p($);Ee=n(ys,"You can visualize the "),Ns=o(ys,"CODE",{});var Ct=p(Ns);ke=n(Ct,"bboxes"),Ct.forEach(e),Ie=n(ys," on the image using some internal torch utilities. To do that, you will need to reference the "),ds=o(ys,"A",{href:!0});var Ot=p(ds);Ce=n(Ot,"ClassLabel"),Ot.forEach(e),Oe=n(ys," feature associated with the category IDs so you can look up the string labels:"),ys.forEach(e),la=m(s),C(K.$$.fragment,s),oa=m(s),Q=o(s,"DIV",{class:!0});var Dt=p(Q);Ss=o(Dt,"IMG",{src:!0}),Dt.forEach(e),pa=m(s),E=o(s,"P",{});var vs=p(E);De=n(vs,"With "),Ms=o(vs,"CODE",{});var Pt=p(Ms);Pe=n(Pt,"albumentations"),Pt.forEach(e),Te=n(vs,", you can apply transforms that will affect the image while also updating the "),Fs=o(vs,"CODE",{});var Tt=p(Fs);Le=n(Tt,"bboxes"),Tt.forEach(e),ze=n(vs," accordingly. In this case, the image is resized to (480, 480), flipped horizontally, and brightened."),vs.forEach(e),ra=m(s),X=o(s,"P",{});var Qe=p(X);Us=o(Qe,"CODE",{});var Lt=p(Us);Ge=n(Lt,"albumentations"),Lt.forEach(e),Be=n(Qe," expects the image to be in BGR format, not RGB, so you\u2019ll have to convert the image before applying the transform."),Qe.forEach(e),ia=m(s),C(Z.$$.fragment,s),ca=m(s),A=o(s,"P",{});var $a=p(A);Re=n($a,"Now when you visualize the result, the image should be flipped, but the "),Ys=o($a,"CODE",{});var zt=p(Ys);Ae=n(zt,"bboxes"),zt.forEach(e),qe=n($a," should still be in the right places."),$a.forEach(e),ma=m(s),C(ss.$$.fragment,s),ha=m(s),as=o(s,"DIV",{class:!0});var Gt=p(as);Vs=o(Gt,"IMG",{src:!0}),Gt.forEach(e),fa=m(s),bs=o(s,"P",{});var Bt=p(bs);Ne=n(Bt,"Create a function to apply the transform to a batch of examples:"),Bt.forEach(e),ga=m(s),C(es.$$.fragment,s),da=m(s),q=o(s,"P",{});var Ea=p(q);Se=n(Ea,"Use the "),us=o(Ea,"A",{href:!0});var Rt=p(us);Me=n(Rt,"set_transform()"),Rt.forEach(e),Fe=n(Ea," function to apply the transform on-the-fly which consumes less disk space. The randomness of data augmentation may return a different image if you access the same example twice. It is especially useful when training a model for several epochs."),Ea.forEach(e),ba=m(s),C(ts.$$.fragment,s),ua=m(s),xs=o(s,"P",{});var At=p(xs);Ue=n(At,"You can verify the transform works by visualizing the 10th example:"),At.forEach(e),xa=m(s),C(ns.$$.fragment,s),ja=m(s),ls=o(s,"DIV",{class:!0});var qt=p(ls);Hs=o(qt,"IMG",{src:!0}),qt.forEach(e),_a=m(s),C(N.$$.fragment,s),this.h()},h(){h(f,"name","hf:doc:metadata"),h(f,"content",JSON.stringify(Wt)),h(j,"id","object-detection"),h(j,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(j,"href","#object-detection"),h(g,"class","relative group"),h(F,"href","https://albumentations.ai/docs/examples/example_bboxes/"),h(F,"rel","nofollow"),h(U,"href","https://albumentations.ai/docs/"),h(U,"rel","nofollow"),h(V,"href","https://huggingface.co/datasets/cppe-5"),h(V,"rel","nofollow"),h(W,"href","https://albumentations.ai/docs/getting_started/bounding_boxes_augmentation/#coco"),h(W,"rel","nofollow"),h(ds,"href","/docs/datasets/v2.11.0/en/package_reference/main_classes#datasets.ClassLabel"),Xe(Ss.src,Ze="https://huggingface.co/datasets/nateraw/documentation-images/resolve/main/visualize_detection_example.png")||h(Ss,"src",Ze),h(Q,"class","flex justify-center"),Xe(Vs.src,st="https://huggingface.co/datasets/nateraw/documentation-images/resolve/main/visualize_detection_example_transformed.png")||h(Vs,"src",st),h(as,"class","flex justify-center"),h(us,"href","/docs/datasets/v2.11.0/en/package_reference/main_classes#datasets.Dataset.set_transform"),Xe(Hs.src,at="https://huggingface.co/datasets/nateraw/documentation-images/resolve/main/visualize_detection_example_transformed_2.png")||h(Hs,"src",at),h(ls,"class","flex justify-center")},m(s,r){a(document.head,f),i(s,z,r),i(s,g,r),a(g,j),a(j,L),O(u,L,null),a(g,y),a(g,G),a(G,ka),i(s,Ks,r),i(s,v,r),a(v,Ia),a(v,F),a(F,Ca),a(v,Oa),a(v,U),a(U,Da),a(v,Pa),i(s,Qs,r),i(s,w,r),a(w,Ta),a(w,ws),a(ws,La),a(w,za),a(w,$s),a($s,Ga),a(w,Ba),i(s,Xs,r),O(Y,s,r),i(s,Zs,r),i(s,B,r),a(B,Ra),a(B,V),a(V,Es),a(Es,Aa),a(B,qa),i(s,sa,r),i(s,ps,r),a(ps,Na),i(s,aa,r),O(H,s,r),i(s,ea,r),i(s,rs,r),a(rs,Sa),i(s,ta,r),i(s,b,r),a(b,is),a(is,ks),a(ks,Ma),a(is,Fa),a(b,Ua),a(b,cs),a(cs,Is),a(Is,Ya),a(cs,Va),a(b,Ha),a(b,ms),a(ms,Cs),a(Cs,Ja),a(ms,Wa),a(b,Ka),a(b,hs),a(hs,Os),a(Os,Qa),a(hs,Xa),a(b,Za),a(b,J),a(J,Ds),a(Ds,se),a(J,ae),a(J,_),a(_,fs),a(fs,Ps),a(Ps,ee),a(fs,te),a(_,ne),a(_,gs),a(gs,Ts),a(Ts,le),a(gs,oe),a(_,pe),a(_,R),a(R,Ls),a(Ls,re),a(R,ie),a(R,W),a(W,ce),a(R,me),a(_,he),a(_,d),a(d,zs),a(zs,fe),a(d,ge),a(d,Gs),a(Gs,de),a(d,be),a(d,Bs),a(Bs,ue),a(d,xe),a(d,Rs),a(Rs,je),a(d,_e),a(d,As),a(As,ye),a(d,ve),a(d,qs),a(qs,we),a(d,$e),i(s,na,r),i(s,$,r),a($,Ee),a($,Ns),a(Ns,ke),a($,Ie),a($,ds),a(ds,Ce),a($,Oe),i(s,la,r),O(K,s,r),i(s,oa,r),i(s,Q,r),a(Q,Ss),i(s,pa,r),i(s,E,r),a(E,De),a(E,Ms),a(Ms,Pe),a(E,Te),a(E,Fs),a(Fs,Le),a(E,ze),i(s,ra,r),i(s,X,r),a(X,Us),a(Us,Ge),a(X,Be),i(s,ia,r),O(Z,s,r),i(s,ca,r),i(s,A,r),a(A,Re),a(A,Ys),a(Ys,Ae),a(A,qe),i(s,ma,r),O(ss,s,r),i(s,ha,r),i(s,as,r),a(as,Vs),i(s,fa,r),i(s,bs,r),a(bs,Ne),i(s,ga,r),O(es,s,r),i(s,da,r),i(s,q,r),a(q,Se),a(q,us),a(us,Me),a(q,Fe),i(s,ba,r),O(ts,s,r),i(s,ua,r),i(s,xs,r),a(xs,Ue),i(s,xa,r),O(ns,s,r),i(s,ja,r),i(s,ls,r),a(ls,Hs),i(s,_a,r),O(N,s,r),ya=!0},p(s,[r]){const os={};r&2&&(os.$$scope={dirty:r,ctx:s}),N.$set(os)},i(s){ya||(D(u.$$.fragment,s),D(Y.$$.fragment,s),D(H.$$.fragment,s),D(K.$$.fragment,s),D(Z.$$.fragment,s),D(ss.$$.fragment,s),D(es.$$.fragment,s),D(ts.$$.fragment,s),D(ns.$$.fragment,s),D(N.$$.fragment,s),ya=!0)},o(s){P(u.$$.fragment,s),P(Y.$$.fragment,s),P(H.$$.fragment,s),P(K.$$.fragment,s),P(Z.$$.fragment,s),P(ss.$$.fragment,s),P(es.$$.fragment,s),P(ts.$$.fragment,s),P(ns.$$.fragment,s),P(N.$$.fragment,s),ya=!1},d(s){e(f),s&&e(z),s&&e(g),T(u),s&&e(Ks),s&&e(v),s&&e(Qs),s&&e(w),s&&e(Xs),T(Y,s),s&&e(Zs),s&&e(B),s&&e(sa),s&&e(ps),s&&e(aa),T(H,s),s&&e(ea),s&&e(rs),s&&e(ta),s&&e(b),s&&e(na),s&&e($),s&&e(la),T(K,s),s&&e(oa),s&&e(Q),s&&e(pa),s&&e(E),s&&e(ra),s&&e(X),s&&e(ia),T(Z,s),s&&e(ca),s&&e(A),s&&e(ma),T(ss,s),s&&e(ha),s&&e(as),s&&e(fa),s&&e(bs),s&&e(ga),T(es,s),s&&e(da),s&&e(q),s&&e(ba),T(ts,s),s&&e(ua),s&&e(xs),s&&e(xa),T(ns,s),s&&e(ja),s&&e(ls),s&&e(_a),T(N,s)}}}const Wt={local:"object-detection",title:"Object detection"};function Kt(Ws){return Ut(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class an extends Nt{constructor(f){super();St(this,f,Kt,Jt,Mt,{})}}export{an as default,Wt as metadata};
