import{S as ph,i as oh,s as rh,e as n,k as c,w as u,t as e,M as ih,c as p,d as l,m as h,a as o,x as j,h as t,b as m,N as nh,G as a,g as i,y as M,q as d,o as y,B as b,v as ch}from"../../chunks/vendor-hf-doc-builder.js";import{T as hh}from"../../chunks/Tip-hf-doc-builder.js";import{I as ul}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as J}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as mh}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function uh(Ze){let _,w,g,k,ns,v,Ws,ps,$,ms,X,Y,z,Rs,N,S,Vs,F,B;return{c(){_=e(`The task illustrated in this tutorial is supported by the following model architectures:

`),w=n("p"),g=n("a"),k=e("Conditional DETR"),ns=e(", "),v=n("a"),Ws=e("Deformable DETR"),ps=e(", "),$=n("a"),ms=e("DETA"),X=e(", "),Y=n("a"),z=e("DETR"),Rs=e(", "),N=n("a"),S=e("Table Transformer"),Vs=e(", "),F=n("a"),B=e("YOLOS"),this.h()},l(U){_=t(U,`The task illustrated in this tutorial is supported by the following model architectures:

`),w=p(U,"P",{});var T=o(w);g=p(T,"A",{href:!0});var H=o(g);k=t(H,"Conditional DETR"),H.forEach(l),ns=t(T,", "),v=p(T,"A",{href:!0});var Ia=o(v);Ws=t(Ia,"Deformable DETR"),Ia.forEach(l),ps=t(T,", "),$=p(T,"A",{href:!0});var Ca=o($);ms=t(Ca,"DETA"),Ca.forEach(l),X=t(T,", "),Y=p(T,"A",{href:!0});var D=o(Y);z=t(D,"DETR"),D.forEach(l),Rs=t(T,", "),N=p(T,"A",{href:!0});var _a=o(N);S=t(_a,"Table Transformer"),_a.forEach(l),Vs=t(T,", "),F=p(T,"A",{href:!0});var va=o(F);B=t(va,"YOLOS"),va.forEach(l),T.forEach(l),this.h()},h(){m(g,"href","../model_doc/conditional_detr"),m(v,"href","../model_doc/deformable_detr"),m($,"href","../model_doc/deta"),m(Y,"href","../model_doc/detr"),m(N,"href","../model_doc/table-transformer"),m(F,"href","../model_doc/yolos")},m(U,T){i(U,_,T),i(U,w,T),a(w,g),a(g,k),a(w,ns),a(w,v),a(v,Ws),a(w,ps),a(w,$),a($,ms),a(w,X),a(w,Y),a(Y,z),a(w,Rs),a(w,N),a(N,S),a(w,Vs),a(w,F),a(F,B)},d(U){U&&l(_),U&&l(w)}}}function jh(Ze){let _,w,g,k,ns,v,Ws,ps,$,ms,X,Y,z,Rs,N,S,Vs,F,B,U,T,H,Ia,Ca,D,_a,va,un,jl,jn,Ae,us,ke,Ea,Mn,Be,Qs,Ge,P,dn,Ml,yn,bn,dl,Jn,wn,We,Za,fn,Re,xs,Ve,os,js,yl,Xs,Tn,bl,Un,Qe,Ms,gn,Ys,In,Cn,xe,Aa,_n,Xe,Ns,Ye,ka,vn,Ne,Ba,En,Fe,Fs,qe,Ga,Zn,$e,E,Wa,Jl,An,kn,Bn,ds,wl,Gn,Wn,fl,Rn,Vn,Qn,Ra,Tl,xn,Xn,Yn,Va,Ul,Nn,Fn,qn,qs,gl,$n,zn,q,Qa,Il,Sn,Hn,Dn,xa,Cl,Pn,On,Kn,ys,_l,Ln,sp,$s,ap,lp,ep,C,vl,tp,np,El,pp,op,Zl,rp,ip,Al,cp,hp,kl,mp,up,Bl,jp,ze,O,Mp,Gl,dp,yp,Wl,bp,Jp,Se,Xa,wp,He,zs,De,Ss,Ya,Lr,Pe,G,fp,Rl,Tp,Up,Vl,gp,Ip,Ql,Cp,_p,Oe,Na,vp,Ke,Hs,Le,rs,bs,xl,Ds,Ep,Xl,Zp,st,Z,Ap,Fa,kp,Bp,Yl,Gp,Wp,Nl,Rp,Vp,Fl,Qp,xp,at,Js,ql,$l,Xp,Yp,zl,Sl,Np,lt,qa,Fp,et,$a,qp,tt,Ps,nt,ws,$p,Hl,zp,Sp,pt,fs,Dl,Hp,Dp,Pl,Pp,ot,K,Op,Os,Kp,Lp,Ks,so,ao,rt,Ls,it,L,lo,Ol,eo,to,Kl,no,po,ct,sa,ht,za,oo,mt,aa,ut,Ts,ro,la,io,co,jt,W,ho,Ll,mo,uo,se,jo,Mo,ae,yo,bo,Mt,ea,dt,R,Jo,le,wo,fo,ee,To,Uo,te,go,Io,yt,ta,bt,is,Us,ne,na,Co,pe,_o,Jt,Sa,vo,wt,V,pa,Eo,Ha,Zo,Ao,ko,oa,Bo,Da,Go,Wo,Ro,ra,Vo,Pa,Qo,xo,Xo,ia,Yo,Oa,No,Fo,ft,Q,qo,oe,$o,zo,re,So,Ho,ie,Do,Po,Tt,ca,Ut,f,Oo,Ka,Ko,Lo,ce,sr,ar,he,lr,er,me,tr,nr,ue,pr,or,je,rr,ir,Me,cr,hr,gt,ha,It,gs,mr,La,ur,jr,Ct,ma,_t,A,Mr,de,dr,yr,ye,br,Jr,be,wr,fr,sl,Tr,Ur,vt,ua,Et,cs,Is,Je,ja,gr,we,Ir,Zt,Ma,Cr,At,ss,_r,fe,vr,Er,Te,Zr,Ar,kt,Cs,kr,Ue,Br,Gr,Bt,da,Gt,as,Wr,ge,Rr,Vr,Ie,Qr,xr,Wt,ya,Rt,al,Xr,Vt,ba,Qt,_s,Yr,ll,Nr,Fr,xt,hs,vs,Ce,Ja,qr,_e,$r,Xt,wa,Yt,el,zr,Nt,fa,Ft,tl,Sr,qt,Ta,$t,Ua,nl,si,zt;return v=new ul({}),X=new mh({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"}]}}),us=new hh({props:{$$slots:{default:[uh]},$$scope:{ctx:Ze}}}),Qs=new J({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1xJTIwZGF0YXNldHMlMjB0cmFuc2Zvcm1lcnMlMjBldmFsdWF0ZSUyMHRpbW0lMjBhbGJ1bWVudGF0aW9ucw==",highlighted:"pip install -q datasets transformers evaluate timm albumentations"}}),xs=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()`}}),Xs=new ul({}),Ns=new J({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBY3BwZTUlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIyY3BwZS01JTIyKSUwQWNwcGU1",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>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">1000</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>
    })
})`}}),Fs=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">15</span>,
 <span class="hljs-string">&#x27;image&#x27;</span>: &lt;PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=943x663 at <span class="hljs-number">0x7F9EC9E77C10</span>&gt;,
 <span class="hljs-string">&#x27;width&#x27;</span>: <span class="hljs-number">943</span>,
 <span class="hljs-string">&#x27;height&#x27;</span>: <span class="hljs-number">663</span>,
 <span class="hljs-string">&#x27;objects&#x27;</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;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>]}}`}}),zs=new J({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBaW1wb3J0JTIwb3MlMEFmcm9tJTIwUElMJTIwaW1wb3J0JTIwSW1hZ2UlMkMlMjBJbWFnZURyYXclMEElMEFpbWFnZSUyMCUzRCUyMGNwcGU1JTVCJTIydHJhaW4lMjIlNUQlNUIwJTVEJTVCJTIyaW1hZ2UlMjIlNUQlMEFhbm5vdGF0aW9ucyUyMCUzRCUyMGNwcGU1JTVCJTIydHJhaW4lMjIlNUQlNUIwJTVEJTVCJTIyb2JqZWN0cyUyMiU1RCUwQWRyYXclMjAlM0QlMjBJbWFnZURyYXcuRHJhdyhpbWFnZSklMEElMEFjYXRlZ29yaWVzJTIwJTNEJTIwY3BwZTUlNUIlMjJ0cmFpbiUyMiU1RC5mZWF0dXJlcyU1QiUyMm9iamVjdHMlMjIlNUQuZmVhdHVyZSU1QiUyMmNhdGVnb3J5JTIyJTVELm5hbWVzJTBBJTBBaWQybGFiZWwlMjAlM0QlMjAlN0JpbmRleCUzQSUyMHglMjBmb3IlMjBpbmRleCUyQyUyMHglMjBpbiUyMGVudW1lcmF0ZShjYXRlZ29yaWVzJTJDJTIwc3RhcnQlM0QwKSU3RCUwQWxhYmVsMmlkJTIwJTNEJTIwJTdCdiUzQSUyMGslMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwaWQybGFiZWwuaXRlbXMoKSU3RCUwQSUwQWZvciUyMGklMjBpbiUyMHJhbmdlKGxlbihhbm5vdGF0aW9ucyU1QiUyMmlkJTIyJTVEKSklM0ElMEElMjAlMjAlMjAlMjBib3glMjAlM0QlMjBhbm5vdGF0aW9ucyU1QiUyMmJib3glMjIlNUQlNUJpJTIwLSUyMDElNUQlMEElMjAlMjAlMjAlMjBjbGFzc19pZHglMjAlM0QlMjBhbm5vdGF0aW9ucyU1QiUyMmNhdGVnb3J5JTIyJTVEJTVCaSUyMC0lMjAxJTVEJTBBJTIwJTIwJTIwJTIweCUyQyUyMHklMkMlMjB3JTJDJTIwaCUyMCUzRCUyMHR1cGxlKGJveCklMEElMjAlMjAlMjAlMjBkcmF3LnJlY3RhbmdsZSgoeCUyQyUyMHklMkMlMjB4JTIwJTJCJTIwdyUyQyUyMHklMjAlMkIlMjBoKSUyQyUyMG91dGxpbmUlM0QlMjJyZWQlMjIlMkMlMjB3aWR0aCUzRDEpJTBBJTIwJTIwJTIwJTIwZHJhdy50ZXh0KCh4JTJDJTIweSklMkMlMjBpZDJsYWJlbCU1QmNsYXNzX2lkeCU1RCUyQyUyMGZpbGwlM0QlMjJ3aGl0ZSUyMiklMEElMEFpbWFnZQ==",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">0</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">0</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-number">1</span>]
<span class="hljs-meta">... </span>    class_idx = annotations[<span class="hljs-string">&quot;category&quot;</span>][i - <span class="hljs-number">1</span>]
<span class="hljs-meta">... </span>    x, y, w, h = <span class="hljs-built_in">tuple</span>(box)
<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`}}),Hs=new J({props:{code:"cmVtb3ZlX2lkeCUyMCUzRCUyMCU1QjU5MCUyQyUyMDgyMSUyQyUyMDgyMiUyQyUyMDg3NSUyQyUyMDg3NiUyQyUyMDg3OCUyQyUyMDg3OSU1RCUwQWtlZXAlMjAlM0QlMjAlNUJpJTIwZm9yJTIwaSUyMGluJTIwcmFuZ2UobGVuKGNwcGU1JTVCJTIydHJhaW4lMjIlNUQpKSUyMGlmJTIwaSUyMG5vdCUyMGluJTIwcmVtb3ZlX2lkeCU1RCUwQWNwcGU1JTVCJTIydHJhaW4lMjIlNUQlMjAlM0QlMjBjcHBlNSU1QiUyMnRyYWluJTIyJTVELnNlbGVjdChrZWVwKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>remove_idx = [<span class="hljs-number">590</span>, <span class="hljs-number">821</span>, <span class="hljs-number">822</span>, <span class="hljs-number">875</span>, <span class="hljs-number">876</span>, <span class="hljs-number">878</span>, <span class="hljs-number">879</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>keep = [i <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>(cppe5[<span class="hljs-string">&quot;train&quot;</span>])) <span class="hljs-keyword">if</span> i <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> remove_idx]
<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>].select(keep)`}}),Ds=new ul({}),Ps=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJmYWNlYm9vayUyRmRldHItcmVzbmV0LTUwJTIyJTBBaW1hZ2VfcHJvY2Vzc29yJTIwJTNEJTIwQXV0b0ltYWdlUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KQ==",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>checkpoint = <span class="hljs-string">&quot;facebook/detr-resnet-50&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(checkpoint)`}}),Ls=new J({props:{code:"aW1wb3J0JTIwYWxidW1lbnRhdGlvbnMlMEFpbXBvcnQlMjBudW1weSUyMGFzJTIwbnAlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXRyYW5zZm9ybSUyMCUzRCUyMGFsYnVtZW50YXRpb25zLkNvbXBvc2UoJTBBJTIwJTIwJTIwJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYWxidW1lbnRhdGlvbnMuUmVzaXplKDQ4MCUyQyUyMDQ4MCklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhbGJ1bWVudGF0aW9ucy5Ib3Jpem9udGFsRmxpcChwJTNEMS4wKSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGFsYnVtZW50YXRpb25zLlJhbmRvbUJyaWdodG5lc3NDb250cmFzdChwJTNEMS4wKSUyQyUwQSUyMCUyMCUyMCUyMCU1RCUyQyUwQSUyMCUyMCUyMCUyMGJib3hfcGFyYW1zJTNEYWxidW1lbnRhdGlvbnMuQmJveFBhcmFtcyhmb3JtYXQlM0QlMjJjb2NvJTIyJTJDJTIwbGFiZWxfZmllbGRzJTNEJTVCJTIyY2F0ZWdvcnklMjIlNUQpJTJDJTBBKQ==",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><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>transform = albumentations.Compose(
<span class="hljs-meta">... </span>    [
<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>    ],
<span class="hljs-meta">... </span>    bbox_params=albumentations.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>]),
<span class="hljs-meta">... </span>)`}}),sa=new J({props:{code:"ZGVmJTIwZm9ybWF0dGVkX2FubnMoaW1hZ2VfaWQlMkMlMjBjYXRlZ29yeSUyQyUyMGFyZWElMkMlMjBiYm94KSUzQSUwQSUyMCUyMCUyMCUyMGFubm90YXRpb25zJTIwJTNEJTIwJTVCJTVEJTBBJTIwJTIwJTIwJTIwZm9yJTIwaSUyMGluJTIwcmFuZ2UoMCUyQyUyMGxlbihjYXRlZ29yeSkpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbmV3X2FubiUyMCUzRCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmltYWdlX2lkJTIyJTNBJTIwaW1hZ2VfaWQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJjYXRlZ29yeV9pZCUyMiUzQSUyMGNhdGVnb3J5JTVCaSU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmlzQ3Jvd2QlMjIlM0ElMjAwJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyYXJlYSUyMiUzQSUyMGFyZWElNUJpJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyYmJveCUyMiUzQSUyMGxpc3QoYmJveCU1QmklNUQpJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYW5ub3RhdGlvbnMuYXBwZW5kKG5ld19hbm4pJTBBJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwYW5ub3RhdGlvbnM=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">formatted_anns</span>(<span class="hljs-params">image_id, category, area, bbox</span>):
<span class="hljs-meta">... </span>    annotations = []
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, <span class="hljs-built_in">len</span>(category)):
<span class="hljs-meta">... </span>        new_ann = {
<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[i],
<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[i],
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;bbox&quot;</span>: <span class="hljs-built_in">list</span>(bbox[i]),
<span class="hljs-meta">... </span>        }
<span class="hljs-meta">... </span>        annotations.append(new_ann)

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> annotations`}}),aa=new J({props:{code:"JTIzJTIwdHJhbnNmb3JtaW5nJTIwYSUyMGJhdGNoJTBBZGVmJTIwdHJhbnNmb3JtX2F1Z19hbm4oZXhhbXBsZXMpJTNBJTBBJTIwJTIwJTIwJTIwaW1hZ2VfaWRzJTIwJTNEJTIwZXhhbXBsZXMlNUIlMjJpbWFnZV9pZCUyMiU1RCUwQSUyMCUyMCUyMCUyMGltYWdlcyUyQyUyMGJib3hlcyUyQyUyMGFyZWElMkMlMjBjYXRlZ29yaWVzJTIwJTNEJTIwJTVCJTVEJTJDJTIwJTVCJTVEJTJDJTIwJTVCJTVEJTJDJTIwJTVCJTVEJTBBJTIwJTIwJTIwJTIwZm9yJTIwaW1hZ2UlMkMlMjBvYmplY3RzJTIwaW4lMjB6aXAoZXhhbXBsZXMlNUIlMjJpbWFnZSUyMiU1RCUyQyUyMGV4YW1wbGVzJTVCJTIyb2JqZWN0cyUyMiU1RCklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpbWFnZSUyMCUzRCUyMG5wLmFycmF5KGltYWdlLmNvbnZlcnQoJTIyUkdCJTIyKSklNUIlM0ElMkMlMjAlM0ElMkMlMjAlM0ElM0EtMSU1RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dCUyMCUzRCUyMHRyYW5zZm9ybShpbWFnZSUzRGltYWdlJTJDJTIwYmJveGVzJTNEb2JqZWN0cyU1QiUyMmJib3glMjIlNUQlMkMlMjBjYXRlZ29yeSUzRG9iamVjdHMlNUIlMjJjYXRlZ29yeSUyMiU1RCklMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhcmVhLmFwcGVuZChvYmplY3RzJTVCJTIyYXJlYSUyMiU1RCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpbWFnZXMuYXBwZW5kKG91dCU1QiUyMmltYWdlJTIyJTVEKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGJib3hlcy5hcHBlbmQob3V0JTVCJTIyYmJveGVzJTIyJTVEKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGNhdGVnb3JpZXMuYXBwZW5kKG91dCU1QiUyMmNhdGVnb3J5JTIyJTVEKSUwQSUwQSUyMCUyMCUyMCUyMHRhcmdldHMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0IlMjJpbWFnZV9pZCUyMiUzQSUyMGlkXyUyQyUyMCUyMmFubm90YXRpb25zJTIyJTNBJTIwZm9ybWF0dGVkX2FubnMoaWRfJTJDJTIwY2F0XyUyQyUyMGFyXyUyQyUyMGJveF8pJTdEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZm9yJTIwaWRfJTJDJTIwY2F0XyUyQyUyMGFyXyUyQyUyMGJveF8lMjBpbiUyMHppcChpbWFnZV9pZHMlMkMlMjBjYXRlZ29yaWVzJTJDJTIwYXJlYSUyQyUyMGJib3hlcyklMEElMjAlMjAlMjAlMjAlNUQlMEElMEElMjAlMjAlMjAlMjByZXR1cm4lMjBpbWFnZV9wcm9jZXNzb3IoaW1hZ2VzJTNEaW1hZ2VzJTJDJTIwYW5ub3RhdGlvbnMlM0R0YXJnZXRzJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># transforming a batch</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">transform_aug_ann</span>(<span class="hljs-params">examples</span>):
<span class="hljs-meta">... </span>    image_ids = examples[<span class="hljs-string">&quot;image_id&quot;</span>]
<span class="hljs-meta">... </span>    images, bboxes, area, 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">&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-number">1</span>]
<span class="hljs-meta">... </span>        out = 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>        area.append(objects[<span class="hljs-string">&quot;area&quot;</span>])
<span class="hljs-meta">... </span>        images.append(out[<span class="hljs-string">&quot;image&quot;</span>])
<span class="hljs-meta">... </span>        bboxes.append(out[<span class="hljs-string">&quot;bboxes&quot;</span>])
<span class="hljs-meta">... </span>        categories.append(out[<span class="hljs-string">&quot;category&quot;</span>])

<span class="hljs-meta">... </span>    targets = [
<span class="hljs-meta">... </span>        {<span class="hljs-string">&quot;image_id&quot;</span>: id_, <span class="hljs-string">&quot;annotations&quot;</span>: formatted_anns(id_, cat_, ar_, box_)}
<span class="hljs-meta">... </span>        <span class="hljs-keyword">for</span> id_, cat_, ar_, box_ <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(image_ids, categories, area, bboxes)
<span class="hljs-meta">... </span>    ]

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> image_processor(images=images, annotations=targets, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)`}}),ea=new J({props:{code:"Y3BwZTUlNUIlMjJ0cmFpbiUyMiU1RCUyMCUzRCUyMGNwcGU1JTVCJTIydHJhaW4lMjIlNUQud2l0aF90cmFuc2Zvcm0odHJhbnNmb3JtX2F1Z19hbm4pJTBBY3BwZTUlNUIlMjJ0cmFpbiUyMiU1RCU1QjE1JTVEJTBBJTBB",highlighted:`<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(transform_aug_ann)
<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">0.9132</span>,  <span class="hljs-number">0.9132</span>,  <span class="hljs-number">0.9132</span>,  ..., -<span class="hljs-number">1.9809</span>, -<span class="hljs-number">1.9809</span>, -<span class="hljs-number">1.9809</span>],
          [ <span class="hljs-number">0.9132</span>,  <span class="hljs-number">0.9132</span>,  <span class="hljs-number">0.9132</span>,  ..., -<span class="hljs-number">1.9809</span>, -<span class="hljs-number">1.9809</span>, -<span class="hljs-number">1.9809</span>],
          [ <span class="hljs-number">0.9132</span>,  <span class="hljs-number">0.9132</span>,  <span class="hljs-number">0.9132</span>,  ..., -<span class="hljs-number">1.9638</span>, -<span class="hljs-number">1.9638</span>, -<span class="hljs-number">1.9638</span>],
          ...,
          [-<span class="hljs-number">1.5699</span>, -<span class="hljs-number">1.5699</span>, -<span class="hljs-number">1.5699</span>,  ..., -<span class="hljs-number">1.9980</span>, -<span class="hljs-number">1.9980</span>, -<span class="hljs-number">1.9980</span>],
          [-<span class="hljs-number">1.5528</span>, -<span class="hljs-number">1.5528</span>, -<span class="hljs-number">1.5528</span>,  ..., -<span class="hljs-number">1.9980</span>, -<span class="hljs-number">1.9809</span>, -<span class="hljs-number">1.9809</span>],
          [-<span class="hljs-number">1.5528</span>, -<span class="hljs-number">1.5528</span>, -<span class="hljs-number">1.5528</span>,  ..., -<span class="hljs-number">1.9980</span>, -<span class="hljs-number">1.9809</span>, -<span class="hljs-number">1.9809</span>]],

         [[ <span class="hljs-number">1.3081</span>,  <span class="hljs-number">1.3081</span>,  <span class="hljs-number">1.3081</span>,  ..., -<span class="hljs-number">1.8431</span>, -<span class="hljs-number">1.8431</span>, -<span class="hljs-number">1.8431</span>],
          [ <span class="hljs-number">1.3081</span>,  <span class="hljs-number">1.3081</span>,  <span class="hljs-number">1.3081</span>,  ..., -<span class="hljs-number">1.8431</span>, -<span class="hljs-number">1.8431</span>, -<span class="hljs-number">1.8431</span>],
          [ <span class="hljs-number">1.3081</span>,  <span class="hljs-number">1.3081</span>,  <span class="hljs-number">1.3081</span>,  ..., -<span class="hljs-number">1.8256</span>, -<span class="hljs-number">1.8256</span>, -<span class="hljs-number">1.8256</span>],
          ...,
          [-<span class="hljs-number">1.3179</span>, -<span class="hljs-number">1.3179</span>, -<span class="hljs-number">1.3179</span>,  ..., -<span class="hljs-number">1.8606</span>, -<span class="hljs-number">1.8606</span>, -<span class="hljs-number">1.8606</span>],
          [-<span class="hljs-number">1.3004</span>, -<span class="hljs-number">1.3004</span>, -<span class="hljs-number">1.3004</span>,  ..., -<span class="hljs-number">1.8606</span>, -<span class="hljs-number">1.8431</span>, -<span class="hljs-number">1.8431</span>],
          [-<span class="hljs-number">1.3004</span>, -<span class="hljs-number">1.3004</span>, -<span class="hljs-number">1.3004</span>,  ..., -<span class="hljs-number">1.8606</span>, -<span class="hljs-number">1.8431</span>, -<span class="hljs-number">1.8431</span>]],

         [[ <span class="hljs-number">1.4200</span>,  <span class="hljs-number">1.4200</span>,  <span class="hljs-number">1.4200</span>,  ..., -<span class="hljs-number">1.6476</span>, -<span class="hljs-number">1.6476</span>, -<span class="hljs-number">1.6476</span>],
          [ <span class="hljs-number">1.4200</span>,  <span class="hljs-number">1.4200</span>,  <span class="hljs-number">1.4200</span>,  ..., -<span class="hljs-number">1.6476</span>, -<span class="hljs-number">1.6476</span>, -<span class="hljs-number">1.6476</span>],
          [ <span class="hljs-number">1.4200</span>,  <span class="hljs-number">1.4200</span>,  <span class="hljs-number">1.4200</span>,  ..., -<span class="hljs-number">1.6302</span>, -<span class="hljs-number">1.6302</span>, -<span class="hljs-number">1.6302</span>],
          ...,
          [-<span class="hljs-number">1.0201</span>, -<span class="hljs-number">1.0201</span>, -<span class="hljs-number">1.0201</span>,  ..., -<span class="hljs-number">1.5604</span>, -<span class="hljs-number">1.5604</span>, -<span class="hljs-number">1.5604</span>],
          [-<span class="hljs-number">1.0027</span>, -<span class="hljs-number">1.0027</span>, -<span class="hljs-number">1.0027</span>,  ..., -<span class="hljs-number">1.5604</span>, -<span class="hljs-number">1.5430</span>, -<span class="hljs-number">1.5430</span>],
          [-<span class="hljs-number">1.0027</span>, -<span class="hljs-number">1.0027</span>, -<span class="hljs-number">1.0027</span>,  ..., -<span class="hljs-number">1.5604</span>, -<span class="hljs-number">1.5430</span>, -<span class="hljs-number">1.5430</span>]]]),
 <span class="hljs-string">&#x27;pixel_mask&#x27;</span>: tensor([[<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>,  ..., <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>],
         [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>,  ..., <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>],
         [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>,  ..., <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>],
         ...,
         [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>,  ..., <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>],
         [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>,  ..., <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>],
         [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>,  ..., <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>]]),
 <span class="hljs-string">&#x27;labels&#x27;</span>: {<span class="hljs-string">&#x27;size&#x27;</span>: tensor([<span class="hljs-number">800</span>, <span class="hljs-number">800</span>]), <span class="hljs-string">&#x27;image_id&#x27;</span>: tensor([<span class="hljs-number">756</span>]), <span class="hljs-string">&#x27;class_labels&#x27;</span>: tensor([<span class="hljs-number">4</span>]), <span class="hljs-string">&#x27;boxes&#x27;</span>: tensor([[<span class="hljs-number">0.7340</span>, <span class="hljs-number">0.6986</span>, <span class="hljs-number">0.3414</span>, <span class="hljs-number">0.5944</span>]]), <span class="hljs-string">&#x27;area&#x27;</span>: tensor([<span class="hljs-number">519544.4375</span>]), <span class="hljs-string">&#x27;iscrowd&#x27;</span>: tensor([<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>])}}`}}),ta=new J({props:{code:"ZGVmJTIwY29sbGF0ZV9mbihiYXRjaCklM0ElMEElMjAlMjAlMjAlMjBwaXhlbF92YWx1ZXMlMjAlM0QlMjAlNUJpdGVtJTVCJTIycGl4ZWxfdmFsdWVzJTIyJTVEJTIwZm9yJTIwaXRlbSUyMGluJTIwYmF0Y2glNUQlMEElMjAlMjAlMjAlMjBlbmNvZGluZyUyMCUzRCUyMGltYWdlX3Byb2Nlc3Nvci5wYWRfYW5kX2NyZWF0ZV9waXhlbF9tYXNrKHBpeGVsX3ZhbHVlcyUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBJTIwJTIwJTIwJTIwbGFiZWxzJTIwJTNEJTIwJTVCaXRlbSU1QiUyMmxhYmVscyUyMiU1RCUyMGZvciUyMGl0ZW0lMjBpbiUyMGJhdGNoJTVEJTBBJTIwJTIwJTIwJTIwYmF0Y2glMjAlM0QlMjAlN0IlN0QlMEElMjAlMjAlMjAlMjBiYXRjaCU1QiUyMnBpeGVsX3ZhbHVlcyUyMiU1RCUyMCUzRCUyMGVuY29kaW5nJTVCJTIycGl4ZWxfdmFsdWVzJTIyJTVEJTBBJTIwJTIwJTIwJTIwYmF0Y2glNUIlMjJwaXhlbF9tYXNrJTIyJTVEJTIwJTNEJTIwZW5jb2RpbmclNUIlMjJwaXhlbF9tYXNrJTIyJTVEJTBBJTIwJTIwJTIwJTIwYmF0Y2glNUIlMjJsYWJlbHMlMjIlNUQlMjAlM0QlMjBsYWJlbHMlMEElMjAlMjAlMjAlMjByZXR1cm4lMjBiYXRjaA==",highlighted:`<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>    pixel_values = [item[<span class="hljs-string">&quot;pixel_values&quot;</span>] <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> batch]
<span class="hljs-meta">... </span>    encoding = image_processor.pad_and_create_pixel_mask(pixel_values, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">... </span>    labels = [item[<span class="hljs-string">&quot;labels&quot;</span>] <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> batch]
<span class="hljs-meta">... </span>    batch = {}
<span class="hljs-meta">... </span>    batch[<span class="hljs-string">&quot;pixel_values&quot;</span>] = encoding[<span class="hljs-string">&quot;pixel_values&quot;</span>]
<span class="hljs-meta">... </span>    batch[<span class="hljs-string">&quot;pixel_mask&quot;</span>] = encoding[<span class="hljs-string">&quot;pixel_mask&quot;</span>]
<span class="hljs-meta">... </span>    batch[<span class="hljs-string">&quot;labels&quot;</span>] = labels
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> batch`}}),na=new ul({}),ca=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvck9iamVjdERldGVjdGlvbiUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yT2JqZWN0RGV0ZWN0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBjaGVja3BvaW50JTJDJTBBJTIwJTIwJTIwJTIwaWQybGFiZWwlM0RpZDJsYWJlbCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsMmlkJTNEbGFiZWwyaWQlMkMlMEElMjAlMjAlMjAlMjBpZ25vcmVfbWlzbWF0Y2hlZF9zaXplcyUzRFRydWUlMkMlMEEp",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>    checkpoint,
<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>)`}}),ha=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTBBJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0QlMjJkZXRyLXJlc25ldC01MF9maW5ldHVuZWRfY3BwZTUlMjIlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX3RyYWluX2JhdGNoX3NpemUlM0Q4JTJDJTBBJTIwJTIwJTIwJTIwbnVtX3RyYWluX2Vwb2NocyUzRDEwJTJDJTBBJTIwJTIwJTIwJTIwZnAxNiUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBzYXZlX3N0ZXBzJTNEMjAwJTJDJTBBJTIwJTIwJTIwJTIwbG9nZ2luZ19zdGVwcyUzRDUwJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDFlLTUlMkMlMEElMjAlMjAlMjAlMjB3ZWlnaHRfZGVjYXklM0QxZS00JTJDJTBBJTIwJTIwJTIwJTIwc2F2ZV90b3RhbF9saW1pdCUzRDIlMkMlMEElMjAlMjAlMjAlMjByZW1vdmVfdW51c2VkX2NvbHVtbnMlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMHB1c2hfdG9faHViJTNEVHJ1ZSUyQyUwQSk=",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-resnet-50_finetuned_cppe5&quot;</span>,
<span class="hljs-meta">... </span>    per_device_train_batch_size=<span class="hljs-number">8</span>,
<span class="hljs-meta">... </span>    num_train_epochs=<span class="hljs-number">10</span>,
<span class="hljs-meta">... </span>    fp16=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    save_steps=<span class="hljs-number">200</span>,
<span class="hljs-meta">... </span>    logging_steps=<span class="hljs-number">50</span>,
<span class="hljs-meta">... </span>    learning_rate=<span class="hljs-number">1e-5</span>,
<span class="hljs-meta">... </span>    weight_decay=<span class="hljs-number">1e-4</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>    push_to_hub=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>)`}}),ma=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXIlMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRHRyYWluaW5nX2FyZ3MlMkMlMEElMjAlMjAlMjAlMjBkYXRhX2NvbGxhdG9yJTNEY29sbGF0ZV9mbiUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0RjcHBlNSU1QiUyMnRyYWluJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwdG9rZW5pemVyJTNEaW1hZ2VfcHJvY2Vzc29yJTJDJTBBKSUwQSUwQXRyYWluZXIudHJhaW4oKQ==",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>    data_collator=collate_fn,
<span class="hljs-meta">... </span>    train_dataset=cppe5[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    tokenizer=image_processor,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()`}}),ua=new J({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()'}}),ja=new ul({}),da=new J({props:{code:" ",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> json


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># format annotations the same as for training, no need for data augmentation</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">val_formatted_anns</span>(<span class="hljs-params">image_id, objects</span>):
<span class="hljs-meta">... </span>    annotations = []
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, <span class="hljs-built_in">len</span>(objects[<span class="hljs-string">&quot;id&quot;</span>])):
<span class="hljs-meta">... </span>        new_ann = {
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;id&quot;</span>: objects[<span class="hljs-string">&quot;id&quot;</span>][i],
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;category_id&quot;</span>: objects[<span class="hljs-string">&quot;category&quot;</span>][i],
<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;image_id&quot;</span>: image_id,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;area&quot;</span>: objects[<span class="hljs-string">&quot;area&quot;</span>][i],
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;bbox&quot;</span>: objects[<span class="hljs-string">&quot;bbox&quot;</span>][i],
<span class="hljs-meta">... </span>        }
<span class="hljs-meta">... </span>        annotations.append(new_ann)

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


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Save images and annotations into the files torchvision.datasets.CocoDetection expects</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">save_cppe5_annotation_file_images</span>(<span class="hljs-params">cppe5</span>):
<span class="hljs-meta">... </span>    output_json = {}
<span class="hljs-meta">... </span>    path_output_cppe5 = <span class="hljs-string">f&quot;<span class="hljs-subst">{os.getcwd()}</span>/cppe5/&quot;</span>

<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.exists(path_output_cppe5):
<span class="hljs-meta">... </span>        os.makedirs(path_output_cppe5)

<span class="hljs-meta">... </span>    path_anno = os.path.join(path_output_cppe5, <span class="hljs-string">&quot;cppe5_ann.json&quot;</span>)
<span class="hljs-meta">... </span>    categories_json = [{<span class="hljs-string">&quot;supercategory&quot;</span>: <span class="hljs-string">&quot;none&quot;</span>, <span class="hljs-string">&quot;id&quot;</span>: <span class="hljs-built_in">id</span>, <span class="hljs-string">&quot;name&quot;</span>: id2label[<span class="hljs-built_in">id</span>]} <span class="hljs-keyword">for</span> <span class="hljs-built_in">id</span> <span class="hljs-keyword">in</span> id2label]
<span class="hljs-meta">... </span>    output_json[<span class="hljs-string">&quot;images&quot;</span>] = []
<span class="hljs-meta">... </span>    output_json[<span class="hljs-string">&quot;annotations&quot;</span>] = []
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> example <span class="hljs-keyword">in</span> cppe5:
<span class="hljs-meta">... </span>        ann = val_formatted_anns(example[<span class="hljs-string">&quot;image_id&quot;</span>], example[<span class="hljs-string">&quot;objects&quot;</span>])
<span class="hljs-meta">... </span>        output_json[<span class="hljs-string">&quot;images&quot;</span>].append(
<span class="hljs-meta">... </span>            {
<span class="hljs-meta">... </span>                <span class="hljs-string">&quot;id&quot;</span>: example[<span class="hljs-string">&quot;image_id&quot;</span>],
<span class="hljs-meta">... </span>                <span class="hljs-string">&quot;width&quot;</span>: example[<span class="hljs-string">&quot;image&quot;</span>].width,
<span class="hljs-meta">... </span>                <span class="hljs-string">&quot;height&quot;</span>: example[<span class="hljs-string">&quot;image&quot;</span>].height,
<span class="hljs-meta">... </span>                <span class="hljs-string">&quot;file_name&quot;</span>: <span class="hljs-string">f&quot;<span class="hljs-subst">{example[<span class="hljs-string">&#x27;image_id&#x27;</span>]}</span>.png&quot;</span>,
<span class="hljs-meta">... </span>            }
<span class="hljs-meta">... </span>        )
<span class="hljs-meta">... </span>        output_json[<span class="hljs-string">&quot;annotations&quot;</span>].extend(ann)
<span class="hljs-meta">... </span>    output_json[<span class="hljs-string">&quot;categories&quot;</span>] = categories_json

<span class="hljs-meta">... </span>    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(path_anno, <span class="hljs-string">&quot;w&quot;</span>) <span class="hljs-keyword">as</span> file:
<span class="hljs-meta">... </span>        json.dump(output_json, file, ensure_ascii=<span class="hljs-literal">False</span>, indent=<span class="hljs-number">4</span>)

<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> im, img_id <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(cppe5[<span class="hljs-string">&quot;image&quot;</span>], cppe5[<span class="hljs-string">&quot;image_id&quot;</span>]):
<span class="hljs-meta">... </span>        path_img = os.path.join(path_output_cppe5, <span class="hljs-string">f&quot;<span class="hljs-subst">{img_id}</span>.png&quot;</span>)
<span class="hljs-meta">... </span>        im.save(path_img)

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> path_output_cppe5, path_anno`}}),ya=new J({props:{code:"aW1wb3J0JTIwdG9yY2h2aXNpb24lMEElMEElMEFjbGFzcyUyMENvY29EZXRlY3Rpb24odG9yY2h2aXNpb24uZGF0YXNldHMuQ29jb0RldGVjdGlvbiklM0ElMEElMjAlMjAlMjAlMjBkZWYlMjBfX2luaXRfXyhzZWxmJTJDJTIwaW1nX2ZvbGRlciUyQyUyMGZlYXR1cmVfZXh0cmFjdG9yJTJDJTIwYW5uX2ZpbGUpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc3VwZXIoKS5fX2luaXRfXyhpbWdfZm9sZGVyJTJDJTIwYW5uX2ZpbGUpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2VsZi5mZWF0dXJlX2V4dHJhY3RvciUyMCUzRCUyMGZlYXR1cmVfZXh0cmFjdG9yJTBBJTBBJTIwJTIwJTIwJTIwZGVmJTIwX19nZXRpdGVtX18oc2VsZiUyQyUyMGlkeCklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjByZWFkJTIwaW4lMjBQSUwlMjBpbWFnZSUyMGFuZCUyMHRhcmdldCUyMGluJTIwQ09DTyUyMGZvcm1hdCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGltZyUyQyUyMHRhcmdldCUyMCUzRCUyMHN1cGVyKENvY29EZXRlY3Rpb24lMkMlMjBzZWxmKS5fX2dldGl0ZW1fXyhpZHgpJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwcHJlcHJvY2VzcyUyMGltYWdlJTIwYW5kJTIwdGFyZ2V0JTNBJTIwY29udmVydGluZyUyMHRhcmdldCUyMHRvJTIwREVUUiUyMGZvcm1hdCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyMHJlc2l6aW5nJTIwJTJCJTIwbm9ybWFsaXphdGlvbiUyMG9mJTIwYm90aCUyMGltYWdlJTIwYW5kJTIwdGFyZ2V0KSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGltYWdlX2lkJTIwJTNEJTIwc2VsZi5pZHMlNUJpZHglNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0YXJnZXQlMjAlM0QlMjAlN0IlMjJpbWFnZV9pZCUyMiUzQSUyMGltYWdlX2lkJTJDJTIwJTIyYW5ub3RhdGlvbnMlMjIlM0ElMjB0YXJnZXQlN0QlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBlbmNvZGluZyUyMCUzRCUyMHNlbGYuZmVhdHVyZV9leHRyYWN0b3IoaW1hZ2VzJTNEaW1nJTJDJTIwYW5ub3RhdGlvbnMlM0R0YXJnZXQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHBpeGVsX3ZhbHVlcyUyMCUzRCUyMGVuY29kaW5nJTVCJTIycGl4ZWxfdmFsdWVzJTIyJTVELnNxdWVlemUoKSUyMCUyMCUyMyUyMHJlbW92ZSUyMGJhdGNoJTIwZGltZW5zaW9uJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdGFyZ2V0JTIwJTNEJTIwZW5jb2RpbmclNUIlMjJsYWJlbHMlMjIlNUQlNUIwJTVEJTIwJTIwJTIzJTIwcmVtb3ZlJTIwYmF0Y2glMjBkaW1lbnNpb24lMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXR1cm4lMjAlN0IlMjJwaXhlbF92YWx1ZXMlMjIlM0ElMjBwaXhlbF92YWx1ZXMlMkMlMjAlMjJsYWJlbHMlMjIlM0ElMjB0YXJnZXQlN0QlMEElMEElMEFpbV9wcm9jZXNzb3IlMjAlM0QlMjBBdXRvSW1hZ2VQcm9jZXNzb3IuZnJvbV9wcmV0cmFpbmVkKCUyMk1hcmlhSyUyRmRldHItcmVzbmV0LTUwX2ZpbmV0dW5lZF9jcHBlNSUyMiklMEElMEFwYXRoX291dHB1dF9jcHBlNSUyQyUyMHBhdGhfYW5ubyUyMCUzRCUyMHNhdmVfY3BwZTVfYW5ub3RhdGlvbl9maWxlX2ltYWdlcyhjcHBlNSU1QiUyMnRlc3QlMjIlNUQpJTBBdGVzdF9kc19jb2NvX2Zvcm1hdCUyMCUzRCUyMENvY29EZXRlY3Rpb24ocGF0aF9vdXRwdXRfY3BwZTUlMkMlMjBpbV9wcm9jZXNzb3IlMkMlMjBwYXRoX2Fubm8p",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torchvision


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">class</span> <span class="hljs-title class_">CocoDetection</span>(torchvision.datasets.CocoDetection):
<span class="hljs-meta">... </span>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, img_folder, feature_extractor, ann_file</span>):
<span class="hljs-meta">... </span>        <span class="hljs-built_in">super</span>().__init__(img_folder, ann_file)
<span class="hljs-meta">... </span>        self.feature_extractor = feature_extractor

<span class="hljs-meta">... </span>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__getitem__</span>(<span class="hljs-params">self, idx</span>):
<span class="hljs-meta">... </span>        <span class="hljs-comment"># read in PIL image and target in COCO format</span>
<span class="hljs-meta">... </span>        img, target = <span class="hljs-built_in">super</span>(CocoDetection, self).__getitem__(idx)

<span class="hljs-meta">... </span>        <span class="hljs-comment"># preprocess image and target: converting target to DETR format,</span>
<span class="hljs-meta">... </span>        <span class="hljs-comment"># resizing + normalization of both image and target)</span>
<span class="hljs-meta">... </span>        image_id = self.ids[idx]
<span class="hljs-meta">... </span>        target = {<span class="hljs-string">&quot;image_id&quot;</span>: image_id, <span class="hljs-string">&quot;annotations&quot;</span>: target}
<span class="hljs-meta">... </span>        encoding = self.feature_extractor(images=img, annotations=target, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">... </span>        pixel_values = encoding[<span class="hljs-string">&quot;pixel_values&quot;</span>].squeeze()  <span class="hljs-comment"># remove batch dimension</span>
<span class="hljs-meta">... </span>        target = encoding[<span class="hljs-string">&quot;labels&quot;</span>][<span class="hljs-number">0</span>]  <span class="hljs-comment"># remove batch dimension</span>

<span class="hljs-meta">... </span>        <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;pixel_values&quot;</span>: pixel_values, <span class="hljs-string">&quot;labels&quot;</span>: target}


<span class="hljs-meta">&gt;&gt;&gt; </span>im_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;MariaK/detr-resnet-50_finetuned_cppe5&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>path_output_cppe5, path_anno = save_cppe5_annotation_file_images(cppe5[<span class="hljs-string">&quot;test&quot;</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>test_ds_coco_format = CocoDetection(path_output_cppe5, im_processor, path_anno)`}}),ba=new J({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEFmcm9tJTIwdHFkbSUyMGltcG9ydCUyMHRxZG0lMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvck9iamVjdERldGVjdGlvbi5mcm9tX3ByZXRyYWluZWQoJTIyTWFyaWFLJTJGZGV0ci1yZXNuZXQtNTBfZmluZXR1bmVkX2NwcGU1JTIyKSUwQW1vZHVsZSUyMCUzRCUyMGV2YWx1YXRlLmxvYWQoJTIyeWJlbGthZGElMkZjb2NvZXZhbHVhdGUlMjIlMkMlMjBjb2NvJTNEdGVzdF9kc19jb2NvX2Zvcm1hdC5jb2NvKSUwQXZhbF9kYXRhbG9hZGVyJTIwJTNEJTIwdG9yY2gudXRpbHMuZGF0YS5EYXRhTG9hZGVyKCUwQSUyMCUyMCUyMCUyMHRlc3RfZHNfY29jb19mb3JtYXQlMkMlMjBiYXRjaF9zaXplJTNEOCUyQyUyMHNodWZmbGUlM0RGYWxzZSUyQyUyMG51bV93b3JrZXJzJTNENCUyQyUyMGNvbGxhdGVfZm4lM0Rjb2xsYXRlX2ZuJTBBKSUwQSUwQXdpdGglMjB0b3JjaC5ub19ncmFkKCklM0ElMEElMjAlMjAlMjAlMjBmb3IlMjBpZHglMkMlMjBiYXRjaCUyMGluJTIwZW51bWVyYXRlKHRxZG0odmFsX2RhdGFsb2FkZXIpKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHBpeGVsX3ZhbHVlcyUyMCUzRCUyMGJhdGNoJTVCJTIycGl4ZWxfdmFsdWVzJTIyJTVEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcGl4ZWxfbWFzayUyMCUzRCUyMGJhdGNoJTVCJTIycGl4ZWxfbWFzayUyMiU1RCUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QmslM0ElMjB2JTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMHQuaXRlbXMoKSU3RCUyMGZvciUyMHQlMjBpbiUyMGJhdGNoJTVCJTIybGFiZWxzJTIyJTVEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTVEJTIwJTIwJTIzJTIwdGhlc2UlMjBhcmUlMjBpbiUyMERFVFIlMjBmb3JtYXQlMkMlMjByZXNpemVkJTIwJTJCJTIwbm9ybWFsaXplZCUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyMGZvcndhcmQlMjBwYXNzJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwb3V0cHV0cyUyMCUzRCUyMG1vZGVsKHBpeGVsX3ZhbHVlcyUzRHBpeGVsX3ZhbHVlcyUyQyUyMHBpeGVsX21hc2slM0RwaXhlbF9tYXNrKSUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG9yaWdfdGFyZ2V0X3NpemVzJTIwJTNEJTIwdG9yY2guc3RhY2soJTVCdGFyZ2V0JTVCJTIyb3JpZ19zaXplJTIyJTVEJTIwZm9yJTIwdGFyZ2V0JTIwaW4lMjBsYWJlbHMlNUQlMkMlMjBkaW0lM0QwKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJlc3VsdHMlMjAlM0QlMjBpbV9wcm9jZXNzb3IucG9zdF9wcm9jZXNzKG91dHB1dHMlMkMlMjBvcmlnX3RhcmdldF9zaXplcyklMjAlMjAlMjMlMjBjb252ZXJ0JTIwb3V0cHV0cyUyMG9mJTIwbW9kZWwlMjB0byUyMENPQ08lMjBhcGklMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBtb2R1bGUuYWRkKHByZWRpY3Rpb24lM0RyZXN1bHRzJTJDJTIwcmVmZXJlbmNlJTNEbGFiZWxzKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGRlbCUyMGJhdGNoJTBBJTBBcmVzdWx0cyUyMCUzRCUyMG1vZHVsZS5jb21wdXRlKCklMEFwcmludChyZXN1bHRzKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> evaluate
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> tqdm <span class="hljs-keyword">import</span> tqdm

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForObjectDetection.from_pretrained(<span class="hljs-string">&quot;MariaK/detr-resnet-50_finetuned_cppe5&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>module = evaluate.load(<span class="hljs-string">&quot;ybelkada/cocoevaluate&quot;</span>, coco=test_ds_coco_format.coco)
<span class="hljs-meta">&gt;&gt;&gt; </span>val_dataloader = torch.utils.data.DataLoader(
<span class="hljs-meta">... </span>    test_ds_coco_format, batch_size=<span class="hljs-number">8</span>, shuffle=<span class="hljs-literal">False</span>, num_workers=<span class="hljs-number">4</span>, collate_fn=collate_fn
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> idx, batch <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(tqdm(val_dataloader)):
<span class="hljs-meta">... </span>        pixel_values = batch[<span class="hljs-string">&quot;pixel_values&quot;</span>]
<span class="hljs-meta">... </span>        pixel_mask = batch[<span class="hljs-string">&quot;pixel_mask&quot;</span>]

<span class="hljs-meta">... </span>        labels = [
<span class="hljs-meta">... </span>            {k: v <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> t.items()} <span class="hljs-keyword">for</span> t <span class="hljs-keyword">in</span> batch[<span class="hljs-string">&quot;labels&quot;</span>]
<span class="hljs-meta">... </span>        ]  <span class="hljs-comment"># these are in DETR format, resized + normalized</span>

<span class="hljs-meta">... </span>        <span class="hljs-comment"># forward pass</span>
<span class="hljs-meta">... </span>        outputs = model(pixel_values=pixel_values, pixel_mask=pixel_mask)

<span class="hljs-meta">... </span>        orig_target_sizes = torch.stack([target[<span class="hljs-string">&quot;orig_size&quot;</span>] <span class="hljs-keyword">for</span> target <span class="hljs-keyword">in</span> labels], dim=<span class="hljs-number">0</span>)
<span class="hljs-meta">... </span>        results = im_processor.post_process(outputs, orig_target_sizes)  <span class="hljs-comment"># convert outputs of model to COCO api</span>

<span class="hljs-meta">... </span>        module.add(prediction=results, reference=labels)
<span class="hljs-meta">... </span>        <span class="hljs-keyword">del</span> batch

<span class="hljs-meta">&gt;&gt;&gt; </span>results = module.compute()
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(results)
Accumulating evaluation results...
DONE (t=<span class="hljs-number">0.08</span>s).
IoU metric: bbox
 Average Precision  (AP) @[ IoU=<span class="hljs-number">0.50</span>:<span class="hljs-number">0.95</span> | area=   <span class="hljs-built_in">all</span> | maxDets=<span class="hljs-number">100</span> ] = <span class="hljs-number">0.150</span>
 Average Precision  (AP) @[ IoU=<span class="hljs-number">0.50</span>      | area=   <span class="hljs-built_in">all</span> | maxDets=<span class="hljs-number">100</span> ] = <span class="hljs-number">0.280</span>
 Average Precision  (AP) @[ IoU=<span class="hljs-number">0.75</span>      | area=   <span class="hljs-built_in">all</span> | maxDets=<span class="hljs-number">100</span> ] = <span class="hljs-number">0.130</span>
 Average Precision  (AP) @[ IoU=<span class="hljs-number">0.50</span>:<span class="hljs-number">0.95</span> | area= small | maxDets=<span class="hljs-number">100</span> ] = <span class="hljs-number">0.038</span>
 Average Precision  (AP) @[ IoU=<span class="hljs-number">0.50</span>:<span class="hljs-number">0.95</span> | area=medium | maxDets=<span class="hljs-number">100</span> ] = <span class="hljs-number">0.036</span>
 Average Precision  (AP) @[ IoU=<span class="hljs-number">0.50</span>:<span class="hljs-number">0.95</span> | area= large | maxDets=<span class="hljs-number">100</span> ] = <span class="hljs-number">0.182</span>
 Average Recall     (AR) @[ IoU=<span class="hljs-number">0.50</span>:<span class="hljs-number">0.95</span> | area=   <span class="hljs-built_in">all</span> | maxDets=  <span class="hljs-number">1</span> ] = <span class="hljs-number">0.166</span>
 Average Recall     (AR) @[ IoU=<span class="hljs-number">0.50</span>:<span class="hljs-number">0.95</span> | area=   <span class="hljs-built_in">all</span> | maxDets= <span class="hljs-number">10</span> ] = <span class="hljs-number">0.317</span>
 Average Recall     (AR) @[ IoU=<span class="hljs-number">0.50</span>:<span class="hljs-number">0.95</span> | area=   <span class="hljs-built_in">all</span> | maxDets=<span class="hljs-number">100</span> ] = <span class="hljs-number">0.335</span>
 Average Recall     (AR) @[ IoU=<span class="hljs-number">0.50</span>:<span class="hljs-number">0.95</span> | area= small | maxDets=<span class="hljs-number">100</span> ] = <span class="hljs-number">0.104</span>
 Average Recall     (AR) @[ IoU=<span class="hljs-number">0.50</span>:<span class="hljs-number">0.95</span> | area=medium | maxDets=<span class="hljs-number">100</span> ] = <span class="hljs-number">0.146</span>
 Average Recall     (AR) @[ IoU=<span class="hljs-number">0.50</span>:<span class="hljs-number">0.95</span> | area= large | maxDets=<span class="hljs-number">100</span> ] = <span class="hljs-number">0.382</span>`}}),Ja=new ul({}),wa=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBaW1wb3J0JTIwcmVxdWVzdHMlMEElMEF1cmwlMjAlM0QlMjAlMjJodHRwcyUzQSUyRiUyRmkuaW1ndXIuY29tJTJGMmxuV29seS5qcGclMjIlMEFpbWFnZSUyMCUzRCUyMEltYWdlLm9wZW4ocmVxdWVzdHMuZ2V0KHVybCUyQyUyMHN0cmVhbSUzRFRydWUpLnJhdyklMEElMEFvYmpfZGV0ZWN0b3IlMjAlM0QlMjBwaXBlbGluZSglMjJvYmplY3QtZGV0ZWN0aW9uJTIyJTJDJTIwbW9kZWwlM0QlMjJNYXJpYUslMkZkZXRyLXJlc25ldC01MF9maW5ldHVuZWRfY3BwZTUlMjIpJTBBb2JqX2RldGVjdG9yKGltYWdlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests

<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;https://i.imgur.com/2lnWoly.jpg&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)

<span class="hljs-meta">&gt;&gt;&gt; </span>obj_detector = pipeline(<span class="hljs-string">&quot;object-detection&quot;</span>, model=<span class="hljs-string">&quot;MariaK/detr-resnet-50_finetuned_cppe5&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>obj_detector(image)`}}),fa=new J({props:{code:"aW1hZ2VfcHJvY2Vzc29yJTIwJTNEJTIwQXV0b0ltYWdlUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCglMjJNYXJpYUslMkZkZXRyLXJlc25ldC01MF9maW5ldHVuZWRfY3BwZTUlMjIpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JPYmplY3REZXRlY3Rpb24uZnJvbV9wcmV0cmFpbmVkKCUyMk1hcmlhSyUyRmRldHItcmVzbmV0LTUwX2ZpbmV0dW5lZF9jcHBlNSUyMiklMEElMEF3aXRoJTIwdG9yY2gubm9fZ3JhZCgpJTNBJTBBJTIwJTIwJTIwJTIwaW5wdXRzJTIwJTNEJTIwaW1hZ2VfcHJvY2Vzc29yKGltYWdlcyUzRGltYWdlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMpJTBBJTIwJTIwJTIwJTIwdGFyZ2V0X3NpemVzJTIwJTNEJTIwdG9yY2gudGVuc29yKCU1QmltYWdlLnNpemUlNUIlM0ElM0EtMSU1RCU1RCklMEElMjAlMjAlMjAlMjByZXN1bHRzJTIwJTNEJTIwaW1hZ2VfcHJvY2Vzc29yLnBvc3RfcHJvY2Vzc19vYmplY3RfZGV0ZWN0aW9uKG91dHB1dHMlMkMlMjB0aHJlc2hvbGQlM0QwLjUlMkMlMjB0YXJnZXRfc2l6ZXMlM0R0YXJnZXRfc2l6ZXMpJTVCMCU1RCUwQSUwQWZvciUyMHNjb3JlJTJDJTIwbGFiZWwlMkMlMjBib3glMjBpbiUyMHppcChyZXN1bHRzJTVCJTIyc2NvcmVzJTIyJTVEJTJDJTIwcmVzdWx0cyU1QiUyMmxhYmVscyUyMiU1RCUyQyUyMHJlc3VsdHMlNUIlMjJib3hlcyUyMiU1RCklM0ElMEElMjAlMjAlMjAlMjBib3glMjAlM0QlMjAlNUJyb3VuZChpJTJDJTIwMiklMjBmb3IlMjBpJTIwaW4lMjBib3gudG9saXN0KCklNUQlMEElMjAlMjAlMjAlMjBwcmludCglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmJTIyRGV0ZWN0ZWQlMjAlN0Jtb2RlbC5jb25maWcuaWQybGFiZWwlNUJsYWJlbC5pdGVtKCklNUQlN0QlMjB3aXRoJTIwY29uZmlkZW5jZSUyMCUyMiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGYlMjIlN0Jyb3VuZChzY29yZS5pdGVtKCklMkMlMjAzKSU3RCUyMGF0JTIwbG9jYXRpb24lMjAlN0Jib3glN0QlMjIlMEElMjAlMjAlMjAlMjAp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;MariaK/detr-resnet-50_finetuned_cppe5&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForObjectDetection.from_pretrained(<span class="hljs-string">&quot;MariaK/detr-resnet-50_finetuned_cppe5&quot;</span>)

<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)
<span class="hljs-meta">... </span>    target_sizes = torch.tensor([image.size[::-<span class="hljs-number">1</span>]])
<span class="hljs-meta">... </span>    results = image_processor.post_process_object_detection(outputs, threshold=<span class="hljs-number">0.5</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 Coverall <span class="hljs-keyword">with</span> confidence <span class="hljs-number">0.566</span> at location [<span class="hljs-number">1215.32</span>, <span class="hljs-number">147.38</span>, <span class="hljs-number">4401.81</span>, <span class="hljs-number">3227.08</span>]
Detected Mask <span class="hljs-keyword">with</span> confidence <span class="hljs-number">0.584</span> at location [<span class="hljs-number">2449.06</span>, <span class="hljs-number">823.19</span>, <span class="hljs-number">3256.43</span>, <span class="hljs-number">1413.9</span>]`}}),Ta=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`}}),{c(){_=n("meta"),w=c(),g=n("h1"),k=n("a"),ns=n("span"),u(v.$$.fragment),Ws=c(),ps=n("span"),$=e("Object detection"),ms=c(),u(X.$$.fragment),Y=c(),z=n("p"),Rs=e(`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.`),N=c(),S=n("p"),Vs=e("In this guide, you will learn how to:"),F=c(),B=n("ol"),U=n("li"),T=e("Finetune "),H=n("a"),Ia=e("DETR"),Ca=e(`, a model that combines a convolutional
backbone with an encoder-decoder Transformer, on the `),D=n("a"),_a=e("CPPE-5"),va=e(`
dataset.`),un=c(),jl=n("li"),jn=e("Use your finetuned model for inference."),Ae=c(),u(us.$$.fragment),ke=c(),Ea=n("p"),Mn=e("Before you begin, make sure you have all the necessary libraries installed:"),Be=c(),u(Qs.$$.fragment),Ge=c(),P=n("p"),dn=e(`You\u2019ll use \u{1F917} Datasets to load a dataset from the Hugging Face Hub, \u{1F917} Transformers to train your model,
and `),Ml=n("code"),yn=e("albumentations"),bn=e(" to augment the data. "),dl=n("code"),Jn=e("timm"),wn=e(" is currently required to load a convolutional backbone for the DETR model."),We=c(),Za=n("p"),fn=e(`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:`),Re=c(),u(xs.$$.fragment),Ve=c(),os=n("h2"),js=n("a"),yl=n("span"),u(Xs.$$.fragment),Tn=c(),bl=n("span"),Un=e("Load the CPPE-5 dataset"),Qe=c(),Ms=n("p"),gn=e("The "),Ys=n("a"),In=e("CPPE-5 dataset"),Cn=e(` contains images with
annotations identifying medical personal protective equipment (PPE) in the context of the COVID-19 pandemic.`),xe=c(),Aa=n("p"),_n=e("Start by loading the dataset:"),Xe=c(),u(Ns.$$.fragment),Ye=c(),ka=n("p"),vn=e("You\u2019ll see that this dataset already comes with a training set containing 1000 images and a test set with 29 images."),Ne=c(),Ba=n("p"),En=e("To get familiar with the data, explore what the examples look like."),Fe=c(),u(Fs.$$.fragment),qe=c(),Ga=n("p"),Zn=e("The examples in the dataset have the following fields:"),$e=c(),E=n("ul"),Wa=n("li"),Jl=n("code"),An=e("image_id"),kn=e(": the example image id"),Bn=c(),ds=n("li"),wl=n("code"),Gn=e("image"),Wn=e(": a "),fl=n("code"),Rn=e("PIL.Image.Image"),Vn=e(" object containing the image"),Qn=c(),Ra=n("li"),Tl=n("code"),xn=e("width"),Xn=e(": width of the image"),Yn=c(),Va=n("li"),Ul=n("code"),Nn=e("height"),Fn=e(": height of the image"),qn=c(),qs=n("li"),gl=n("code"),$n=e("objects"),zn=e(": a dictionary containing bounding box metadata for the objects in the image:"),q=n("ul"),Qa=n("li"),Il=n("code"),Sn=e("id"),Hn=e(": the annotation id"),Dn=c(),xa=n("li"),Cl=n("code"),Pn=e("area"),On=e(": the area of the bounding box"),Kn=c(),ys=n("li"),_l=n("code"),Ln=e("bbox"),sp=e(": the object\u2019s bounding box (in the "),$s=n("a"),ap=e("COCO format"),lp=e(" )"),ep=c(),C=n("li"),vl=n("code"),tp=e("category"),np=e(": the object\u2019s category, with possible values including "),El=n("code"),pp=e("Coverall (0)"),op=e(", "),Zl=n("code"),rp=e("Face_Shield (1)"),ip=e(", "),Al=n("code"),cp=e("Gloves (2)"),hp=e(", "),kl=n("code"),mp=e("Goggles (3)"),up=e(" and "),Bl=n("code"),jp=e("Mask (4)"),ze=c(),O=n("p"),Mp=e("You may notice that the "),Gl=n("code"),dp=e("bbox"),yp=e(` field follows the COCO format, which is the format that the DETR model expects.
However, the grouping of the fields inside `),Wl=n("code"),bp=e("objects"),Jp=e(` differs from the annotation format DETR requires. You will
need to apply some preprocessing transformations before using this data for training.`),Se=c(),Xa=n("p"),wp=e("To get an even better understanding of the data, visualize an example in the dataset."),He=c(),u(zs.$$.fragment),De=c(),Ss=n("div"),Ya=n("img"),Pe=c(),G=n("p"),fp=e(`To visualize the bounding boxes with associated labels, you can get the labels from the dataset\u2019s metadata, specifically
the `),Rl=n("code"),Tp=e("category"),Up=e(` field.
You\u2019ll also want to create dictionaries that map a label id to a label class (`),Vl=n("code"),gp=e("id2label"),Ip=e(") and the other way around ("),Ql=n("code"),Cp=e("label2id"),_p=e(`).
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.`),Oe=c(),Na=n("p"),vp=e(`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 \u201Cstretch\u201D beyond the edge of the image. Such \u201Crunaway\u201D bounding boxes can raise
errors during training and should be addressed at this stage. There are a few examples with this issue in this dataset.
To keep things simple in this guide, we remove these images from the data.`),Ke=c(),u(Hs.$$.fragment),Le=c(),rs=n("h2"),bs=n("a"),xl=n("span"),u(Ds.$$.fragment),Ep=c(),Xl=n("span"),Zp=e("Preprocess the data"),st=c(),Z=n("p"),Ap=e(`To finetune a model, you must preprocess the data you plan to use to match precisely the approach used for the pre-trained model.
`),Fa=n("a"),kp=e("AutoImageProcessor"),Bp=e(" takes care of processing image data to create "),Yl=n("code"),Gp=e("pixel_values"),Wp=e(", "),Nl=n("code"),Rp=e("pixel_mask"),Vp=e(`, and
`),Fl=n("code"),Qp=e("labels"),xp=e(" that a DETR model can train with. The image processor has some attributes that you won\u2019t have to worry about:"),at=c(),Js=n("ul"),ql=n("li"),$l=n("code"),Xp=e("image_mean = [0.485, 0.456, 0.406 ]"),Yp=c(),zl=n("li"),Sl=n("code"),Np=e("image_std = [0.229, 0.224, 0.225]"),lt=c(),qa=n("p"),Fp=e(`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.`),et=c(),$a=n("p"),qp=e("Instantiate the image processor from the same checkpoint as the model you want to finetune."),tt=c(),u(Ps.$$.fragment),nt=c(),ws=n("p"),$p=e("Before passing the images to the "),Hl=n("code"),zp=e("image_processor"),Sp=e(", apply two preprocessing transformations to the dataset:"),pt=c(),fs=n("ul"),Dl=n("li"),Hp=e("Augmenting images"),Dp=c(),Pl=n("li"),Pp=e("Reformatting annotations to meet DETR expectations"),ot=c(),K=n("p"),Op=e("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 "),Os=n("a"),Kp=e("Albumentations"),Lp=e(` \u2026
This library ensures that transformations affect the image and update the bounding boxes accordingly.
The \u{1F917} Datasets library documentation has a detailed `),Ks=n("a"),so=e("guide on how to augment images for object detection"),ao=e(`,
and it uses the exact same dataset as an example. Apply the same approach here, resize each image to (480, 480),
flip it horizontally, and brighten it:`),rt=c(),u(Ls.$$.fragment),it=c(),L=n("p"),lo=e("The "),Ol=n("code"),eo=e("image_processor"),to=e(" expects the annotations to be in the following format: "),Kl=n("code"),no=e("{'image_id': int, 'annotations': List[Dict]}"),po=e(`,
where each dictionary is a COCO object annotation. Let\u2019s add a function to reformat annotations for a single example:`),ct=c(),u(sa.$$.fragment),ht=c(),za=n("p"),oo=e("Now you can combine the image and annotation transformations to use on a batch of examples:"),mt=c(),u(aa.$$.fragment),ut=c(),Ts=n("p"),ro=e("Apply this preprocessing function to the entire dataset using \u{1F917} Datasets "),la=n("a"),io=e("with_transform"),co=e(` method. This method applies
transformations on the fly when you load an element of the dataset.`),jt=c(),W=n("p"),ho=e(`At this point, you can check what an example from the dataset looks like after the transformations. You should see a tensor
with `),Ll=n("code"),mo=e("pixel_values"),uo=e(", a tensor with "),se=n("code"),jo=e("pixel_mask"),Mo=e(", and "),ae=n("code"),yo=e("labels"),bo=e("."),Mt=c(),u(ea.$$.fragment),dt=c(),R=n("p"),Jo=e(`You have successfully augmented the individual images and prepared their annotations. However, preprocessing isn\u2019t
complete yet. In the final step, create a custom `),le=n("code"),wo=e("collate_fn"),fo=e(` to batch images together.
Pad images (which are now `),ee=n("code"),To=e("pixel_values"),Uo=e(") to the largest image in a batch, and create a corresponding "),te=n("code"),go=e("pixel_mask"),Io=e(`
to indicate which pixels are real (1) and which are padding (0).`),yt=c(),u(ta.$$.fragment),bt=c(),is=n("h2"),Us=n("a"),ne=n("span"),u(na.$$.fragment),Co=c(),pe=n("span"),_o=e("Training the DETR model"),Jt=e(`

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.
`),Sa=n("p"),vo=e("Training involves the following steps:"),wt=c(),V=n("ol"),pa=n("li"),Eo=e("Load the model with "),Ha=n("a"),Zo=e("AutoModelForObjectDetection"),Ao=e(" using the same checkpoint as in the preprocessing."),ko=c(),oa=n("li"),Bo=e("Define your training hyperparameters in "),Da=n("a"),Go=e("TrainingArguments"),Wo=e("."),Ro=c(),ra=n("li"),Vo=e("Pass the training arguments to "),Pa=n("a"),Qo=e("Trainer"),xo=e(" along with the model, dataset, image processor, and data collator."),Xo=c(),ia=n("li"),Yo=e("Call "),Oa=n("a"),No=e("train()"),Fo=e(" to finetune your model."),ft=c(),Q=n("p"),qo=e("When loading the model from the same checkpoint that you used for the preprocessing, remember to pass the "),oe=n("code"),$o=e("label2id"),zo=e(`
and `),re=n("code"),So=e("id2label"),Ho=e(" maps that you created earlier from the dataset\u2019s metadata. Additionally, we specify "),ie=n("code"),Do=e("ignore_mismatched_sizes=True"),Po=e(" to replace the existing classification head with a new one."),Tt=c(),u(ca.$$.fragment),Ut=c(),f=n("p"),Oo=e("In the "),Ka=n("a"),Ko=e("TrainingArguments"),Lo=e(" use "),ce=n("code"),sr=e("output_dir"),ar=e(` to specify where to save your model, then configure hyperparameters as you see fit.
It is important you do not remove unused columns because this will drop the image column. Without the image column, you
can\u2019t create `),he=n("code"),lr=e("pixel_values"),er=e(". For this reason, set "),me=n("code"),tr=e("remove_unused_columns"),nr=e(" to "),ue=n("code"),pr=e("False"),or=e(`.
If you wish to share your model by pushing to the Hub, set `),je=n("code"),rr=e("push_to_hub"),ir=e(" to "),Me=n("code"),cr=e("True"),hr=e(` (you must be signed in to Hugging
Face to upload your model).`),gt=c(),u(ha.$$.fragment),It=c(),gs=n("p"),mr=e("Finally, bring everything together, and call "),La=n("a"),ur=e("train()"),jr=e(":"),Ct=c(),u(ma.$$.fragment),_t=c(),A=n("p"),Mr=e("If you have set "),de=n("code"),dr=e("push_to_hub"),yr=e(" to "),ye=n("code"),br=e("True"),Jr=e(" in the "),be=n("code"),wr=e("training_args"),fr=e(`, 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 `),sl=n("a"),Tr=e("push_to_hub()"),Ur=e(" method."),vt=c(),u(ua.$$.fragment),Et=c(),cs=n("h2"),Is=n("a"),Je=n("span"),u(ja.$$.fragment),gr=c(),we=n("span"),Ir=e("Evaluate"),Zt=e(`

Object detection models are commonly evaluated with a set of `),Ma=n("a"),Cr=e("COCO-style metrics"),At=e(`.
You can use one of the existing metrics implementations, but here you'll use the one from \`torchvision\` to evaluate the final
model that you pushed to the Hub.
`),ss=n("p"),_r=e("To use the "),fe=n("code"),vr=e("torchvision"),Er=e(` evaluator, you\u2019ll need to prepare a ground truth COCO dataset. The API to build a COCO dataset
requires the data to be stored in a certain format, so you\u2019ll need to save images and annotations to disk first. Just like
when you prepared your data for training, the annotations from the `),Te=n("code"),Zr=e('cppe5["test"]'),Ar=e(` need to be formatted. However, images
should stay as they are.`),kt=c(),Cs=n("p"),kr=e(`The evaluation step requires a bit of work, but it can be split in three major steps.
First, prepare the `),Ue=n("code"),Br=e('cppe5["test"]'),Gr=e(" set: format the annotations and save the data to disk."),Bt=c(),u(da.$$.fragment),Gt=c(),as=n("p"),Wr=e("Next, prepare an instance of a "),ge=n("code"),Rr=e("CocoDetection"),Vr=e(" class that can be used with "),Ie=n("code"),Qr=e("cocoevaluator"),xr=e("."),Wt=c(),u(ya.$$.fragment),Rt=c(),al=n("p"),Xr=e("Finally, load the metrics and run the evaluation."),Vt=c(),u(ba.$$.fragment),Qt=c(),_s=n("p"),Yr=e("These results can be further improved by adjusting the hyperparameters in "),ll=n("a"),Nr=e("TrainingArguments"),Fr=e(". Give it a go!"),xt=c(),hs=n("h2"),vs=n("a"),Ce=n("span"),u(Ja.$$.fragment),qr=c(),_e=n("span"),$r=e("Inference"),Xt=e(`

Now that you have finetuned a DETR model, evaluated it, and uploaded it to the Hugging Face Hub, you can use it for inference.
The simplest way to try out your finetuned model for inference is to use it in a [Pipeline](/docs/transformers/v4.30.0/en/main_classes/pipelines#transformers.Pipeline). Instantiate a pipeline
for object detection with your model, and pass an image to it:

	`),u(wa.$$.fragment),Yt=c(),el=n("p"),zr=e("You can also manually replicate the results of the pipeline if you\u2019d like:"),Nt=c(),u(fa.$$.fragment),Ft=c(),tl=n("p"),Sr=e("Let\u2019s plot the result:"),qt=c(),u(Ta.$$.fragment),$t=c(),Ua=n("div"),nl=n("img"),this.h()},l(s){const r=ih('[data-svelte="svelte-1phssyn"]',document.head);_=p(r,"META",{name:!0,content:!0}),r.forEach(l),w=h(s),g=p(s,"H1",{class:!0});var ga=o(g);k=p(ga,"A",{id:!0,class:!0,href:!0});var ai=o(k);ns=p(ai,"SPAN",{});var li=o(ns);j(v.$$.fragment,li),li.forEach(l),ai.forEach(l),Ws=h(ga),ps=p(ga,"SPAN",{});var ei=o(ps);$=t(ei,"Object detection"),ei.forEach(l),ga.forEach(l),ms=h(s),j(X.$$.fragment,s),Y=h(s),z=p(s,"P",{});var ti=o(z);Rs=t(ti,`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.`),ti.forEach(l),N=h(s),S=p(s,"P",{});var ni=o(S);Vs=t(ni,"In this guide, you will learn how to:"),ni.forEach(l),F=h(s),B=p(s,"OL",{});var St=o(B);U=p(St,"LI",{});var pl=o(U);T=t(pl,"Finetune "),H=p(pl,"A",{href:!0,rel:!0});var pi=o(H);Ia=t(pi,"DETR"),pi.forEach(l),Ca=t(pl,`, a model that combines a convolutional
backbone with an encoder-decoder Transformer, on the `),D=p(pl,"A",{href:!0,rel:!0});var oi=o(D);_a=t(oi,"CPPE-5"),oi.forEach(l),va=t(pl,`
dataset.`),pl.forEach(l),un=h(St),jl=p(St,"LI",{});var ri=o(jl);jn=t(ri,"Use your finetuned model for inference."),ri.forEach(l),St.forEach(l),Ae=h(s),j(us.$$.fragment,s),ke=h(s),Ea=p(s,"P",{});var ii=o(Ea);Mn=t(ii,"Before you begin, make sure you have all the necessary libraries installed:"),ii.forEach(l),Be=h(s),j(Qs.$$.fragment,s),Ge=h(s),P=p(s,"P",{});var ol=o(P);dn=t(ol,`You\u2019ll use \u{1F917} Datasets to load a dataset from the Hugging Face Hub, \u{1F917} Transformers to train your model,
and `),Ml=p(ol,"CODE",{});var ci=o(Ml);yn=t(ci,"albumentations"),ci.forEach(l),bn=t(ol," to augment the data. "),dl=p(ol,"CODE",{});var hi=o(dl);Jn=t(hi,"timm"),hi.forEach(l),wn=t(ol," is currently required to load a convolutional backbone for the DETR model."),ol.forEach(l),We=h(s),Za=p(s,"P",{});var mi=o(Za);fn=t(mi,`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:`),mi.forEach(l),Re=h(s),j(xs.$$.fragment,s),Ve=h(s),os=p(s,"H2",{class:!0});var Ht=o(os);js=p(Ht,"A",{id:!0,class:!0,href:!0});var ui=o(js);yl=p(ui,"SPAN",{});var ji=o(yl);j(Xs.$$.fragment,ji),ji.forEach(l),ui.forEach(l),Tn=h(Ht),bl=p(Ht,"SPAN",{});var Mi=o(bl);Un=t(Mi,"Load the CPPE-5 dataset"),Mi.forEach(l),Ht.forEach(l),Qe=h(s),Ms=p(s,"P",{});var Dt=o(Ms);gn=t(Dt,"The "),Ys=p(Dt,"A",{href:!0,rel:!0});var di=o(Ys);In=t(di,"CPPE-5 dataset"),di.forEach(l),Cn=t(Dt,` contains images with
annotations identifying medical personal protective equipment (PPE) in the context of the COVID-19 pandemic.`),Dt.forEach(l),xe=h(s),Aa=p(s,"P",{});var yi=o(Aa);_n=t(yi,"Start by loading the dataset:"),yi.forEach(l),Xe=h(s),j(Ns.$$.fragment,s),Ye=h(s),ka=p(s,"P",{});var bi=o(ka);vn=t(bi,"You\u2019ll see that this dataset already comes with a training set containing 1000 images and a test set with 29 images."),bi.forEach(l),Ne=h(s),Ba=p(s,"P",{});var Ji=o(Ba);En=t(Ji,"To get familiar with the data, explore what the examples look like."),Ji.forEach(l),Fe=h(s),j(Fs.$$.fragment,s),qe=h(s),Ga=p(s,"P",{});var wi=o(Ga);Zn=t(wi,"The examples in the dataset have the following fields:"),wi.forEach(l),$e=h(s),E=p(s,"UL",{});var ls=o(E);Wa=p(ls,"LI",{});var Hr=o(Wa);Jl=p(Hr,"CODE",{});var fi=o(Jl);An=t(fi,"image_id"),fi.forEach(l),kn=t(Hr,": the example image id"),Hr.forEach(l),Bn=h(ls),ds=p(ls,"LI",{});var ve=o(ds);wl=p(ve,"CODE",{});var Ti=o(wl);Gn=t(Ti,"image"),Ti.forEach(l),Wn=t(ve,": a "),fl=p(ve,"CODE",{});var Ui=o(fl);Rn=t(Ui,"PIL.Image.Image"),Ui.forEach(l),Vn=t(ve," object containing the image"),ve.forEach(l),Qn=h(ls),Ra=p(ls,"LI",{});var Dr=o(Ra);Tl=p(Dr,"CODE",{});var gi=o(Tl);xn=t(gi,"width"),gi.forEach(l),Xn=t(Dr,": width of the image"),Dr.forEach(l),Yn=h(ls),Va=p(ls,"LI",{});var Pr=o(Va);Ul=p(Pr,"CODE",{});var Ii=o(Ul);Nn=t(Ii,"height"),Ii.forEach(l),Fn=t(Pr,": height of the image"),Pr.forEach(l),qn=h(ls),qs=p(ls,"LI",{});var Pt=o(qs);gl=p(Pt,"CODE",{});var Ci=o(gl);$n=t(Ci,"objects"),Ci.forEach(l),zn=t(Pt,": a dictionary containing bounding box metadata for the objects in the image:"),q=p(Pt,"UL",{});var Es=o(q);Qa=p(Es,"LI",{});var Or=o(Qa);Il=p(Or,"CODE",{});var _i=o(Il);Sn=t(_i,"id"),_i.forEach(l),Hn=t(Or,": the annotation id"),Or.forEach(l),Dn=h(Es),xa=p(Es,"LI",{});var Kr=o(xa);Cl=p(Kr,"CODE",{});var vi=o(Cl);Pn=t(vi,"area"),vi.forEach(l),On=t(Kr,": the area of the bounding box"),Kr.forEach(l),Kn=h(Es),ys=p(Es,"LI",{});var Ee=o(ys);_l=p(Ee,"CODE",{});var Ei=o(_l);Ln=t(Ei,"bbox"),Ei.forEach(l),sp=t(Ee,": the object\u2019s bounding box (in the "),$s=p(Ee,"A",{href:!0,rel:!0});var Zi=o($s);ap=t(Zi,"COCO format"),Zi.forEach(l),lp=t(Ee," )"),Ee.forEach(l),ep=h(Es),C=p(Es,"LI",{});var x=o(C);vl=p(x,"CODE",{});var Ai=o(vl);tp=t(Ai,"category"),Ai.forEach(l),np=t(x,": the object\u2019s category, with possible values including "),El=p(x,"CODE",{});var ki=o(El);pp=t(ki,"Coverall (0)"),ki.forEach(l),op=t(x,", "),Zl=p(x,"CODE",{});var Bi=o(Zl);rp=t(Bi,"Face_Shield (1)"),Bi.forEach(l),ip=t(x,", "),Al=p(x,"CODE",{});var Gi=o(Al);cp=t(Gi,"Gloves (2)"),Gi.forEach(l),hp=t(x,", "),kl=p(x,"CODE",{});var Wi=o(kl);mp=t(Wi,"Goggles (3)"),Wi.forEach(l),up=t(x," and "),Bl=p(x,"CODE",{});var Ri=o(Bl);jp=t(Ri,"Mask (4)"),Ri.forEach(l),x.forEach(l),Es.forEach(l),Pt.forEach(l),ls.forEach(l),ze=h(s),O=p(s,"P",{});var rl=o(O);Mp=t(rl,"You may notice that the "),Gl=p(rl,"CODE",{});var Vi=o(Gl);dp=t(Vi,"bbox"),Vi.forEach(l),yp=t(rl,` field follows the COCO format, which is the format that the DETR model expects.
However, the grouping of the fields inside `),Wl=p(rl,"CODE",{});var Qi=o(Wl);bp=t(Qi,"objects"),Qi.forEach(l),Jp=t(rl,` differs from the annotation format DETR requires. You will
need to apply some preprocessing transformations before using this data for training.`),rl.forEach(l),Se=h(s),Xa=p(s,"P",{});var xi=o(Xa);wp=t(xi,"To get an even better understanding of the data, visualize an example in the dataset."),xi.forEach(l),He=h(s),j(zs.$$.fragment,s),De=h(s),Ss=p(s,"DIV",{class:!0});var Xi=o(Ss);Ya=p(Xi,"IMG",{src:!0,alt:!0}),Xi.forEach(l),Pe=h(s),G=p(s,"P",{});var Zs=o(G);fp=t(Zs,`To visualize the bounding boxes with associated labels, you can get the labels from the dataset\u2019s metadata, specifically
the `),Rl=p(Zs,"CODE",{});var Yi=o(Rl);Tp=t(Yi,"category"),Yi.forEach(l),Up=t(Zs,` field.
You\u2019ll also want to create dictionaries that map a label id to a label class (`),Vl=p(Zs,"CODE",{});var Ni=o(Vl);gp=t(Ni,"id2label"),Ni.forEach(l),Ip=t(Zs,") and the other way around ("),Ql=p(Zs,"CODE",{});var Fi=o(Ql);Cp=t(Fi,"label2id"),Fi.forEach(l),_p=t(Zs,`).
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.`),Zs.forEach(l),Oe=h(s),Na=p(s,"P",{});var qi=o(Na);vp=t(qi,`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 \u201Cstretch\u201D beyond the edge of the image. Such \u201Crunaway\u201D bounding boxes can raise
errors during training and should be addressed at this stage. There are a few examples with this issue in this dataset.
To keep things simple in this guide, we remove these images from the data.`),qi.forEach(l),Ke=h(s),j(Hs.$$.fragment,s),Le=h(s),rs=p(s,"H2",{class:!0});var Ot=o(rs);bs=p(Ot,"A",{id:!0,class:!0,href:!0});var $i=o(bs);xl=p($i,"SPAN",{});var zi=o(xl);j(Ds.$$.fragment,zi),zi.forEach(l),$i.forEach(l),Ep=h(Ot),Xl=p(Ot,"SPAN",{});var Si=o(Xl);Zp=t(Si,"Preprocess the data"),Si.forEach(l),Ot.forEach(l),st=h(s),Z=p(s,"P",{});var es=o(Z);Ap=t(es,`To finetune a model, you must preprocess the data you plan to use to match precisely the approach used for the pre-trained model.
`),Fa=p(es,"A",{href:!0});var Hi=o(Fa);kp=t(Hi,"AutoImageProcessor"),Hi.forEach(l),Bp=t(es," takes care of processing image data to create "),Yl=p(es,"CODE",{});var Di=o(Yl);Gp=t(Di,"pixel_values"),Di.forEach(l),Wp=t(es,", "),Nl=p(es,"CODE",{});var Pi=o(Nl);Rp=t(Pi,"pixel_mask"),Pi.forEach(l),Vp=t(es,`, and
`),Fl=p(es,"CODE",{});var Oi=o(Fl);Qp=t(Oi,"labels"),Oi.forEach(l),xp=t(es," that a DETR model can train with. The image processor has some attributes that you won\u2019t have to worry about:"),es.forEach(l),at=h(s),Js=p(s,"UL",{});var Kt=o(Js);ql=p(Kt,"LI",{});var Ki=o(ql);$l=p(Ki,"CODE",{});var Li=o($l);Xp=t(Li,"image_mean = [0.485, 0.456, 0.406 ]"),Li.forEach(l),Ki.forEach(l),Yp=h(Kt),zl=p(Kt,"LI",{});var sc=o(zl);Sl=p(sc,"CODE",{});var ac=o(Sl);Np=t(ac,"image_std = [0.229, 0.224, 0.225]"),ac.forEach(l),sc.forEach(l),Kt.forEach(l),lt=h(s),qa=p(s,"P",{});var lc=o(qa);Fp=t(lc,`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.`),lc.forEach(l),et=h(s),$a=p(s,"P",{});var ec=o($a);qp=t(ec,"Instantiate the image processor from the same checkpoint as the model you want to finetune."),ec.forEach(l),tt=h(s),j(Ps.$$.fragment,s),nt=h(s),ws=p(s,"P",{});var Lt=o(ws);$p=t(Lt,"Before passing the images to the "),Hl=p(Lt,"CODE",{});var tc=o(Hl);zp=t(tc,"image_processor"),tc.forEach(l),Sp=t(Lt,", apply two preprocessing transformations to the dataset:"),Lt.forEach(l),pt=h(s),fs=p(s,"UL",{});var sn=o(fs);Dl=p(sn,"LI",{});var nc=o(Dl);Hp=t(nc,"Augmenting images"),nc.forEach(l),Dp=h(sn),Pl=p(sn,"LI",{});var pc=o(Pl);Pp=t(pc,"Reformatting annotations to meet DETR expectations"),pc.forEach(l),sn.forEach(l),ot=h(s),K=p(s,"P",{});var il=o(K);Op=t(il,"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 "),Os=p(il,"A",{href:!0,rel:!0});var oc=o(Os);Kp=t(oc,"Albumentations"),oc.forEach(l),Lp=t(il,` \u2026
This library ensures that transformations affect the image and update the bounding boxes accordingly.
The \u{1F917} Datasets library documentation has a detailed `),Ks=p(il,"A",{href:!0,rel:!0});var rc=o(Ks);so=t(rc,"guide on how to augment images for object detection"),rc.forEach(l),ao=t(il,`,
and it uses the exact same dataset as an example. Apply the same approach here, resize each image to (480, 480),
flip it horizontally, and brighten it:`),il.forEach(l),rt=h(s),j(Ls.$$.fragment,s),it=h(s),L=p(s,"P",{});var cl=o(L);lo=t(cl,"The "),Ol=p(cl,"CODE",{});var ic=o(Ol);eo=t(ic,"image_processor"),ic.forEach(l),to=t(cl," expects the annotations to be in the following format: "),Kl=p(cl,"CODE",{});var cc=o(Kl);no=t(cc,"{'image_id': int, 'annotations': List[Dict]}"),cc.forEach(l),po=t(cl,`,
where each dictionary is a COCO object annotation. Let\u2019s add a function to reformat annotations for a single example:`),cl.forEach(l),ct=h(s),j(sa.$$.fragment,s),ht=h(s),za=p(s,"P",{});var hc=o(za);oo=t(hc,"Now you can combine the image and annotation transformations to use on a batch of examples:"),hc.forEach(l),mt=h(s),j(aa.$$.fragment,s),ut=h(s),Ts=p(s,"P",{});var an=o(Ts);ro=t(an,"Apply this preprocessing function to the entire dataset using \u{1F917} Datasets "),la=p(an,"A",{href:!0,rel:!0});var mc=o(la);io=t(mc,"with_transform"),mc.forEach(l),co=t(an,` method. This method applies
transformations on the fly when you load an element of the dataset.`),an.forEach(l),jt=h(s),W=p(s,"P",{});var As=o(W);ho=t(As,`At this point, you can check what an example from the dataset looks like after the transformations. You should see a tensor
with `),Ll=p(As,"CODE",{});var uc=o(Ll);mo=t(uc,"pixel_values"),uc.forEach(l),uo=t(As,", a tensor with "),se=p(As,"CODE",{});var jc=o(se);jo=t(jc,"pixel_mask"),jc.forEach(l),Mo=t(As,", and "),ae=p(As,"CODE",{});var Mc=o(ae);yo=t(Mc,"labels"),Mc.forEach(l),bo=t(As,"."),As.forEach(l),Mt=h(s),j(ea.$$.fragment,s),dt=h(s),R=p(s,"P",{});var ks=o(R);Jo=t(ks,`You have successfully augmented the individual images and prepared their annotations. However, preprocessing isn\u2019t
complete yet. In the final step, create a custom `),le=p(ks,"CODE",{});var dc=o(le);wo=t(dc,"collate_fn"),dc.forEach(l),fo=t(ks,` to batch images together.
Pad images (which are now `),ee=p(ks,"CODE",{});var yc=o(ee);To=t(yc,"pixel_values"),yc.forEach(l),Uo=t(ks,") to the largest image in a batch, and create a corresponding "),te=p(ks,"CODE",{});var bc=o(te);go=t(bc,"pixel_mask"),bc.forEach(l),Io=t(ks,`
to indicate which pixels are real (1) and which are padding (0).`),ks.forEach(l),yt=h(s),j(ta.$$.fragment,s),bt=h(s),is=p(s,"H2",{class:!0});var ln=o(is);Us=p(ln,"A",{id:!0,class:!0,href:!0});var Jc=o(Us);ne=p(Jc,"SPAN",{});var wc=o(ne);j(na.$$.fragment,wc),wc.forEach(l),Jc.forEach(l),Co=h(ln),pe=p(ln,"SPAN",{});var fc=o(pe);_o=t(fc,"Training the DETR model"),fc.forEach(l),ln.forEach(l),Jt=t(s,`

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.
`),Sa=p(s,"P",{});var Tc=o(Sa);vo=t(Tc,"Training involves the following steps:"),Tc.forEach(l),wt=h(s),V=p(s,"OL",{});var Bs=o(V);pa=p(Bs,"LI",{});var en=o(pa);Eo=t(en,"Load the model with "),Ha=p(en,"A",{href:!0});var Uc=o(Ha);Zo=t(Uc,"AutoModelForObjectDetection"),Uc.forEach(l),Ao=t(en," using the same checkpoint as in the preprocessing."),en.forEach(l),ko=h(Bs),oa=p(Bs,"LI",{});var tn=o(oa);Bo=t(tn,"Define your training hyperparameters in "),Da=p(tn,"A",{href:!0});var gc=o(Da);Go=t(gc,"TrainingArguments"),gc.forEach(l),Wo=t(tn,"."),tn.forEach(l),Ro=h(Bs),ra=p(Bs,"LI",{});var nn=o(ra);Vo=t(nn,"Pass the training arguments to "),Pa=p(nn,"A",{href:!0});var Ic=o(Pa);Qo=t(Ic,"Trainer"),Ic.forEach(l),xo=t(nn," along with the model, dataset, image processor, and data collator."),nn.forEach(l),Xo=h(Bs),ia=p(Bs,"LI",{});var pn=o(ia);Yo=t(pn,"Call "),Oa=p(pn,"A",{href:!0});var Cc=o(Oa);No=t(Cc,"train()"),Cc.forEach(l),Fo=t(pn," to finetune your model."),pn.forEach(l),Bs.forEach(l),ft=h(s),Q=p(s,"P",{});var Gs=o(Q);qo=t(Gs,"When loading the model from the same checkpoint that you used for the preprocessing, remember to pass the "),oe=p(Gs,"CODE",{});var _c=o(oe);$o=t(_c,"label2id"),_c.forEach(l),zo=t(Gs,`
and `),re=p(Gs,"CODE",{});var vc=o(re);So=t(vc,"id2label"),vc.forEach(l),Ho=t(Gs," maps that you created earlier from the dataset\u2019s metadata. Additionally, we specify "),ie=p(Gs,"CODE",{});var Ec=o(ie);Do=t(Ec,"ignore_mismatched_sizes=True"),Ec.forEach(l),Po=t(Gs," to replace the existing classification head with a new one."),Gs.forEach(l),Tt=h(s),j(ca.$$.fragment,s),Ut=h(s),f=p(s,"P",{});var I=o(f);Oo=t(I,"In the "),Ka=p(I,"A",{href:!0});var Zc=o(Ka);Ko=t(Zc,"TrainingArguments"),Zc.forEach(l),Lo=t(I," use "),ce=p(I,"CODE",{});var Ac=o(ce);sr=t(Ac,"output_dir"),Ac.forEach(l),ar=t(I,` to specify where to save your model, then configure hyperparameters as you see fit.
It is important you do not remove unused columns because this will drop the image column. Without the image column, you
can\u2019t create `),he=p(I,"CODE",{});var kc=o(he);lr=t(kc,"pixel_values"),kc.forEach(l),er=t(I,". For this reason, set "),me=p(I,"CODE",{});var Bc=o(me);tr=t(Bc,"remove_unused_columns"),Bc.forEach(l),nr=t(I," to "),ue=p(I,"CODE",{});var Gc=o(ue);pr=t(Gc,"False"),Gc.forEach(l),or=t(I,`.
If you wish to share your model by pushing to the Hub, set `),je=p(I,"CODE",{});var Wc=o(je);rr=t(Wc,"push_to_hub"),Wc.forEach(l),ir=t(I," to "),Me=p(I,"CODE",{});var Rc=o(Me);cr=t(Rc,"True"),Rc.forEach(l),hr=t(I,` (you must be signed in to Hugging
Face to upload your model).`),I.forEach(l),gt=h(s),j(ha.$$.fragment,s),It=h(s),gs=p(s,"P",{});var on=o(gs);mr=t(on,"Finally, bring everything together, and call "),La=p(on,"A",{href:!0});var Vc=o(La);ur=t(Vc,"train()"),Vc.forEach(l),jr=t(on,":"),on.forEach(l),Ct=h(s),j(ma.$$.fragment,s),_t=h(s),A=p(s,"P",{});var ts=o(A);Mr=t(ts,"If you have set "),de=p(ts,"CODE",{});var Qc=o(de);dr=t(Qc,"push_to_hub"),Qc.forEach(l),yr=t(ts," to "),ye=p(ts,"CODE",{});var xc=o(ye);br=t(xc,"True"),xc.forEach(l),Jr=t(ts," in the "),be=p(ts,"CODE",{});var Xc=o(be);wr=t(Xc,"training_args"),Xc.forEach(l),fr=t(ts,`, 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 `),sl=p(ts,"A",{href:!0});var Yc=o(sl);Tr=t(Yc,"push_to_hub()"),Yc.forEach(l),Ur=t(ts," method."),ts.forEach(l),vt=h(s),j(ua.$$.fragment,s),Et=h(s),cs=p(s,"H2",{class:!0});var rn=o(cs);Is=p(rn,"A",{id:!0,class:!0,href:!0});var Nc=o(Is);Je=p(Nc,"SPAN",{});var Fc=o(Je);j(ja.$$.fragment,Fc),Fc.forEach(l),Nc.forEach(l),gr=h(rn),we=p(rn,"SPAN",{});var qc=o(we);Ir=t(qc,"Evaluate"),qc.forEach(l),rn.forEach(l),Zt=t(s,`

Object detection models are commonly evaluated with a set of `),Ma=p(s,"A",{href:!0});var $c=o(Ma);Cr=t($c,"COCO-style metrics"),$c.forEach(l),At=t(s,`.
You can use one of the existing metrics implementations, but here you'll use the one from \`torchvision\` to evaluate the final
model that you pushed to the Hub.
`),ss=p(s,"P",{});var hl=o(ss);_r=t(hl,"To use the "),fe=p(hl,"CODE",{});var zc=o(fe);vr=t(zc,"torchvision"),zc.forEach(l),Er=t(hl,` evaluator, you\u2019ll need to prepare a ground truth COCO dataset. The API to build a COCO dataset
requires the data to be stored in a certain format, so you\u2019ll need to save images and annotations to disk first. Just like
when you prepared your data for training, the annotations from the `),Te=p(hl,"CODE",{});var Sc=o(Te);Zr=t(Sc,'cppe5["test"]'),Sc.forEach(l),Ar=t(hl,` need to be formatted. However, images
should stay as they are.`),hl.forEach(l),kt=h(s),Cs=p(s,"P",{});var cn=o(Cs);kr=t(cn,`The evaluation step requires a bit of work, but it can be split in three major steps.
First, prepare the `),Ue=p(cn,"CODE",{});var Hc=o(Ue);Br=t(Hc,'cppe5["test"]'),Hc.forEach(l),Gr=t(cn," set: format the annotations and save the data to disk."),cn.forEach(l),Bt=h(s),j(da.$$.fragment,s),Gt=h(s),as=p(s,"P",{});var ml=o(as);Wr=t(ml,"Next, prepare an instance of a "),ge=p(ml,"CODE",{});var Dc=o(ge);Rr=t(Dc,"CocoDetection"),Dc.forEach(l),Vr=t(ml," class that can be used with "),Ie=p(ml,"CODE",{});var Pc=o(Ie);Qr=t(Pc,"cocoevaluator"),Pc.forEach(l),xr=t(ml,"."),ml.forEach(l),Wt=h(s),j(ya.$$.fragment,s),Rt=h(s),al=p(s,"P",{});var Oc=o(al);Xr=t(Oc,"Finally, load the metrics and run the evaluation."),Oc.forEach(l),Vt=h(s),j(ba.$$.fragment,s),Qt=h(s),_s=p(s,"P",{});var hn=o(_s);Yr=t(hn,"These results can be further improved by adjusting the hyperparameters in "),ll=p(hn,"A",{href:!0});var Kc=o(ll);Nr=t(Kc,"TrainingArguments"),Kc.forEach(l),Fr=t(hn,". Give it a go!"),hn.forEach(l),xt=h(s),hs=p(s,"H2",{class:!0});var mn=o(hs);vs=p(mn,"A",{id:!0,class:!0,href:!0});var Lc=o(vs);Ce=p(Lc,"SPAN",{});var sh=o(Ce);j(Ja.$$.fragment,sh),sh.forEach(l),Lc.forEach(l),qr=h(mn),_e=p(mn,"SPAN",{});var ah=o(_e);$r=t(ah,"Inference"),ah.forEach(l),mn.forEach(l),Xt=t(s,`

Now that you have finetuned a DETR model, evaluated it, and uploaded it to the Hugging Face Hub, you can use it for inference.
The simplest way to try out your finetuned model for inference is to use it in a [Pipeline](/docs/transformers/v4.30.0/en/main_classes/pipelines#transformers.Pipeline). Instantiate a pipeline
for object detection with your model, and pass an image to it:

	`),j(wa.$$.fragment,s),Yt=h(s),el=p(s,"P",{});var lh=o(el);zr=t(lh,"You can also manually replicate the results of the pipeline if you\u2019d like:"),lh.forEach(l),Nt=h(s),j(fa.$$.fragment,s),Ft=h(s),tl=p(s,"P",{});var eh=o(tl);Sr=t(eh,"Let\u2019s plot the result:"),eh.forEach(l),qt=h(s),j(Ta.$$.fragment,s),$t=h(s),Ua=p(s,"DIV",{class:!0});var th=o(Ua);nl=p(th,"IMG",{src:!0,alt:!0}),th.forEach(l),this.h()},h(){m(_,"name","hf:doc:metadata"),m(_,"content",JSON.stringify(Mh)),m(k,"id","object-detection"),m(k,"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"),m(k,"href","#object-detection"),m(g,"class","relative group"),m(H,"href","https://huggingface.co/docs/transformers/model_doc/detr"),m(H,"rel","nofollow"),m(D,"href","https://huggingface.co/datasets/cppe-5"),m(D,"rel","nofollow"),m(js,"id","load-the-cppe5-dataset"),m(js,"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"),m(js,"href","#load-the-cppe5-dataset"),m(os,"class","relative group"),m(Ys,"href","https://huggingface.co/datasets/cppe-5"),m(Ys,"rel","nofollow"),m($s,"href","https://albumentations.ai/docs/getting_started/bounding_boxes_augmentation/#coco"),m($s,"rel","nofollow"),nh(Ya.src,Lr="https://i.imgur.com/TdaqPJO.png")||m(Ya,"src",Lr),m(Ya,"alt","CPPE-5 Image Example"),m(Ss,"class","flex justify-center"),m(bs,"id","preprocess-the-data"),m(bs,"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"),m(bs,"href","#preprocess-the-data"),m(rs,"class","relative group"),m(Fa,"href","/docs/transformers/v4.30.0/en/model_doc/auto#transformers.AutoImageProcessor"),m(Os,"href","https://albumentations.ai/docs/"),m(Os,"rel","nofollow"),m(Ks,"href","https://huggingface.co/docs/datasets/object_detection"),m(Ks,"rel","nofollow"),m(la,"href","https://huggingface.co/docs/datasets/v2.12.0/en/package_reference/main_classes#datasets.Dataset.with_transform"),m(la,"rel","nofollow"),m(Us,"id","training-the-detr-model"),m(Us,"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"),m(Us,"href","#training-the-detr-model"),m(is,"class","relative group"),m(Ha,"href","/docs/transformers/v4.30.0/en/model_doc/auto#transformers.AutoModelForObjectDetection"),m(Da,"href","/docs/transformers/v4.30.0/en/main_classes/trainer#transformers.TrainingArguments"),m(Pa,"href","/docs/transformers/v4.30.0/en/main_classes/trainer#transformers.Trainer"),m(Oa,"href","/docs/transformers/v4.30.0/en/main_classes/trainer#transformers.Trainer.train"),m(Ka,"href","/docs/transformers/v4.30.0/en/main_classes/trainer#transformers.TrainingArguments"),m(La,"href","/docs/transformers/v4.30.0/en/main_classes/trainer#transformers.Trainer.train"),m(sl,"href","/docs/transformers/v4.30.0/en/main_classes/trainer#transformers.Trainer.push_to_hub"),m(Is,"id","evaluate"),m(Is,"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"),m(Is,"href","#evaluate"),m(cs,"class","relative group"),m(Ma,"href","https://cocodataset.org/#detection-eval"),m(ll,"href","/docs/transformers/v4.30.0/en/main_classes/trainer#transformers.TrainingArguments"),m(vs,"id","inference"),m(vs,"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"),m(vs,"href","#inference"),m(hs,"class","relative group"),nh(nl.src,si="https://i.imgur.com/4QZnf9A.png")||m(nl,"src",si),m(nl,"alt","Object detection result on a new image"),m(Ua,"class","flex justify-center")},m(s,r){a(document.head,_),i(s,w,r),i(s,g,r),a(g,k),a(k,ns),M(v,ns,null),a(g,Ws),a(g,ps),a(ps,$),i(s,ms,r),M(X,s,r),i(s,Y,r),i(s,z,r),a(z,Rs),i(s,N,r),i(s,S,r),a(S,Vs),i(s,F,r),i(s,B,r),a(B,U),a(U,T),a(U,H),a(H,Ia),a(U,Ca),a(U,D),a(D,_a),a(U,va),a(B,un),a(B,jl),a(jl,jn),i(s,Ae,r),M(us,s,r),i(s,ke,r),i(s,Ea,r),a(Ea,Mn),i(s,Be,r),M(Qs,s,r),i(s,Ge,r),i(s,P,r),a(P,dn),a(P,Ml),a(Ml,yn),a(P,bn),a(P,dl),a(dl,Jn),a(P,wn),i(s,We,r),i(s,Za,r),a(Za,fn),i(s,Re,r),M(xs,s,r),i(s,Ve,r),i(s,os,r),a(os,js),a(js,yl),M(Xs,yl,null),a(os,Tn),a(os,bl),a(bl,Un),i(s,Qe,r),i(s,Ms,r),a(Ms,gn),a(Ms,Ys),a(Ys,In),a(Ms,Cn),i(s,xe,r),i(s,Aa,r),a(Aa,_n),i(s,Xe,r),M(Ns,s,r),i(s,Ye,r),i(s,ka,r),a(ka,vn),i(s,Ne,r),i(s,Ba,r),a(Ba,En),i(s,Fe,r),M(Fs,s,r),i(s,qe,r),i(s,Ga,r),a(Ga,Zn),i(s,$e,r),i(s,E,r),a(E,Wa),a(Wa,Jl),a(Jl,An),a(Wa,kn),a(E,Bn),a(E,ds),a(ds,wl),a(wl,Gn),a(ds,Wn),a(ds,fl),a(fl,Rn),a(ds,Vn),a(E,Qn),a(E,Ra),a(Ra,Tl),a(Tl,xn),a(Ra,Xn),a(E,Yn),a(E,Va),a(Va,Ul),a(Ul,Nn),a(Va,Fn),a(E,qn),a(E,qs),a(qs,gl),a(gl,$n),a(qs,zn),a(qs,q),a(q,Qa),a(Qa,Il),a(Il,Sn),a(Qa,Hn),a(q,Dn),a(q,xa),a(xa,Cl),a(Cl,Pn),a(xa,On),a(q,Kn),a(q,ys),a(ys,_l),a(_l,Ln),a(ys,sp),a(ys,$s),a($s,ap),a(ys,lp),a(q,ep),a(q,C),a(C,vl),a(vl,tp),a(C,np),a(C,El),a(El,pp),a(C,op),a(C,Zl),a(Zl,rp),a(C,ip),a(C,Al),a(Al,cp),a(C,hp),a(C,kl),a(kl,mp),a(C,up),a(C,Bl),a(Bl,jp),i(s,ze,r),i(s,O,r),a(O,Mp),a(O,Gl),a(Gl,dp),a(O,yp),a(O,Wl),a(Wl,bp),a(O,Jp),i(s,Se,r),i(s,Xa,r),a(Xa,wp),i(s,He,r),M(zs,s,r),i(s,De,r),i(s,Ss,r),a(Ss,Ya),i(s,Pe,r),i(s,G,r),a(G,fp),a(G,Rl),a(Rl,Tp),a(G,Up),a(G,Vl),a(Vl,gp),a(G,Ip),a(G,Ql),a(Ql,Cp),a(G,_p),i(s,Oe,r),i(s,Na,r),a(Na,vp),i(s,Ke,r),M(Hs,s,r),i(s,Le,r),i(s,rs,r),a(rs,bs),a(bs,xl),M(Ds,xl,null),a(rs,Ep),a(rs,Xl),a(Xl,Zp),i(s,st,r),i(s,Z,r),a(Z,Ap),a(Z,Fa),a(Fa,kp),a(Z,Bp),a(Z,Yl),a(Yl,Gp),a(Z,Wp),a(Z,Nl),a(Nl,Rp),a(Z,Vp),a(Z,Fl),a(Fl,Qp),a(Z,xp),i(s,at,r),i(s,Js,r),a(Js,ql),a(ql,$l),a($l,Xp),a(Js,Yp),a(Js,zl),a(zl,Sl),a(Sl,Np),i(s,lt,r),i(s,qa,r),a(qa,Fp),i(s,et,r),i(s,$a,r),a($a,qp),i(s,tt,r),M(Ps,s,r),i(s,nt,r),i(s,ws,r),a(ws,$p),a(ws,Hl),a(Hl,zp),a(ws,Sp),i(s,pt,r),i(s,fs,r),a(fs,Dl),a(Dl,Hp),a(fs,Dp),a(fs,Pl),a(Pl,Pp),i(s,ot,r),i(s,K,r),a(K,Op),a(K,Os),a(Os,Kp),a(K,Lp),a(K,Ks),a(Ks,so),a(K,ao),i(s,rt,r),M(Ls,s,r),i(s,it,r),i(s,L,r),a(L,lo),a(L,Ol),a(Ol,eo),a(L,to),a(L,Kl),a(Kl,no),a(L,po),i(s,ct,r),M(sa,s,r),i(s,ht,r),i(s,za,r),a(za,oo),i(s,mt,r),M(aa,s,r),i(s,ut,r),i(s,Ts,r),a(Ts,ro),a(Ts,la),a(la,io),a(Ts,co),i(s,jt,r),i(s,W,r),a(W,ho),a(W,Ll),a(Ll,mo),a(W,uo),a(W,se),a(se,jo),a(W,Mo),a(W,ae),a(ae,yo),a(W,bo),i(s,Mt,r),M(ea,s,r),i(s,dt,r),i(s,R,r),a(R,Jo),a(R,le),a(le,wo),a(R,fo),a(R,ee),a(ee,To),a(R,Uo),a(R,te),a(te,go),a(R,Io),i(s,yt,r),M(ta,s,r),i(s,bt,r),i(s,is,r),a(is,Us),a(Us,ne),M(na,ne,null),a(is,Co),a(is,pe),a(pe,_o),i(s,Jt,r),i(s,Sa,r),a(Sa,vo),i(s,wt,r),i(s,V,r),a(V,pa),a(pa,Eo),a(pa,Ha),a(Ha,Zo),a(pa,Ao),a(V,ko),a(V,oa),a(oa,Bo),a(oa,Da),a(Da,Go),a(oa,Wo),a(V,Ro),a(V,ra),a(ra,Vo),a(ra,Pa),a(Pa,Qo),a(ra,xo),a(V,Xo),a(V,ia),a(ia,Yo),a(ia,Oa),a(Oa,No),a(ia,Fo),i(s,ft,r),i(s,Q,r),a(Q,qo),a(Q,oe),a(oe,$o),a(Q,zo),a(Q,re),a(re,So),a(Q,Ho),a(Q,ie),a(ie,Do),a(Q,Po),i(s,Tt,r),M(ca,s,r),i(s,Ut,r),i(s,f,r),a(f,Oo),a(f,Ka),a(Ka,Ko),a(f,Lo),a(f,ce),a(ce,sr),a(f,ar),a(f,he),a(he,lr),a(f,er),a(f,me),a(me,tr),a(f,nr),a(f,ue),a(ue,pr),a(f,or),a(f,je),a(je,rr),a(f,ir),a(f,Me),a(Me,cr),a(f,hr),i(s,gt,r),M(ha,s,r),i(s,It,r),i(s,gs,r),a(gs,mr),a(gs,La),a(La,ur),a(gs,jr),i(s,Ct,r),M(ma,s,r),i(s,_t,r),i(s,A,r),a(A,Mr),a(A,de),a(de,dr),a(A,yr),a(A,ye),a(ye,br),a(A,Jr),a(A,be),a(be,wr),a(A,fr),a(A,sl),a(sl,Tr),a(A,Ur),i(s,vt,r),M(ua,s,r),i(s,Et,r),i(s,cs,r),a(cs,Is),a(Is,Je),M(ja,Je,null),a(cs,gr),a(cs,we),a(we,Ir),i(s,Zt,r),i(s,Ma,r),a(Ma,Cr),i(s,At,r),i(s,ss,r),a(ss,_r),a(ss,fe),a(fe,vr),a(ss,Er),a(ss,Te),a(Te,Zr),a(ss,Ar),i(s,kt,r),i(s,Cs,r),a(Cs,kr),a(Cs,Ue),a(Ue,Br),a(Cs,Gr),i(s,Bt,r),M(da,s,r),i(s,Gt,r),i(s,as,r),a(as,Wr),a(as,ge),a(ge,Rr),a(as,Vr),a(as,Ie),a(Ie,Qr),a(as,xr),i(s,Wt,r),M(ya,s,r),i(s,Rt,r),i(s,al,r),a(al,Xr),i(s,Vt,r),M(ba,s,r),i(s,Qt,r),i(s,_s,r),a(_s,Yr),a(_s,ll),a(ll,Nr),a(_s,Fr),i(s,xt,r),i(s,hs,r),a(hs,vs),a(vs,Ce),M(Ja,Ce,null),a(hs,qr),a(hs,_e),a(_e,$r),i(s,Xt,r),M(wa,s,r),i(s,Yt,r),i(s,el,r),a(el,zr),i(s,Nt,r),M(fa,s,r),i(s,Ft,r),i(s,tl,r),a(tl,Sr),i(s,qt,r),M(Ta,s,r),i(s,$t,r),i(s,Ua,r),a(Ua,nl),zt=!0},p(s,[r]){const ga={};r&2&&(ga.$$scope={dirty:r,ctx:s}),us.$set(ga)},i(s){zt||(d(v.$$.fragment,s),d(X.$$.fragment,s),d(us.$$.fragment,s),d(Qs.$$.fragment,s),d(xs.$$.fragment,s),d(Xs.$$.fragment,s),d(Ns.$$.fragment,s),d(Fs.$$.fragment,s),d(zs.$$.fragment,s),d(Hs.$$.fragment,s),d(Ds.$$.fragment,s),d(Ps.$$.fragment,s),d(Ls.$$.fragment,s),d(sa.$$.fragment,s),d(aa.$$.fragment,s),d(ea.$$.fragment,s),d(ta.$$.fragment,s),d(na.$$.fragment,s),d(ca.$$.fragment,s),d(ha.$$.fragment,s),d(ma.$$.fragment,s),d(ua.$$.fragment,s),d(ja.$$.fragment,s),d(da.$$.fragment,s),d(ya.$$.fragment,s),d(ba.$$.fragment,s),d(Ja.$$.fragment,s),d(wa.$$.fragment,s),d(fa.$$.fragment,s),d(Ta.$$.fragment,s),zt=!0)},o(s){y(v.$$.fragment,s),y(X.$$.fragment,s),y(us.$$.fragment,s),y(Qs.$$.fragment,s),y(xs.$$.fragment,s),y(Xs.$$.fragment,s),y(Ns.$$.fragment,s),y(Fs.$$.fragment,s),y(zs.$$.fragment,s),y(Hs.$$.fragment,s),y(Ds.$$.fragment,s),y(Ps.$$.fragment,s),y(Ls.$$.fragment,s),y(sa.$$.fragment,s),y(aa.$$.fragment,s),y(ea.$$.fragment,s),y(ta.$$.fragment,s),y(na.$$.fragment,s),y(ca.$$.fragment,s),y(ha.$$.fragment,s),y(ma.$$.fragment,s),y(ua.$$.fragment,s),y(ja.$$.fragment,s),y(da.$$.fragment,s),y(ya.$$.fragment,s),y(ba.$$.fragment,s),y(Ja.$$.fragment,s),y(wa.$$.fragment,s),y(fa.$$.fragment,s),y(Ta.$$.fragment,s),zt=!1},d(s){l(_),s&&l(w),s&&l(g),b(v),s&&l(ms),b(X,s),s&&l(Y),s&&l(z),s&&l(N),s&&l(S),s&&l(F),s&&l(B),s&&l(Ae),b(us,s),s&&l(ke),s&&l(Ea),s&&l(Be),b(Qs,s),s&&l(Ge),s&&l(P),s&&l(We),s&&l(Za),s&&l(Re),b(xs,s),s&&l(Ve),s&&l(os),b(Xs),s&&l(Qe),s&&l(Ms),s&&l(xe),s&&l(Aa),s&&l(Xe),b(Ns,s),s&&l(Ye),s&&l(ka),s&&l(Ne),s&&l(Ba),s&&l(Fe),b(Fs,s),s&&l(qe),s&&l(Ga),s&&l($e),s&&l(E),s&&l(ze),s&&l(O),s&&l(Se),s&&l(Xa),s&&l(He),b(zs,s),s&&l(De),s&&l(Ss),s&&l(Pe),s&&l(G),s&&l(Oe),s&&l(Na),s&&l(Ke),b(Hs,s),s&&l(Le),s&&l(rs),b(Ds),s&&l(st),s&&l(Z),s&&l(at),s&&l(Js),s&&l(lt),s&&l(qa),s&&l(et),s&&l($a),s&&l(tt),b(Ps,s),s&&l(nt),s&&l(ws),s&&l(pt),s&&l(fs),s&&l(ot),s&&l(K),s&&l(rt),b(Ls,s),s&&l(it),s&&l(L),s&&l(ct),b(sa,s),s&&l(ht),s&&l(za),s&&l(mt),b(aa,s),s&&l(ut),s&&l(Ts),s&&l(jt),s&&l(W),s&&l(Mt),b(ea,s),s&&l(dt),s&&l(R),s&&l(yt),b(ta,s),s&&l(bt),s&&l(is),b(na),s&&l(Jt),s&&l(Sa),s&&l(wt),s&&l(V),s&&l(ft),s&&l(Q),s&&l(Tt),b(ca,s),s&&l(Ut),s&&l(f),s&&l(gt),b(ha,s),s&&l(It),s&&l(gs),s&&l(Ct),b(ma,s),s&&l(_t),s&&l(A),s&&l(vt),b(ua,s),s&&l(Et),s&&l(cs),b(ja),s&&l(Zt),s&&l(Ma),s&&l(At),s&&l(ss),s&&l(kt),s&&l(Cs),s&&l(Bt),b(da,s),s&&l(Gt),s&&l(as),s&&l(Wt),b(ya,s),s&&l(Rt),s&&l(al),s&&l(Vt),b(ba,s),s&&l(Qt),s&&l(_s),s&&l(xt),s&&l(hs),b(Ja),s&&l(Xt),b(wa,s),s&&l(Yt),s&&l(el),s&&l(Nt),b(fa,s),s&&l(Ft),s&&l(tl),s&&l(qt),b(Ta,s),s&&l($t),s&&l(Ua)}}}const Mh={local:"object-detection",sections:[{local:"load-the-cppe5-dataset",title:"Load the CPPE-5 dataset"},{local:"preprocess-the-data",title:"Preprocess the data"},{local:"training-the-detr-model",title:"Training the DETR model"},{local:"evaluate",title:"Evaluate"},{local:"inference",title:"Inference"}],title:"Object detection"};function dh(Ze){return ch(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Th extends ph{constructor(_){super();oh(this,_,dh,jh,rh,{})}}export{Th as default,Mh as metadata};
