import{S as Dl,i as Pl,s as ql,e as r,k as u,w as $,t,M as Ll,c as p,d as a,m as d,a as i,x as I,h as l,b as g,N as Hl,G as s,g as c,y as v,q as k,o as E,B as C,v as Kl,L as Ja}from"../../chunks/vendor-hf-doc-builder.js";import{T as sl}from"../../chunks/Tip-hf-doc-builder.js";import{Y as Ol}from"../../chunks/Youtube-hf-doc-builder.js";import{I as ba}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as cs}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as sn}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";import{F as Re,M as Xe}from"../../chunks/Markdown-hf-doc-builder.js";function en(q){let o,f,n,M,T,J,A,X,Y,R,F,Z,W,N,_,os,B,L,b,V,x,P,O,as,ts;return{c(){o=t(`The task illustrated in this tutorial is supported by the following model architectures:

`),f=r("p"),n=r("a"),M=t("BEiT"),T=t(", "),J=r("a"),A=t("Data2VecVision"),X=t(", "),Y=r("a"),R=t("DPT"),F=t(", "),Z=r("a"),W=t("MobileNetV2"),N=t(", "),_=r("a"),os=t("MobileViT"),B=t(", "),L=r("a"),b=t("MobileViTV2"),V=t(", "),x=r("a"),P=t("SegFormer"),O=t(", "),as=r("a"),ts=t("UPerNet"),this.h()},l(ns){o=l(ns,`The task illustrated in this tutorial is supported by the following model architectures:

`),f=p(ns,"P",{});var G=i(f);n=p(G,"A",{href:!0});var fs=i(n);M=l(fs,"BEiT"),fs.forEach(a),T=l(G,", "),J=p(G,"A",{href:!0});var ms=i(J);A=l(ms,"Data2VecVision"),ms.forEach(a),X=l(G,", "),Y=p(G,"A",{href:!0});var us=i(Y);R=l(us,"DPT"),us.forEach(a),F=l(G,", "),Z=p(G,"A",{href:!0});var K=i(Z);W=l(K,"MobileNetV2"),K.forEach(a),N=l(G,", "),_=p(G,"A",{href:!0});var rs=i(_);os=l(rs,"MobileViT"),rs.forEach(a),B=l(G,", "),L=p(G,"A",{href:!0});var ss=i(L);b=l(ss,"MobileViTV2"),ss.forEach(a),V=l(G,", "),x=p(G,"A",{href:!0});var z=i(x);P=l(z,"SegFormer"),z.forEach(a),O=l(G,", "),as=p(G,"A",{href:!0});var ps=i(as);ts=l(ps,"UPerNet"),ps.forEach(a),G.forEach(a),this.h()},h(){g(n,"href","../model_doc/beit"),g(J,"href","../model_doc/data2vec-vision"),g(Y,"href","../model_doc/dpt"),g(Z,"href","../model_doc/mobilenet_v2"),g(_,"href","../model_doc/mobilevit"),g(L,"href","../model_doc/mobilevitv2"),g(x,"href","../model_doc/segformer"),g(as,"href","../model_doc/upernet")},m(ns,G){c(ns,o,G),c(ns,f,G),s(f,n),s(n,M),s(f,T),s(f,J),s(J,A),s(f,X),s(f,Y),s(Y,R),s(f,F),s(f,Z),s(Z,W),s(f,N),s(f,_),s(_,os),s(f,B),s(f,L),s(L,b),s(f,V),s(f,x),s(x,P),s(f,O),s(f,as),s(as,ts)},d(ns){ns&&a(o),ns&&a(f)}}}function an(q){let o,f,n,M,T,J,A,X,Y,R,F,Z,W,N,_,os,B,L,b,V,x,P,O,as,ts,ns,G,fs,ms,us,K,rs,ss,z,ps,y,Q,is,ys,hs,ds,j,H;return F=new cs({props:{code:"ZnJvbSUyMHRvcmNodmlzaW9uLnRyYW5zZm9ybXMlMjBpbXBvcnQlMjBDb2xvckppdHRlciUwQSUwQWppdHRlciUyMCUzRCUyMENvbG9ySml0dGVyKGJyaWdodG5lc3MlM0QwLjI1JTJDJTIwY29udHJhc3QlM0QwLjI1JTJDJTIwc2F0dXJhdGlvbiUzRDAuMjUlMkMlMjBodWUlM0QwLjEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> torchvision.transforms <span class="hljs-keyword">import</span> ColorJitter

<span class="hljs-meta">&gt;&gt;&gt; </span>jitter = ColorJitter(brightness=<span class="hljs-number">0.25</span>, contrast=<span class="hljs-number">0.25</span>, saturation=<span class="hljs-number">0.25</span>, hue=<span class="hljs-number">0.1</span>)`}}),K=new cs({props:{code:"ZGVmJTIwdHJhaW5fdHJhbnNmb3JtcyhleGFtcGxlX2JhdGNoKSUzQSUwQSUyMCUyMCUyMCUyMGltYWdlcyUyMCUzRCUyMCU1QmppdHRlcih4KSUyMGZvciUyMHglMjBpbiUyMGV4YW1wbGVfYmF0Y2glNUIlMjJpbWFnZSUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMCU1QnglMjBmb3IlMjB4JTIwaW4lMjBleGFtcGxlX2JhdGNoJTVCJTIyYW5ub3RhdGlvbiUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMGlucHV0cyUyMCUzRCUyMGltYWdlX3Byb2Nlc3NvcihpbWFnZXMlMkMlMjBsYWJlbHMpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwaW5wdXRzJTBBJTBBJTBBZGVmJTIwdmFsX3RyYW5zZm9ybXMoZXhhbXBsZV9iYXRjaCklM0ElMEElMjAlMjAlMjAlMjBpbWFnZXMlMjAlM0QlMjAlNUJ4JTIwZm9yJTIweCUyMGluJTIwZXhhbXBsZV9iYXRjaCU1QiUyMmltYWdlJTIyJTVEJTVEJTBBJTIwJTIwJTIwJTIwbGFiZWxzJTIwJTNEJTIwJTVCeCUyMGZvciUyMHglMjBpbiUyMGV4YW1wbGVfYmF0Y2glNUIlMjJhbm5vdGF0aW9uJTIyJTVEJTVEJTBBJTIwJTIwJTIwJTIwaW5wdXRzJTIwJTNEJTIwaW1hZ2VfcHJvY2Vzc29yKGltYWdlcyUyQyUyMGxhYmVscyklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBpbnB1dHM=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">train_transforms</span>(<span class="hljs-params">example_batch</span>):
<span class="hljs-meta">... </span>    images = [jitter(x) <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;image&quot;</span>]]
<span class="hljs-meta">... </span>    labels = [x <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;annotation&quot;</span>]]
<span class="hljs-meta">... </span>    inputs = image_processor(images, labels)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> inputs


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">val_transforms</span>(<span class="hljs-params">example_batch</span>):
<span class="hljs-meta">... </span>    images = [x <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;image&quot;</span>]]
<span class="hljs-meta">... </span>    labels = [x <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;annotation&quot;</span>]]
<span class="hljs-meta">... </span>    inputs = image_processor(images, labels)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> inputs`}}),j=new cs({props:{code:"dHJhaW5fZHMuc2V0X3RyYW5zZm9ybSh0cmFpbl90cmFuc2Zvcm1zKSUwQXRlc3RfZHMuc2V0X3RyYW5zZm9ybSh2YWxfdHJhbnNmb3Jtcyk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>train_ds.set_transform(train_transforms)
<span class="hljs-meta">&gt;&gt;&gt; </span>test_ds.set_transform(val_transforms)`}}),{c(){o=r("p"),f=t("It is common to apply some data augmentations to an image dataset to make a model more robust against overfitting. In this guide, you\u2019ll use the "),n=r("a"),M=r("code"),T=t("ColorJitter"),J=t(" function from "),A=r("a"),X=t("torchvision"),Y=t(" to randomly change the color properties of an image, but you can also use any image library you like."),R=u(),$(F.$$.fragment),Z=u(),W=r("p"),N=t("Now create two preprocessing functions to prepare the images and annotations for the model. These functions convert the images into "),_=r("code"),os=t("pixel_values"),B=t(" and annotations to "),L=r("code"),b=t("labels"),V=t(". For the training set, "),x=r("code"),P=t("jitter"),O=t(" is applied before providing the images to the image processor. For the test set, the image processor crops and normalizes the "),as=r("code"),ts=t("images"),ns=t(", and only crops the "),G=r("code"),fs=t("labels"),ms=t(" because no data augmentation is applied during testing."),us=u(),$(K.$$.fragment),rs=u(),ss=r("p"),z=t("To apply the "),ps=r("code"),y=t("jitter"),Q=t(" over the entire dataset, use the \u{1F917} Datasets "),is=r("a"),ys=t("set_transform"),hs=t(" function. The transform is applied on the fly which is faster and consumes less disk space:"),ds=u(),$(j.$$.fragment),this.h()},l(w){o=p(w,"P",{});var es=i(o);f=l(es,"It is common to apply some data augmentations to an image dataset to make a model more robust against overfitting. In this guide, you\u2019ll use the "),n=p(es,"A",{href:!0,rel:!0});var gs=i(n);M=p(gs,"CODE",{});var js=i(M);T=l(js,"ColorJitter"),js.forEach(a),gs.forEach(a),J=l(es," function from "),A=p(es,"A",{href:!0,rel:!0});var Cs=i(A);X=l(Cs,"torchvision"),Cs.forEach(a),Y=l(es," to randomly change the color properties of an image, but you can also use any image library you like."),es.forEach(a),R=d(w),I(F.$$.fragment,w),Z=d(w),W=p(w,"P",{});var S=i(W);N=l(S,"Now create two preprocessing functions to prepare the images and annotations for the model. These functions convert the images into "),_=p(S,"CODE",{});var Bs=i(_);os=l(Bs,"pixel_values"),Bs.forEach(a),B=l(S," and annotations to "),L=p(S,"CODE",{});var bs=i(L);b=l(bs,"labels"),bs.forEach(a),V=l(S,". For the training set, "),x=p(S,"CODE",{});var ks=i(x);P=l(ks,"jitter"),ks.forEach(a),O=l(S," is applied before providing the images to the image processor. For the test set, the image processor crops and normalizes the "),as=p(S,"CODE",{});var Is=i(as);ts=l(Is,"images"),Is.forEach(a),ns=l(S,", and only crops the "),G=p(S,"CODE",{});var Us=i(G);fs=l(Us,"labels"),Us.forEach(a),ms=l(S," because no data augmentation is applied during testing."),S.forEach(a),us=d(w),I(K.$$.fragment,w),rs=d(w),ss=p(w,"P",{});var _s=i(ss);z=l(_s,"To apply the "),ps=p(_s,"CODE",{});var Es=i(ps);y=l(Es,"jitter"),Es.forEach(a),Q=l(_s," over the entire dataset, use the \u{1F917} Datasets "),is=p(_s,"A",{href:!0,rel:!0});var Js=i(is);ys=l(Js,"set_transform"),Js.forEach(a),hs=l(_s," function. The transform is applied on the fly which is faster and consumes less disk space:"),_s.forEach(a),ds=d(w),I(j.$$.fragment,w),this.h()},h(){g(n,"href","https://pytorch.org/vision/stable/generated/torchvision.transforms.ColorJitter.html"),g(n,"rel","nofollow"),g(A,"href","https://pytorch.org/vision/stable/index.html"),g(A,"rel","nofollow"),g(is,"href","https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.set_transform"),g(is,"rel","nofollow")},m(w,es){c(w,o,es),s(o,f),s(o,n),s(n,M),s(M,T),s(o,J),s(o,A),s(A,X),s(o,Y),c(w,R,es),v(F,w,es),c(w,Z,es),c(w,W,es),s(W,N),s(W,_),s(_,os),s(W,B),s(W,L),s(L,b),s(W,V),s(W,x),s(x,P),s(W,O),s(W,as),s(as,ts),s(W,ns),s(W,G),s(G,fs),s(W,ms),c(w,us,es),v(K,w,es),c(w,rs,es),c(w,ss,es),s(ss,z),s(ss,ps),s(ps,y),s(ss,Q),s(ss,is),s(is,ys),s(ss,hs),c(w,ds,es),v(j,w,es),H=!0},p:Ja,i(w){H||(k(F.$$.fragment,w),k(K.$$.fragment,w),k(j.$$.fragment,w),H=!0)},o(w){E(F.$$.fragment,w),E(K.$$.fragment,w),E(j.$$.fragment,w),H=!1},d(w){w&&a(o),w&&a(R),C(F,w),w&&a(Z),w&&a(W),w&&a(us),C(K,w),w&&a(rs),w&&a(ss),w&&a(ds),C(j,w)}}}function tn(q){let o,f;return o=new Xe({props:{$$slots:{default:[an]},$$scope:{ctx:q}}}),{c(){$(o.$$.fragment)},l(n){I(o.$$.fragment,n)},m(n,M){v(o,n,M),f=!0},p(n,M){const T={};M&2&&(T.$$scope={dirty:M,ctx:n}),o.$set(T)},i(n){f||(k(o.$$.fragment,n),f=!0)},o(n){E(o.$$.fragment,n),f=!1},d(n){C(o,n)}}}function ln(q){let o,f,n,M,T,J,A,X,Y,R,F,Z,W,N,_,os,B,L,b,V,x,P,O,as,ts,ns,G,fs,ms,us,K,rs,ss,z,ps,y,Q,is,ys,hs,ds;return _=new cs({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEElMEFkZWYlMjBhdWdfdHJhbnNmb3JtcyhpbWFnZSklM0ElMEElMjAlMjAlMjAlMjBpbWFnZSUyMCUzRCUyMHRmLmtlcmFzLnV0aWxzLmltZ190b19hcnJheShpbWFnZSklMEElMjAlMjAlMjAlMjBpbWFnZSUyMCUzRCUyMHRmLmltYWdlLnJhbmRvbV9icmlnaHRuZXNzKGltYWdlJTJDJTIwMC4yNSklMEElMjAlMjAlMjAlMjBpbWFnZSUyMCUzRCUyMHRmLmltYWdlLnJhbmRvbV9jb250cmFzdChpbWFnZSUyQyUyMDAuNSUyQyUyMDIuMCklMEElMjAlMjAlMjAlMjBpbWFnZSUyMCUzRCUyMHRmLmltYWdlLnJhbmRvbV9zYXR1cmF0aW9uKGltYWdlJTJDJTIwMC43NSUyQyUyMDEuMjUpJTBBJTIwJTIwJTIwJTIwaW1hZ2UlMjAlM0QlMjB0Zi5pbWFnZS5yYW5kb21faHVlKGltYWdlJTJDJTIwMC4xKSUwQSUyMCUyMCUyMCUyMGltYWdlJTIwJTNEJTIwdGYudHJhbnNwb3NlKGltYWdlJTJDJTIwKDIlMkMlMjAwJTJDJTIwMSkpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwaW1hZ2UlMEElMEElMEFkZWYlMjB0cmFuc2Zvcm1zKGltYWdlKSUzQSUwQSUyMCUyMCUyMCUyMGltYWdlJTIwJTNEJTIwdGYua2VyYXMudXRpbHMuaW1nX3RvX2FycmF5KGltYWdlKSUwQSUyMCUyMCUyMCUyMGltYWdlJTIwJTNEJTIwdGYudHJhbnNwb3NlKGltYWdlJTJDJTIwKDIlMkMlMjAwJTJDJTIwMSkpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwaW1hZ2U=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">aug_transforms</span>(<span class="hljs-params">image</span>):
<span class="hljs-meta">... </span>    image = tf.keras.utils.img_to_array(image)
<span class="hljs-meta">... </span>    image = tf.image.random_brightness(image, <span class="hljs-number">0.25</span>)
<span class="hljs-meta">... </span>    image = tf.image.random_contrast(image, <span class="hljs-number">0.5</span>, <span class="hljs-number">2.0</span>)
<span class="hljs-meta">... </span>    image = tf.image.random_saturation(image, <span class="hljs-number">0.75</span>, <span class="hljs-number">1.25</span>)
<span class="hljs-meta">... </span>    image = tf.image.random_hue(image, <span class="hljs-number">0.1</span>)
<span class="hljs-meta">... </span>    image = tf.transpose(image, (<span class="hljs-number">2</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>))
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> image


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">transforms</span>(<span class="hljs-params">image</span>):
<span class="hljs-meta">... </span>    image = tf.keras.utils.img_to_array(image)
<span class="hljs-meta">... </span>    image = tf.transpose(image, (<span class="hljs-number">2</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>))
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> image`}}),rs=new cs({props:{code:"ZGVmJTIwdHJhaW5fdHJhbnNmb3JtcyhleGFtcGxlX2JhdGNoKSUzQSUwQSUyMCUyMCUyMCUyMGltYWdlcyUyMCUzRCUyMCU1QmF1Z190cmFuc2Zvcm1zKHguY29udmVydCglMjJSR0IlMjIpKSUyMGZvciUyMHglMjBpbiUyMGV4YW1wbGVfYmF0Y2glNUIlMjJpbWFnZSUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMCU1QnglMjBmb3IlMjB4JTIwaW4lMjBleGFtcGxlX2JhdGNoJTVCJTIyYW5ub3RhdGlvbiUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMGlucHV0cyUyMCUzRCUyMGltYWdlX3Byb2Nlc3NvcihpbWFnZXMlMkMlMjBsYWJlbHMpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwaW5wdXRzJTBBJTBBJTBBZGVmJTIwdmFsX3RyYW5zZm9ybXMoZXhhbXBsZV9iYXRjaCklM0ElMEElMjAlMjAlMjAlMjBpbWFnZXMlMjAlM0QlMjAlNUJ0cmFuc2Zvcm1zKHguY29udmVydCglMjJSR0IlMjIpKSUyMGZvciUyMHglMjBpbiUyMGV4YW1wbGVfYmF0Y2glNUIlMjJpbWFnZSUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMCU1QnglMjBmb3IlMjB4JTIwaW4lMjBleGFtcGxlX2JhdGNoJTVCJTIyYW5ub3RhdGlvbiUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMGlucHV0cyUyMCUzRCUyMGltYWdlX3Byb2Nlc3NvcihpbWFnZXMlMkMlMjBsYWJlbHMpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwaW5wdXRz",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">train_transforms</span>(<span class="hljs-params">example_batch</span>):
<span class="hljs-meta">... </span>    images = [aug_transforms(x.convert(<span class="hljs-string">&quot;RGB&quot;</span>)) <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;image&quot;</span>]]
<span class="hljs-meta">... </span>    labels = [x <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;annotation&quot;</span>]]
<span class="hljs-meta">... </span>    inputs = image_processor(images, labels)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> inputs


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">val_transforms</span>(<span class="hljs-params">example_batch</span>):
<span class="hljs-meta">... </span>    images = [transforms(x.convert(<span class="hljs-string">&quot;RGB&quot;</span>)) <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;image&quot;</span>]]
<span class="hljs-meta">... </span>    labels = [x <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;annotation&quot;</span>]]
<span class="hljs-meta">... </span>    inputs = image_processor(images, labels)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> inputs`}}),hs=new cs({props:{code:"dHJhaW5fZHMuc2V0X3RyYW5zZm9ybSh0cmFpbl90cmFuc2Zvcm1zKSUwQXRlc3RfZHMuc2V0X3RyYW5zZm9ybSh2YWxfdHJhbnNmb3Jtcyk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>train_ds.set_transform(train_transforms)
<span class="hljs-meta">&gt;&gt;&gt; </span>test_ds.set_transform(val_transforms)`}}),{c(){o=r("p"),f=t(`It is common to apply some data augmentations to an image dataset to make a model more robust against overfitting.
In this guide, you\u2019ll use `),n=r("a"),M=r("code"),T=t("tf.image"),J=t(` to randomly change the color properties of an image, but you can also use any image
library you like.
Define two separate transformation functions:`),A=u(),X=r("ul"),Y=r("li"),R=t("training data transformations that include image augmentation"),F=u(),Z=r("li"),W=t("validation data transformations that only transpose the images, since computer vision models in \u{1F917} Transformers expect channels-first layout"),N=u(),$(_.$$.fragment),os=u(),B=r("p"),L=t(`Next, create two preprocessing functions to prepare batches of images and annotations for the model. These functions apply
the image transformations and use the earlier loaded `),b=r("code"),V=t("image_processor"),x=t(" to convert the images into "),P=r("code"),O=t("pixel_values"),as=t(` and
annotations to `),ts=r("code"),ns=t("labels"),G=t(". "),fs=r("code"),ms=t("ImageProcessor"),us=t(" also takes care of resizing and normalizing the images."),K=u(),$(rs.$$.fragment),ss=u(),z=r("p"),ps=t("To apply the preprocessing transformations over the entire dataset, use the \u{1F917} Datasets "),y=r("a"),Q=t("set_transform"),is=t(` function.
The transform is applied on the fly which is faster and consumes less disk space:`),ys=u(),$(hs.$$.fragment),this.h()},l(j){o=p(j,"P",{});var H=i(o);f=l(H,`It is common to apply some data augmentations to an image dataset to make a model more robust against overfitting.
In this guide, you\u2019ll use `),n=p(H,"A",{href:!0,rel:!0});var w=i(n);M=p(w,"CODE",{});var es=i(M);T=l(es,"tf.image"),es.forEach(a),w.forEach(a),J=l(H,` to randomly change the color properties of an image, but you can also use any image
library you like.
Define two separate transformation functions:`),H.forEach(a),A=d(j),X=p(j,"UL",{});var gs=i(X);Y=p(gs,"LI",{});var js=i(Y);R=l(js,"training data transformations that include image augmentation"),js.forEach(a),F=d(gs),Z=p(gs,"LI",{});var Cs=i(Z);W=l(Cs,"validation data transformations that only transpose the images, since computer vision models in \u{1F917} Transformers expect channels-first layout"),Cs.forEach(a),gs.forEach(a),N=d(j),I(_.$$.fragment,j),os=d(j),B=p(j,"P",{});var S=i(B);L=l(S,`Next, create two preprocessing functions to prepare batches of images and annotations for the model. These functions apply
the image transformations and use the earlier loaded `),b=p(S,"CODE",{});var Bs=i(b);V=l(Bs,"image_processor"),Bs.forEach(a),x=l(S," to convert the images into "),P=p(S,"CODE",{});var bs=i(P);O=l(bs,"pixel_values"),bs.forEach(a),as=l(S,` and
annotations to `),ts=p(S,"CODE",{});var ks=i(ts);ns=l(ks,"labels"),ks.forEach(a),G=l(S,". "),fs=p(S,"CODE",{});var Is=i(fs);ms=l(Is,"ImageProcessor"),Is.forEach(a),us=l(S," also takes care of resizing and normalizing the images."),S.forEach(a),K=d(j),I(rs.$$.fragment,j),ss=d(j),z=p(j,"P",{});var Us=i(z);ps=l(Us,"To apply the preprocessing transformations over the entire dataset, use the \u{1F917} Datasets "),y=p(Us,"A",{href:!0,rel:!0});var _s=i(y);Q=l(_s,"set_transform"),_s.forEach(a),is=l(Us,` function.
The transform is applied on the fly which is faster and consumes less disk space:`),Us.forEach(a),ys=d(j),I(hs.$$.fragment,j),this.h()},h(){g(n,"href","https://www.tensorflow.org/api_docs/python/tf/image"),g(n,"rel","nofollow"),g(y,"href","https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.set_transform"),g(y,"rel","nofollow")},m(j,H){c(j,o,H),s(o,f),s(o,n),s(n,M),s(M,T),s(o,J),c(j,A,H),c(j,X,H),s(X,Y),s(Y,R),s(X,F),s(X,Z),s(Z,W),c(j,N,H),v(_,j,H),c(j,os,H),c(j,B,H),s(B,L),s(B,b),s(b,V),s(B,x),s(B,P),s(P,O),s(B,as),s(B,ts),s(ts,ns),s(B,G),s(B,fs),s(fs,ms),s(B,us),c(j,K,H),v(rs,j,H),c(j,ss,H),c(j,z,H),s(z,ps),s(z,y),s(y,Q),s(z,is),c(j,ys,H),v(hs,j,H),ds=!0},p:Ja,i(j){ds||(k(_.$$.fragment,j),k(rs.$$.fragment,j),k(hs.$$.fragment,j),ds=!0)},o(j){E(_.$$.fragment,j),E(rs.$$.fragment,j),E(hs.$$.fragment,j),ds=!1},d(j){j&&a(o),j&&a(A),j&&a(X),j&&a(N),C(_,j),j&&a(os),j&&a(B),j&&a(K),C(rs,j),j&&a(ss),j&&a(z),j&&a(ys),C(hs,j)}}}function nn(q){let o,f;return o=new Xe({props:{$$slots:{default:[ln]},$$scope:{ctx:q}}}),{c(){$(o.$$.fragment)},l(n){I(o.$$.fragment,n)},m(n,M){v(o,n,M),f=!0},p(n,M){const T={};M&2&&(T.$$scope={dirty:M,ctx:n}),o.$set(T)},i(n){f||(k(o.$$.fragment,n),f=!0)},o(n){E(o.$$.fragment,n),f=!1},d(n){C(o,n)}}}function on(q){let o,f;return o=new cs({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBaW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdG9yY2glMjBpbXBvcnQlMjBubiUwQSUwQWRlZiUyMGNvbXB1dGVfbWV0cmljcyhldmFsX3ByZWQpJTNBJTBBJTIwJTIwJTIwJTIwd2l0aCUyMHRvcmNoLm5vX2dyYWQoKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxvZ2l0cyUyQyUyMGxhYmVscyUyMCUzRCUyMGV2YWxfcHJlZCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxvZ2l0c190ZW5zb3IlMjAlM0QlMjB0b3JjaC5mcm9tX251bXB5KGxvZ2l0cyklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsb2dpdHNfdGVuc29yJTIwJTNEJTIwbm4uZnVuY3Rpb25hbC5pbnRlcnBvbGF0ZSglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsb2dpdHNfdGVuc29yJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2l6ZSUzRGxhYmVscy5zaGFwZSU1Qi0yJTNBJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbW9kZSUzRCUyMmJpbGluZWFyJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYWxpZ25fY29ybmVycyUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKS5hcmdtYXgoZGltJTNEMSklMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmVkX2xhYmVscyUyMCUzRCUyMGxvZ2l0c190ZW5zb3IuZGV0YWNoKCkuY3B1KCkubnVtcHkoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG1ldHJpY3MlMjAlM0QlMjBtZXRyaWMuY29tcHV0ZSglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUzRHByZWRfbGFiZWxzJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmVmZXJlbmNlcyUzRGxhYmVscyUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9sYWJlbHMlM0RudW1fbGFiZWxzJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaWdub3JlX2luZGV4JTNEMjU1JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmVkdWNlX2xhYmVscyUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZvciUyMGtleSUyQyUyMHZhbHVlJTIwaW4lMjBtZXRyaWNzLml0ZW1zKCklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpZiUyMHR5cGUodmFsdWUpJTIwaXMlMjBucC5uZGFycmF5JTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbWV0cmljcyU1QmtleSU1RCUyMCUzRCUyMHZhbHVlLnRvbGlzdCgpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmV0dXJuJTIwbWV0cmljcw==",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> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> torch <span class="hljs-keyword">import</span> nn

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_pred</span>):
<span class="hljs-meta">... </span>    <span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>        logits, labels = eval_pred
<span class="hljs-meta">... </span>        logits_tensor = torch.from_numpy(logits)
<span class="hljs-meta">... </span>        logits_tensor = nn.functional.interpolate(
<span class="hljs-meta">... </span>            logits_tensor,
<span class="hljs-meta">... </span>            size=labels.shape[-<span class="hljs-number">2</span>:],
<span class="hljs-meta">... </span>            mode=<span class="hljs-string">&quot;bilinear&quot;</span>,
<span class="hljs-meta">... </span>            align_corners=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>        ).argmax(dim=<span class="hljs-number">1</span>)

<span class="hljs-meta">... </span>        pred_labels = logits_tensor.detach().cpu().numpy()
<span class="hljs-meta">... </span>        metrics = metric.compute(
<span class="hljs-meta">... </span>            predictions=pred_labels,
<span class="hljs-meta">... </span>            references=labels,
<span class="hljs-meta">... </span>            num_labels=num_labels,
<span class="hljs-meta">... </span>            ignore_index=<span class="hljs-number">255</span>,
<span class="hljs-meta">... </span>            reduce_labels=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>        )
<span class="hljs-meta">... </span>        <span class="hljs-keyword">for</span> key, value <span class="hljs-keyword">in</span> metrics.items():
<span class="hljs-meta">... </span>            <span class="hljs-keyword">if</span> <span class="hljs-built_in">type</span>(value) <span class="hljs-keyword">is</span> np.ndarray:
<span class="hljs-meta">... </span>                metrics[key] = value.tolist()
<span class="hljs-meta">... </span>        <span class="hljs-keyword">return</span> metrics`}}),{c(){$(o.$$.fragment)},l(n){I(o.$$.fragment,n)},m(n,M){v(o,n,M),f=!0},p:Ja,i(n){f||(k(o.$$.fragment,n),f=!0)},o(n){E(o.$$.fragment,n),f=!1},d(n){C(o,n)}}}function rn(q){let o,f;return o=new Xe({props:{$$slots:{default:[on]},$$scope:{ctx:q}}}),{c(){$(o.$$.fragment)},l(n){I(o.$$.fragment,n)},m(n,M){v(o,n,M),f=!0},p(n,M){const T={};M&2&&(T.$$scope={dirty:M,ctx:n}),o.$set(T)},i(n){f||(k(o.$$.fragment,n),f=!0)},o(n){E(o.$$.fragment,n),f=!1},d(n){C(o,n)}}}function pn(q){let o,f;return o=new cs({props:{code:"ZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZCklM0ElMEElMjAlMjAlMjAlMjBsb2dpdHMlMkMlMjBsYWJlbHMlMjAlM0QlMjBldmFsX3ByZWQlMEElMjAlMjAlMjAlMjBsb2dpdHMlMjAlM0QlMjB0Zi50cmFuc3Bvc2UobG9naXRzJTJDJTIwcGVybSUzRCU1QjAlMkMlMjAyJTJDJTIwMyUyQyUyMDElNUQpJTBBJTIwJTIwJTIwJTIwbG9naXRzX3Jlc2l6ZWQlMjAlM0QlMjB0Zi5pbWFnZS5yZXNpemUoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbG9naXRzJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2l6ZSUzRHRmLnNoYXBlKGxhYmVscyklNUIxJTNBJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbWV0aG9kJTNEJTIyYmlsaW5lYXIlMjIlMkMlMEElMjAlMjAlMjAlMjApJTBBJTBBJTIwJTIwJTIwJTIwcHJlZF9sYWJlbHMlMjAlM0QlMjB0Zi5hcmdtYXgobG9naXRzX3Jlc2l6ZWQlMkMlMjBheGlzJTNELTEpJTBBJTIwJTIwJTIwJTIwbWV0cmljcyUyMCUzRCUyMG1ldHJpYy5jb21wdXRlKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHByZWRpY3Rpb25zJTNEcHJlZF9sYWJlbHMlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZWZlcmVuY2VzJTNEbGFiZWxzJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbnVtX2xhYmVscyUzRG51bV9sYWJlbHMlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpZ25vcmVfaW5kZXglM0QtMSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJlZHVjZV9sYWJlbHMlM0RpbWFnZV9wcm9jZXNzb3IuZG9fcmVkdWNlX2xhYmVscyUyQyUwQSUyMCUyMCUyMCUyMCklMEElMEElMjAlMjAlMjAlMjBwZXJfY2F0ZWdvcnlfYWNjdXJhY3klMjAlM0QlMjBtZXRyaWNzLnBvcCglMjJwZXJfY2F0ZWdvcnlfYWNjdXJhY3klMjIpLnRvbGlzdCgpJTBBJTIwJTIwJTIwJTIwcGVyX2NhdGVnb3J5X2lvdSUyMCUzRCUyMG1ldHJpY3MucG9wKCUyMnBlcl9jYXRlZ29yeV9pb3UlMjIpLnRvbGlzdCgpJTBBJTBBJTIwJTIwJTIwJTIwbWV0cmljcy51cGRhdGUoJTdCZiUyMmFjY3VyYWN5XyU3QmlkMmxhYmVsJTVCaSU1RCU3RCUyMiUzQSUyMHYlMjBmb3IlMjBpJTJDJTIwdiUyMGluJTIwZW51bWVyYXRlKHBlcl9jYXRlZ29yeV9hY2N1cmFjeSklN0QpJTBBJTIwJTIwJTIwJTIwbWV0cmljcy51cGRhdGUoJTdCZiUyMmlvdV8lN0JpZDJsYWJlbCU1QmklNUQlN0QlMjIlM0ElMjB2JTIwZm9yJTIwaSUyQyUyMHYlMjBpbiUyMGVudW1lcmF0ZShwZXJfY2F0ZWdvcnlfaW91KSU3RCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjAlN0IlMjJ2YWxfJTIyJTIwJTJCJTIwayUzQSUyMHYlMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwbWV0cmljcy5pdGVtcygpJTdE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_pred</span>):
<span class="hljs-meta">... </span>    logits, labels = eval_pred
<span class="hljs-meta">... </span>    logits = tf.transpose(logits, perm=[<span class="hljs-number">0</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">1</span>])
<span class="hljs-meta">... </span>    logits_resized = tf.image.resize(
<span class="hljs-meta">... </span>        logits,
<span class="hljs-meta">... </span>        size=tf.shape(labels)[<span class="hljs-number">1</span>:],
<span class="hljs-meta">... </span>        method=<span class="hljs-string">&quot;bilinear&quot;</span>,
<span class="hljs-meta">... </span>    )

<span class="hljs-meta">... </span>    pred_labels = tf.argmax(logits_resized, axis=-<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    metrics = metric.compute(
<span class="hljs-meta">... </span>        predictions=pred_labels,
<span class="hljs-meta">... </span>        references=labels,
<span class="hljs-meta">... </span>        num_labels=num_labels,
<span class="hljs-meta">... </span>        ignore_index=-<span class="hljs-number">1</span>,
<span class="hljs-meta">... </span>        reduce_labels=image_processor.do_reduce_labels,
<span class="hljs-meta">... </span>    )

<span class="hljs-meta">... </span>    per_category_accuracy = metrics.pop(<span class="hljs-string">&quot;per_category_accuracy&quot;</span>).tolist()
<span class="hljs-meta">... </span>    per_category_iou = metrics.pop(<span class="hljs-string">&quot;per_category_iou&quot;</span>).tolist()

<span class="hljs-meta">... </span>    metrics.update({<span class="hljs-string">f&quot;accuracy_<span class="hljs-subst">{id2label[i]}</span>&quot;</span>: v <span class="hljs-keyword">for</span> i, v <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(per_category_accuracy)})
<span class="hljs-meta">... </span>    metrics.update({<span class="hljs-string">f&quot;iou_<span class="hljs-subst">{id2label[i]}</span>&quot;</span>: v <span class="hljs-keyword">for</span> i, v <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(per_category_iou)})
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;val_&quot;</span> + k: v <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> metrics.items()}`}}),{c(){$(o.$$.fragment)},l(n){I(o.$$.fragment,n)},m(n,M){v(o,n,M),f=!0},p:Ja,i(n){f||(k(o.$$.fragment,n),f=!0)},o(n){E(o.$$.fragment,n),f=!1},d(n){C(o,n)}}}function cn(q){let o,f;return o=new Xe({props:{$$slots:{default:[pn]},$$scope:{ctx:q}}}),{c(){$(o.$$.fragment)},l(n){I(o.$$.fragment,n)},m(n,M){v(o,n,M),f=!0},p(n,M){const T={};M&2&&(T.$$scope={dirty:M,ctx:n}),o.$set(T)},i(n){f||(k(o.$$.fragment,n),f=!0)},o(n){E(o.$$.fragment,n),f=!1},d(n){C(o,n)}}}function mn(q){let o,f,n,M,T,J,A,X;return{c(){o=r("p"),f=t("If you aren\u2019t familiar with finetuning a model with the "),n=r("a"),M=t("Trainer"),T=t(", take a look at the basic tutorial "),J=r("a"),A=t("here"),X=t("!"),this.h()},l(Y){o=p(Y,"P",{});var R=i(o);f=l(R,"If you aren\u2019t familiar with finetuning a model with the "),n=p(R,"A",{href:!0});var F=i(n);M=l(F,"Trainer"),F.forEach(a),T=l(R,", take a look at the basic tutorial "),J=p(R,"A",{href:!0});var Z=i(J);A=l(Z,"here"),Z.forEach(a),X=l(R,"!"),R.forEach(a),this.h()},h(){g(n,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer"),g(J,"href","../training#finetune-with-trainer")},m(Y,R){c(Y,o,R),s(o,f),s(o,n),s(n,M),s(o,T),s(o,J),s(J,A),s(o,X)},d(Y){Y&&a(o)}}}function hn(q){let o,f,n,M,T,J,A,X,Y,R,F,Z,W,N,_,os,B,L,b,V,x,P,O,as,ts,ns,G,fs,ms,us,K,rs,ss,z,ps,y,Q,is,ys,hs,ds,j,H,w,es,gs,js,Cs,S,Bs,bs,ks,Is,Us,_s,Es,Js,ws,Ts,Fs,As,ae,zs,Rs,Xs,Ys;return o=new sl({props:{$$slots:{default:[mn]},$$scope:{ctx:q}}}),Y=new cs({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlbWFudGljU2VnbWVudGF0aW9uJTJDJTIwVHJhaW5pbmdBcmd1bWVudHMlMkMlMjBUcmFpbmVyJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZW1hbnRpY1NlZ21lbnRhdGlvbi5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCUyQyUyMGlkMmxhYmVsJTNEaWQybGFiZWwlMkMlMjBsYWJlbDJpZCUzRGxhYmVsMmlkKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSemanticSegmentation, TrainingArguments, Trainer

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSemanticSegmentation.from_pretrained(checkpoint, id2label=id2label, label2id=label2id)`}}),Js=new cs({props:{code:"dHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0QlMjJzZWdmb3JtZXItYjAtc2NlbmUtcGFyc2UtMTUwJTIyJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDZlLTUlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fZXBvY2hzJTNENTAlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX3RyYWluX2JhdGNoX3NpemUlM0QyJTJDJTBBJTIwJTIwJTIwJTIwcGVyX2RldmljZV9ldmFsX2JhdGNoX3NpemUlM0QyJTJDJTBBJTIwJTIwJTIwJTIwc2F2ZV90b3RhbF9saW1pdCUzRDMlMkMlMEElMjAlMjAlMjAlMjBldmFsdWF0aW9uX3N0cmF0ZWd5JTNEJTIyc3RlcHMlMjIlMkMlMEElMjAlMjAlMjAlMjBzYXZlX3N0cmF0ZWd5JTNEJTIyc3RlcHMlMjIlMkMlMEElMjAlMjAlMjAlMjBzYXZlX3N0ZXBzJTNEMjAlMkMlMEElMjAlMjAlMjAlMjBldmFsX3N0ZXBzJTNEMjAlMkMlMEElMjAlMjAlMjAlMjBsb2dnaW5nX3N0ZXBzJTNEMSUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfYWNjdW11bGF0aW9uX3N0ZXBzJTNENSUyQyUwQSUyMCUyMCUyMCUyMHJlbW92ZV91bnVzZWRfY29sdW1ucyUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwcHVzaF90b19odWIlM0RUcnVlJTJDJTBBKSUwQSUwQXRyYWluZXIlMjAlM0QlMjBUcmFpbmVyKCUwQSUyMCUyMCUyMCUyMG1vZGVsJTNEbW9kZWwlMkMlMEElMjAlMjAlMjAlMjBhcmdzJTNEdHJhaW5pbmdfYXJncyUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0R0cmFpbl9kcyUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfZGF0YXNldCUzRHRlc3RfZHMlMkMlMEElMjAlMjAlMjAlMjBjb21wdXRlX21ldHJpY3MlM0Rjb21wdXRlX21ldHJpY3MlMkMlMEEpJTBBJTBBdHJhaW5lci50cmFpbigp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;segformer-b0-scene-parse-150&quot;</span>,
<span class="hljs-meta">... </span>    learning_rate=<span class="hljs-number">6e-5</span>,
<span class="hljs-meta">... </span>    num_train_epochs=<span class="hljs-number">50</span>,
<span class="hljs-meta">... </span>    per_device_train_batch_size=<span class="hljs-number">2</span>,
<span class="hljs-meta">... </span>    per_device_eval_batch_size=<span class="hljs-number">2</span>,
<span class="hljs-meta">... </span>    save_total_limit=<span class="hljs-number">3</span>,
<span class="hljs-meta">... </span>    evaluation_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
<span class="hljs-meta">... </span>    save_strategy=<span class="hljs-string">&quot;steps&quot;</span>,
<span class="hljs-meta">... </span>    save_steps=<span class="hljs-number">20</span>,
<span class="hljs-meta">... </span>    eval_steps=<span class="hljs-number">20</span>,
<span class="hljs-meta">... </span>    logging_steps=<span class="hljs-number">1</span>,
<span class="hljs-meta">... </span>    eval_accumulation_steps=<span class="hljs-number">5</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>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer = Trainer(
<span class="hljs-meta">... </span>    model=model,
<span class="hljs-meta">... </span>    args=training_args,
<span class="hljs-meta">... </span>    train_dataset=train_ds,
<span class="hljs-meta">... </span>    eval_dataset=test_ds,
<span class="hljs-meta">... </span>    compute_metrics=compute_metrics,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()`}}),Xs=new cs({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()'}}),{c(){$(o.$$.fragment),f=u(),n=r("p"),M=t("You\u2019re ready to start training your model now! Load SegFormer with "),T=r("a"),J=t("AutoModelForSemanticSegmentation"),A=t(", and pass the model the mapping between label ids and label classes:"),X=u(),$(Y.$$.fragment),R=u(),F=r("p"),Z=t("At this point, only three steps remain:"),W=u(),N=r("ol"),_=r("li"),os=t("Define your training hyperparameters in "),B=r("a"),L=t("TrainingArguments"),b=t(". It is important you don\u2019t remove unused columns because this\u2019ll drop the "),V=r("code"),x=t("image"),P=t(" column. Without the "),O=r("code"),as=t("image"),ts=t(" column, you can\u2019t create "),ns=r("code"),G=t("pixel_values"),fs=t(". Set "),ms=r("code"),us=t("remove_unused_columns=False"),K=t(" to prevent this behavior! The only other required parameter is "),rs=r("code"),ss=t("output_dir"),z=t(" which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),ps=r("code"),y=t("push_to_hub=True"),Q=t(" (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),is=r("a"),ys=t("Trainer"),hs=t(" will evaluate the IoU metric and save the training checkpoint."),ds=u(),j=r("li"),H=t("Pass the training arguments to "),w=r("a"),es=t("Trainer"),gs=t(" along with the model, dataset, tokenizer, data collator, and "),js=r("code"),Cs=t("compute_metrics"),S=t(" function."),Bs=u(),bs=r("li"),ks=t("Call "),Is=r("a"),Us=t("train()"),_s=t(" to finetune your model."),Es=u(),$(Js.$$.fragment),ws=u(),Ts=r("p"),Fs=t("Once training is completed, share your model to the Hub with the "),As=r("a"),ae=t("push_to_hub()"),zs=t(" method so everyone can use your model:"),Rs=u(),$(Xs.$$.fragment),this.h()},l(U){I(o.$$.fragment,U),f=d(U),n=p(U,"P",{});var ls=i(n);M=l(ls,"You\u2019re ready to start training your model now! Load SegFormer with "),T=p(ls,"A",{href:!0});var Gs=i(T);J=l(Gs,"AutoModelForSemanticSegmentation"),Gs.forEach(a),A=l(ls,", and pass the model the mapping between label ids and label classes:"),ls.forEach(a),X=d(U),I(Y.$$.fragment,U),R=d(U),F=p(U,"P",{});var Ss=i(F);Z=l(Ss,"At this point, only three steps remain:"),Ss.forEach(a),W=d(U),N=p(U,"OL",{});var Vs=i(N);_=p(Vs,"LI",{});var Ms=i(_);os=l(Ms,"Define your training hyperparameters in "),B=p(Ms,"A",{href:!0});var Zs=i(B);L=l(Zs,"TrainingArguments"),Zs.forEach(a),b=l(Ms,". It is important you don\u2019t remove unused columns because this\u2019ll drop the "),V=p(Ms,"CODE",{});var Ls=i(V);x=l(Ls,"image"),Ls.forEach(a),P=l(Ms," column. Without the "),O=p(Ms,"CODE",{});var $s=i(O);as=l($s,"image"),$s.forEach(a),ts=l(Ms," column, you can\u2019t create "),ns=p(Ms,"CODE",{});var Qs=i(ns);G=l(Qs,"pixel_values"),Qs.forEach(a),fs=l(Ms,". Set "),ms=p(Ms,"CODE",{});var xs=i(ms);us=l(xs,"remove_unused_columns=False"),xs.forEach(a),K=l(Ms," to prevent this behavior! The only other required parameter is "),rs=p(Ms,"CODE",{});var ne=i(rs);ss=l(ne,"output_dir"),ne.forEach(a),z=l(Ms," which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),ps=p(Ms,"CODE",{});var oe=i(ps);y=l(oe,"push_to_hub=True"),oe.forEach(a),Q=l(Ms," (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),is=p(Ms,"A",{href:!0});var te=i(is);ys=l(te,"Trainer"),te.forEach(a),hs=l(Ms," will evaluate the IoU metric and save the training checkpoint."),Ms.forEach(a),ds=d(Vs),j=p(Vs,"LI",{});var vs=i(j);H=l(vs,"Pass the training arguments to "),w=p(vs,"A",{href:!0});var Hs=i(w);es=l(Hs,"Trainer"),Hs.forEach(a),gs=l(vs," along with the model, dataset, tokenizer, data collator, and "),js=p(vs,"CODE",{});var Ds=i(js);Cs=l(Ds,"compute_metrics"),Ds.forEach(a),S=l(vs," function."),vs.forEach(a),Bs=d(Vs),bs=p(Vs,"LI",{});var Ks=i(bs);ks=l(Ks,"Call "),Is=p(Ks,"A",{href:!0});var le=i(Is);Us=l(le,"train()"),le.forEach(a),_s=l(Ks," to finetune your model."),Ks.forEach(a),Vs.forEach(a),Es=d(U),I(Js.$$.fragment,U),ws=d(U),Ts=p(U,"P",{});var m=i(Ts);Fs=l(m,"Once training is completed, share your model to the Hub with the "),As=p(m,"A",{href:!0});var D=i(As);ae=l(D,"push_to_hub()"),D.forEach(a),zs=l(m," method so everyone can use your model:"),m.forEach(a),Rs=d(U),I(Xs.$$.fragment,U),this.h()},h(){g(T,"href","/docs/transformers/main/en/model_doc/auto#transformers.AutoModelForSemanticSegmentation"),g(B,"href","/docs/transformers/main/en/main_classes/trainer#transformers.TrainingArguments"),g(is,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer"),g(w,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer"),g(Is,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer.train"),g(As,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer.push_to_hub")},m(U,ls){v(o,U,ls),c(U,f,ls),c(U,n,ls),s(n,M),s(n,T),s(T,J),s(n,A),c(U,X,ls),v(Y,U,ls),c(U,R,ls),c(U,F,ls),s(F,Z),c(U,W,ls),c(U,N,ls),s(N,_),s(_,os),s(_,B),s(B,L),s(_,b),s(_,V),s(V,x),s(_,P),s(_,O),s(O,as),s(_,ts),s(_,ns),s(ns,G),s(_,fs),s(_,ms),s(ms,us),s(_,K),s(_,rs),s(rs,ss),s(_,z),s(_,ps),s(ps,y),s(_,Q),s(_,is),s(is,ys),s(_,hs),s(N,ds),s(N,j),s(j,H),s(j,w),s(w,es),s(j,gs),s(j,js),s(js,Cs),s(j,S),s(N,Bs),s(N,bs),s(bs,ks),s(bs,Is),s(Is,Us),s(bs,_s),c(U,Es,ls),v(Js,U,ls),c(U,ws,ls),c(U,Ts,ls),s(Ts,Fs),s(Ts,As),s(As,ae),s(Ts,zs),c(U,Rs,ls),v(Xs,U,ls),Ys=!0},p(U,ls){const Gs={};ls&2&&(Gs.$$scope={dirty:ls,ctx:U}),o.$set(Gs)},i(U){Ys||(k(o.$$.fragment,U),k(Y.$$.fragment,U),k(Js.$$.fragment,U),k(Xs.$$.fragment,U),Ys=!0)},o(U){E(o.$$.fragment,U),E(Y.$$.fragment,U),E(Js.$$.fragment,U),E(Xs.$$.fragment,U),Ys=!1},d(U){C(o,U),U&&a(f),U&&a(n),U&&a(X),C(Y,U),U&&a(R),U&&a(F),U&&a(W),U&&a(N),U&&a(Es),C(Js,U),U&&a(ws),U&&a(Ts),U&&a(Rs),C(Xs,U)}}}function fn(q){let o,f;return o=new Xe({props:{$$slots:{default:[hn]},$$scope:{ctx:q}}}),{c(){$(o.$$.fragment)},l(n){I(o.$$.fragment,n)},m(n,M){v(o,n,M),f=!0},p(n,M){const T={};M&2&&(T.$$scope={dirty:M,ctx:n}),o.$set(T)},i(n){f||(k(o.$$.fragment,n),f=!0)},o(n){E(o.$$.fragment,n),f=!1},d(n){C(o,n)}}}function un(q){let o,f,n,M,T;return{c(){o=r("p"),f=t("If you are unfamiliar with fine-tuning a model with Keras, check out the "),n=r("a"),M=t("basic tutorial"),T=t(" first!"),this.h()},l(J){o=p(J,"P",{});var A=i(o);f=l(A,"If you are unfamiliar with fine-tuning a model with Keras, check out the "),n=p(A,"A",{href:!0});var X=i(n);M=l(X,"basic tutorial"),X.forEach(a),T=l(A," first!"),A.forEach(a),this.h()},h(){g(n,"href","./training#train-a-tensorflow-model-with-keras")},m(J,A){c(J,o,A),s(o,f),s(o,n),s(n,M),s(o,T)},d(J){J&&a(o)}}}function dn(q){let o,f,n,M,T,J,A,X,Y,R,F,Z,W,N,_,os,B,L,b,V,x,P,O,as,ts,ns,G,fs,ms,us,K,rs,ss,z,ps,y,Q,is,ys,hs,ds,j,H,w,es,gs,js,Cs,S,Bs,bs,ks,Is,Us,_s,Es,Js,ws,Ts,Fs,As,ae,zs,Rs,Xs,Ys,U,ls,Gs,Ss,Vs,Ms,Zs,Ls,$s,Qs,xs,ne,oe,te,vs,Hs,Ds,Ks,le;return o=new sl({props:{$$slots:{default:[un]},$$scope:{ctx:q}}}),z=new cs({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEElMEFiYXRjaF9zaXplJTIwJTNEJTIwMiUwQW51bV9lcG9jaHMlMjAlM0QlMjA1MCUwQW51bV90cmFpbl9zdGVwcyUyMCUzRCUyMGxlbih0cmFpbl9kcyklMjAqJTIwbnVtX2Vwb2NocyUwQWxlYXJuaW5nX3JhdGUlMjAlM0QlMjA2ZS01JTBBd2VpZ2h0X2RlY2F5X3JhdGUlMjAlM0QlMjAwLjAxJTBBJTBBb3B0aW1pemVyJTJDJTIwbHJfc2NoZWR1bGUlMjAlM0QlMjBjcmVhdGVfb3B0aW1pemVyKCUwQSUyMCUyMCUyMCUyMGluaXRfbHIlM0RsZWFybmluZ19yYXRlJTJDJTBBJTIwJTIwJTIwJTIwbnVtX3RyYWluX3N0ZXBzJTNEbnVtX3RyYWluX3N0ZXBzJTJDJTBBJTIwJTIwJTIwJTIwd2VpZ2h0X2RlY2F5X3JhdGUlM0R3ZWlnaHRfZGVjYXlfcmF0ZSUyQyUwQSUyMCUyMCUyMCUyMG51bV93YXJtdXBfc3RlcHMlM0QwJTJDJTBBKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer

<span class="hljs-meta">&gt;&gt;&gt; </span>batch_size = <span class="hljs-number">2</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_epochs = <span class="hljs-number">50</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_train_steps = <span class="hljs-built_in">len</span>(train_ds) * num_epochs
<span class="hljs-meta">&gt;&gt;&gt; </span>learning_rate = <span class="hljs-number">6e-5</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>weight_decay_rate = <span class="hljs-number">0.01</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer, lr_schedule = create_optimizer(
<span class="hljs-meta">... </span>    init_lr=learning_rate,
<span class="hljs-meta">... </span>    num_train_steps=num_train_steps,
<span class="hljs-meta">... </span>    weight_decay_rate=weight_decay_rate,
<span class="hljs-meta">... </span>    num_warmup_steps=<span class="hljs-number">0</span>,
<span class="hljs-meta">... </span>)`}}),j=new cs({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yU2VtYW50aWNTZWdtZW50YXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMFRGQXV0b01vZGVsRm9yU2VtYW50aWNTZWdtZW50YXRpb24uZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMGNoZWNrcG9pbnQlMkMlMEElMjAlMjAlMjAlMjBpZDJsYWJlbCUzRGlkMmxhYmVsJTJDJTBBJTIwJTIwJTIwJTIwbGFiZWwyaWQlM0RsYWJlbDJpZCUyQyUwQSklMEFtb2RlbC5jb21waWxlKG9wdGltaXplciUzRG9wdGltaXplciklMjAlMjAlMjMlMjBObyUyMGxvc3MlMjBhcmd1bWVudCE=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSemanticSegmentation

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForSemanticSegmentation.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>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.<span class="hljs-built_in">compile</span>(optimizer=optimizer)  <span class="hljs-comment"># No loss argument!</span>`}}),Es=new cs({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERlZmF1bHREYXRhQ29sbGF0b3IlMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGVmYXVsdERhdGFDb2xsYXRvcihyZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyKSUwQSUwQXRmX3RyYWluX2RhdGFzZXQlMjAlM0QlMjB0cmFpbl9kcy50b190Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMGNvbHVtbnMlM0QlNUIlMjJwaXhlbF92YWx1ZXMlMjIlMkMlMjAlMjJsYWJlbCUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMHNodWZmbGUlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRGJhdGNoX3NpemUlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSklMEElMEF0Zl9ldmFsX2RhdGFzZXQlMjAlM0QlMjB0ZXN0X2RzLnRvX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwY29sdW1ucyUzRCU1QiUyMnBpeGVsX3ZhbHVlcyUyMiUyQyUyMCUyMmxhYmVsJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEYmF0Y2hfc2l6ZSUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DefaultDataCollator

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DefaultDataCollator(return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>tf_train_dataset = train_ds.to_tf_dataset(
<span class="hljs-meta">... </span>    columns=[<span class="hljs-string">&quot;pixel_values&quot;</span>, <span class="hljs-string">&quot;label&quot;</span>],
<span class="hljs-meta">... </span>    shuffle=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    batch_size=batch_size,
<span class="hljs-meta">... </span>    collate_fn=data_collator,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>tf_eval_dataset = test_ds.to_tf_dataset(
<span class="hljs-meta">... </span>    columns=[<span class="hljs-string">&quot;pixel_values&quot;</span>, <span class="hljs-string">&quot;label&quot;</span>],
<span class="hljs-meta">... </span>    shuffle=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    batch_size=batch_size,
<span class="hljs-meta">... </span>    collate_fn=data_collator,
<span class="hljs-meta">... </span>)`}}),Zs=new cs({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5rZXJhc19jYWxsYmFja3MlMjBpbXBvcnQlMjBLZXJhc01ldHJpY0NhbGxiYWNrJTJDJTIwUHVzaFRvSHViQ2FsbGJhY2slMEElMEFtZXRyaWNfY2FsbGJhY2slMjAlM0QlMjBLZXJhc01ldHJpY0NhbGxiYWNrKCUwQSUyMCUyMCUyMCUyMG1ldHJpY19mbiUzRGNvbXB1dGVfbWV0cmljcyUyQyUyMGV2YWxfZGF0YXNldCUzRHRmX2V2YWxfZGF0YXNldCUyQyUyMGJhdGNoX3NpemUlM0RiYXRjaF9zaXplJTJDJTIwbGFiZWxfY29scyUzRCU1QiUyMmxhYmVscyUyMiU1RCUwQSklMEElMEFwdXNoX3RvX2h1Yl9jYWxsYmFjayUyMCUzRCUyMFB1c2hUb0h1YkNhbGxiYWNrKG91dHB1dF9kaXIlM0QlMjJzY2VuZV9zZWdtZW50YXRpb24lMjIlMkMlMjB0b2tlbml6ZXIlM0RpbWFnZV9wcm9jZXNzb3IpJTBBJTBBY2FsbGJhY2tzJTIwJTNEJTIwJTVCbWV0cmljX2NhbGxiYWNrJTJDJTIwcHVzaF90b19odWJfY2FsbGJhY2slNUQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> KerasMetricCallback, PushToHubCallback

<span class="hljs-meta">&gt;&gt;&gt; </span>metric_callback = KerasMetricCallback(
<span class="hljs-meta">... </span>    metric_fn=compute_metrics, eval_dataset=tf_eval_dataset, batch_size=batch_size, label_cols=[<span class="hljs-string">&quot;labels&quot;</span>]
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>push_to_hub_callback = PushToHubCallback(output_dir=<span class="hljs-string">&quot;scene_segmentation&quot;</span>, tokenizer=image_processor)

<span class="hljs-meta">&gt;&gt;&gt; </span>callbacks = [metric_callback, push_to_hub_callback]`}}),vs=new cs({props:{code:"bW9kZWwuZml0KCUwQSUyMCUyMCUyMCUyMHRmX3RyYWluX2RhdGFzZXQlMkMlMEElMjAlMjAlMjAlMjB2YWxpZGF0aW9uX2RhdGElM0R0Zl9ldmFsX2RhdGFzZXQlMkMlMEElMjAlMjAlMjAlMjBjYWxsYmFja3MlM0RjYWxsYmFja3MlMkMlMEElMjAlMjAlMjAlMjBlcG9jaHMlM0RudW1fZXBvY2hzJTJDJTBBKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>model.fit(
<span class="hljs-meta">... </span>    tf_train_dataset,
<span class="hljs-meta">... </span>    validation_data=tf_eval_dataset,
<span class="hljs-meta">... </span>    callbacks=callbacks,
<span class="hljs-meta">... </span>    epochs=num_epochs,
<span class="hljs-meta">... </span>)`}}),{c(){$(o.$$.fragment),f=u(),n=r("p"),M=t("To fine-tune a model in TensorFlow, follow these steps:"),T=u(),J=r("ol"),A=r("li"),X=t("Define the training hyperparameters, and set up an optimizer and a learning rate schedule."),Y=u(),R=r("li"),F=t("Instantiate a pretrained model."),Z=u(),W=r("li"),N=t("Convert a \u{1F917} Dataset to a "),_=r("code"),os=t("tf.data.Dataset"),B=t("."),L=u(),b=r("li"),V=t("Compile your model."),x=u(),P=r("li"),O=t("Add callbacks to calculate metrics and upload your model to \u{1F917} Hub"),as=u(),ts=r("li"),ns=t("Use the "),G=r("code"),fs=t("fit()"),ms=t(" method to run the training."),us=u(),K=r("p"),rs=t("Start by defining the hyperparameters, optimizer and learning rate schedule:"),ss=u(),$(z.$$.fragment),ps=u(),y=r("p"),Q=t("Then, load SegFormer with "),is=r("a"),ys=t("TFAutoModelForSemanticSegmentation"),hs=t(` along with the label mappings, and compile it with the
optimizer. Note that Transformers models all have a default task-relevant loss function, so you don\u2019t need to specify one unless you want to:`),ds=u(),$(j.$$.fragment),H=u(),w=r("p"),es=t("Convert your datasets to the "),gs=r("code"),js=t("tf.data.Dataset"),Cs=t(" format using the "),S=r("a"),Bs=t("to_tf_dataset"),bs=t(" and the "),ks=r("a"),Is=t("DefaultDataCollator"),Us=t(":"),_s=u(),$(Es.$$.fragment),Js=u(),ws=r("p"),Ts=t("To compute the accuracy from the predictions and push your model to the \u{1F917} Hub, use "),Fs=r("a"),As=t("Keras callbacks"),ae=t(`.
Pass your `),zs=r("code"),Rs=t("compute_metrics"),Xs=t(" function to "),Ys=r("a"),U=t("KerasMetricCallback"),ls=t(`,
and use the `),Gs=r("a"),Ss=t("PushToHubCallback"),Vs=t(" to upload the model:"),Ms=u(),$(Zs.$$.fragment),Ls=u(),$s=r("p"),Qs=t("Finally, you are ready to train your model! Call "),xs=r("code"),ne=t("fit()"),oe=t(` with your training and validation datasets, the number of epochs,
and your callbacks to fine-tune the model:`),te=u(),$(vs.$$.fragment),Hs=u(),Ds=r("p"),Ks=t("Congratulations! You have fine-tuned your model and shared it on the \u{1F917} Hub. You can now use it for inference!"),this.h()},l(m){I(o.$$.fragment,m),f=d(m),n=p(m,"P",{});var D=i(n);M=l(D,"To fine-tune a model in TensorFlow, follow these steps:"),D.forEach(a),T=d(m),J=p(m,"OL",{});var Ws=i(J);A=p(Ws,"LI",{});var oa=i(A);X=l(oa,"Define the training hyperparameters, and set up an optimizer and a learning rate schedule."),oa.forEach(a),Y=d(Ws),R=p(Ws,"LI",{});var Me=i(R);F=l(Me,"Instantiate a pretrained model."),Me.forEach(a),Z=d(Ws),W=p(Ws,"LI",{});var ye=i(W);N=l(ye,"Convert a \u{1F917} Dataset to a "),_=p(ye,"CODE",{});var ra=i(_);os=l(ra,"tf.data.Dataset"),ra.forEach(a),B=l(ye,"."),ye.forEach(a),L=d(Ws),b=p(Ws,"LI",{});var ge=i(b);V=l(ge,"Compile your model."),ge.forEach(a),x=d(Ws),P=p(Ws,"LI",{});var pa=i(P);O=l(pa,"Add callbacks to calculate metrics and upload your model to \u{1F917} Hub"),pa.forEach(a),as=d(Ws),ts=p(Ws,"LI",{});var je=i(ts);ns=l(je,"Use the "),G=p(je,"CODE",{});var Ye=i(G);fs=l(Ye,"fit()"),Ye.forEach(a),ms=l(je," method to run the training."),je.forEach(a),Ws.forEach(a),us=d(m),K=p(m,"P",{});var Ps=i(K);rs=l(Ps,"Start by defining the hyperparameters, optimizer and learning rate schedule:"),Ps.forEach(a),ss=d(m),I(z.$$.fragment,m),ps=d(m),y=p(m,"P",{});var we=i(y);Q=l(we,"Then, load SegFormer with "),is=p(we,"A",{href:!0});var be=i(is);ys=l(be,"TFAutoModelForSemanticSegmentation"),be.forEach(a),hs=l(we,` along with the label mappings, and compile it with the
optimizer. Note that Transformers models all have a default task-relevant loss function, so you don\u2019t need to specify one unless you want to:`),we.forEach(a),ds=d(m),I(j.$$.fragment,m),H=d(m),w=p(m,"P",{});var Os=i(w);es=l(Os,"Convert your datasets to the "),gs=p(Os,"CODE",{});var ia=i(gs);js=l(ia,"tf.data.Dataset"),ia.forEach(a),Cs=l(Os," format using the "),S=p(Os,"A",{href:!0,rel:!0});var Je=i(S);Bs=l(Je,"to_tf_dataset"),Je.forEach(a),bs=l(Os," and the "),ks=p(Os,"A",{href:!0});var ca=i(ks);Is=l(ca,"DefaultDataCollator"),ca.forEach(a),Us=l(Os,":"),Os.forEach(a),_s=d(m),I(Es.$$.fragment,m),Js=d(m),ws=p(m,"P",{});var Ns=i(ws);Ts=l(Ns,"To compute the accuracy from the predictions and push your model to the \u{1F917} Hub, use "),Fs=p(Ns,"A",{href:!0});var Fe=i(Fs);As=l(Fe,"Keras callbacks"),Fe.forEach(a),ae=l(Ns,`.
Pass your `),zs=p(Ns,"CODE",{});var re=i(zs);Rs=l(re,"compute_metrics"),re.forEach(a),Xs=l(Ns," function to "),Ys=p(Ns,"A",{href:!0});var Ve=i(Ys);U=l(Ve,"KerasMetricCallback"),Ve.forEach(a),ls=l(Ns,`,
and use the `),Gs=p(Ns,"A",{href:!0});var se=i(Gs);Ss=l(se,"PushToHubCallback"),se.forEach(a),Vs=l(Ns," to upload the model:"),Ns.forEach(a),Ms=d(m),I(Zs.$$.fragment,m),Ls=d(m),$s=p(m,"P",{});var qs=i($s);Qs=l(qs,"Finally, you are ready to train your model! Call "),xs=p(qs,"CODE",{});var Te=i(xs);ne=l(Te,"fit()"),Te.forEach(a),oe=l(qs,` with your training and validation datasets, the number of epochs,
and your callbacks to fine-tune the model:`),qs.forEach(a),te=d(m),I(vs.$$.fragment,m),Hs=d(m),Ds=p(m,"P",{});var pe=i(Ds);Ks=l(pe,"Congratulations! You have fine-tuned your model and shared it on the \u{1F917} Hub. You can now use it for inference!"),pe.forEach(a),this.h()},h(){g(is,"href","/docs/transformers/main/en/model_doc/auto#transformers.TFAutoModelForSemanticSegmentation"),g(S,"href","https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.to_tf_dataset"),g(S,"rel","nofollow"),g(ks,"href","/docs/transformers/main/en/main_classes/data_collator#transformers.DefaultDataCollator"),g(Fs,"href","../main_classes/keras_callbacks"),g(Ys,"href","/docs/transformers/main/en/main_classes/keras_callbacks#transformers.KerasMetricCallback"),g(Gs,"href","/docs/transformers/main/en/main_classes/keras_callbacks#transformers.PushToHubCallback")},m(m,D){v(o,m,D),c(m,f,D),c(m,n,D),s(n,M),c(m,T,D),c(m,J,D),s(J,A),s(A,X),s(J,Y),s(J,R),s(R,F),s(J,Z),s(J,W),s(W,N),s(W,_),s(_,os),s(W,B),s(J,L),s(J,b),s(b,V),s(J,x),s(J,P),s(P,O),s(J,as),s(J,ts),s(ts,ns),s(ts,G),s(G,fs),s(ts,ms),c(m,us,D),c(m,K,D),s(K,rs),c(m,ss,D),v(z,m,D),c(m,ps,D),c(m,y,D),s(y,Q),s(y,is),s(is,ys),s(y,hs),c(m,ds,D),v(j,m,D),c(m,H,D),c(m,w,D),s(w,es),s(w,gs),s(gs,js),s(w,Cs),s(w,S),s(S,Bs),s(w,bs),s(w,ks),s(ks,Is),s(w,Us),c(m,_s,D),v(Es,m,D),c(m,Js,D),c(m,ws,D),s(ws,Ts),s(ws,Fs),s(Fs,As),s(ws,ae),s(ws,zs),s(zs,Rs),s(ws,Xs),s(ws,Ys),s(Ys,U),s(ws,ls),s(ws,Gs),s(Gs,Ss),s(ws,Vs),c(m,Ms,D),v(Zs,m,D),c(m,Ls,D),c(m,$s,D),s($s,Qs),s($s,xs),s(xs,ne),s($s,oe),c(m,te,D),v(vs,m,D),c(m,Hs,D),c(m,Ds,D),s(Ds,Ks),le=!0},p(m,D){const Ws={};D&2&&(Ws.$$scope={dirty:D,ctx:m}),o.$set(Ws)},i(m){le||(k(o.$$.fragment,m),k(z.$$.fragment,m),k(j.$$.fragment,m),k(Es.$$.fragment,m),k(Zs.$$.fragment,m),k(vs.$$.fragment,m),le=!0)},o(m){E(o.$$.fragment,m),E(z.$$.fragment,m),E(j.$$.fragment,m),E(Es.$$.fragment,m),E(Zs.$$.fragment,m),E(vs.$$.fragment,m),le=!1},d(m){C(o,m),m&&a(f),m&&a(n),m&&a(T),m&&a(J),m&&a(us),m&&a(K),m&&a(ss),C(z,m),m&&a(ps),m&&a(y),m&&a(ds),C(j,m),m&&a(H),m&&a(w),m&&a(_s),C(Es,m),m&&a(Js),m&&a(ws),m&&a(Ms),C(Zs,m),m&&a(Ls),m&&a($s),m&&a(te),C(vs,m),m&&a(Hs),m&&a(Ds)}}}function Mn(q){let o,f;return o=new Xe({props:{$$slots:{default:[dn]},$$scope:{ctx:q}}}),{c(){$(o.$$.fragment)},l(n){I(o.$$.fragment,n)},m(n,M){v(o,n,M),f=!0},p(n,M){const T={};M&2&&(T.$$scope={dirty:M,ctx:n}),o.$set(T)},i(n){f||(k(o.$$.fragment,n),f=!0)},o(n){E(o.$$.fragment,n),f=!1},d(n){C(o,n)}}}function yn(q){let o,f,n,M,T,J,A,X,Y,R,F,Z,W,N,_,os,B,L,b,V,x,P,O,as,ts,ns,G,fs,ms,us,K,rs,ss,z,ps;return R=new cs({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBc2VnbWVudGVyJTIwJTNEJTIwcGlwZWxpbmUoJTIyaW1hZ2Utc2VnbWVudGF0aW9uJTIyJTJDJTIwbW9kZWwlM0QlMjJteV9hd2Vzb21lX3NlZ19tb2RlbCUyMiklMEFzZWdtZW50ZXIoaW1hZ2Up",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>segmenter = pipeline(<span class="hljs-string">&quot;image-segmentation&quot;</span>, model=<span class="hljs-string">&quot;my_awesome_seg_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>segmenter(image)
[{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-literal">None</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;wall&#x27;</span>,
  <span class="hljs-string">&#x27;mask&#x27;</span>: &lt;PIL.Image.Image image mode=L size=640x427 at <span class="hljs-number">0x7FD5B2062690</span>&gt;},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-literal">None</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;sky&#x27;</span>,
  <span class="hljs-string">&#x27;mask&#x27;</span>: &lt;PIL.Image.Image image mode=L size=640x427 at <span class="hljs-number">0x7FD5B2062A50</span>&gt;},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-literal">None</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;floor&#x27;</span>,
  <span class="hljs-string">&#x27;mask&#x27;</span>: &lt;PIL.Image.Image image mode=L size=640x427 at <span class="hljs-number">0x7FD5B2062B50</span>&gt;},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-literal">None</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;ceiling&#x27;</span>,
  <span class="hljs-string">&#x27;mask&#x27;</span>: &lt;PIL.Image.Image image mode=L size=640x427 at <span class="hljs-number">0x7FD5B2062A10</span>&gt;},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-literal">None</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;bed &#x27;</span>,
  <span class="hljs-string">&#x27;mask&#x27;</span>: &lt;PIL.Image.Image image mode=L size=640x427 at <span class="hljs-number">0x7FD5B2062E90</span>&gt;},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-literal">None</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;windowpane&#x27;</span>,
  <span class="hljs-string">&#x27;mask&#x27;</span>: &lt;PIL.Image.Image image mode=L size=640x427 at <span class="hljs-number">0x7FD5B2062390</span>&gt;},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-literal">None</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;cabinet&#x27;</span>,
  <span class="hljs-string">&#x27;mask&#x27;</span>: &lt;PIL.Image.Image image mode=L size=640x427 at <span class="hljs-number">0x7FD5B2062550</span>&gt;},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-literal">None</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;chair&#x27;</span>,
  <span class="hljs-string">&#x27;mask&#x27;</span>: &lt;PIL.Image.Image image mode=L size=640x427 at <span class="hljs-number">0x7FD5B2062D90</span>&gt;},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-literal">None</span>,
  <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;armchair&#x27;</span>,
  <span class="hljs-string">&#x27;mask&#x27;</span>: &lt;PIL.Image.Image image mode=L size=640x427 at <span class="hljs-number">0x7FD5B2062E10</span>&gt;}]`}}),x=new cs({props:{code:"ZGV2aWNlJTIwJTNEJTIwdG9yY2guZGV2aWNlKCUyMmN1ZGElMjIlMjBpZiUyMHRvcmNoLmN1ZGEuaXNfYXZhaWxhYmxlKCklMjBlbHNlJTIwJTIyY3B1JTIyKSUyMCUyMCUyMyUyMHVzZSUyMEdQVSUyMGlmJTIwYXZhaWxhYmxlJTJDJTIwb3RoZXJ3aXNlJTIwdXNlJTIwYSUyMENQVSUwQWVuY29kaW5nJTIwJTNEJTIwaW1hZ2VfcHJvY2Vzc29yKGltYWdlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEFwaXhlbF92YWx1ZXMlMjAlM0QlMjBlbmNvZGluZy5waXhlbF92YWx1ZXMudG8oZGV2aWNlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cpu&quot;</span>)  <span class="hljs-comment"># use GPU if available, otherwise use a CPU</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>encoding = image_processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>pixel_values = encoding.pixel_values.to(device)`}}),ms=new cs({props:{code:"b3V0cHV0cyUyMCUzRCUyMG1vZGVsKHBpeGVsX3ZhbHVlcyUzRHBpeGVsX3ZhbHVlcyklMEFsb2dpdHMlMjAlM0QlMjBvdXRwdXRzLmxvZ2l0cy5jcHUoKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(pixel_values=pixel_values)
<span class="hljs-meta">&gt;&gt;&gt; </span>logits = outputs.logits.cpu()`}}),z=new cs({props:{code:"dXBzYW1wbGVkX2xvZ2l0cyUyMCUzRCUyMG5uLmZ1bmN0aW9uYWwuaW50ZXJwb2xhdGUoJTBBJTIwJTIwJTIwJTIwbG9naXRzJTJDJTBBJTIwJTIwJTIwJTIwc2l6ZSUzRGltYWdlLnNpemUlNUIlM0ElM0EtMSU1RCUyQyUwQSUyMCUyMCUyMCUyMG1vZGUlM0QlMjJiaWxpbmVhciUyMiUyQyUwQSUyMCUyMCUyMCUyMGFsaWduX2Nvcm5lcnMlM0RGYWxzZSUyQyUwQSklMEElMEFwcmVkX3NlZyUyMCUzRCUyMHVwc2FtcGxlZF9sb2dpdHMuYXJnbWF4KGRpbSUzRDEpJTVCMCU1RA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>upsampled_logits = nn.functional.interpolate(
<span class="hljs-meta">... </span>    logits,
<span class="hljs-meta">... </span>    size=image.size[::-<span class="hljs-number">1</span>],
<span class="hljs-meta">... </span>    mode=<span class="hljs-string">&quot;bilinear&quot;</span>,
<span class="hljs-meta">... </span>    align_corners=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>pred_seg = upsampled_logits.argmax(dim=<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>]`}}),{c(){o=r("p"),f=t("The simplest way to try out your finetuned model for inference is to use it in a "),n=r("a"),M=t("pipeline()"),T=t(". Instantiate a "),J=r("code"),A=t("pipeline"),X=t(" for image segmentation with your model, and pass your image to it:"),Y=u(),$(R.$$.fragment),F=u(),Z=r("p"),W=t("You can also manually replicate the results of the "),N=r("code"),_=t("pipeline"),os=t(" if you\u2019d like. Process the image with an image processor and place the "),B=r("code"),L=t("pixel_values"),b=t(" on a GPU:"),V=u(),$(x.$$.fragment),P=u(),O=r("p"),as=t("Pass your input to the model and return the "),ts=r("code"),ns=t("logits"),G=t(":"),fs=u(),$(ms.$$.fragment),us=u(),K=r("p"),rs=t("Next, rescale the logits to the original image size:"),ss=u(),$(z.$$.fragment),this.h()},l(y){o=p(y,"P",{});var Q=i(o);f=l(Q,"The simplest way to try out your finetuned model for inference is to use it in a "),n=p(Q,"A",{href:!0});var is=i(n);M=l(is,"pipeline()"),is.forEach(a),T=l(Q,". Instantiate a "),J=p(Q,"CODE",{});var ys=i(J);A=l(ys,"pipeline"),ys.forEach(a),X=l(Q," for image segmentation with your model, and pass your image to it:"),Q.forEach(a),Y=d(y),I(R.$$.fragment,y),F=d(y),Z=p(y,"P",{});var hs=i(Z);W=l(hs,"You can also manually replicate the results of the "),N=p(hs,"CODE",{});var ds=i(N);_=l(ds,"pipeline"),ds.forEach(a),os=l(hs," if you\u2019d like. Process the image with an image processor and place the "),B=p(hs,"CODE",{});var j=i(B);L=l(j,"pixel_values"),j.forEach(a),b=l(hs," on a GPU:"),hs.forEach(a),V=d(y),I(x.$$.fragment,y),P=d(y),O=p(y,"P",{});var H=i(O);as=l(H,"Pass your input to the model and return the "),ts=p(H,"CODE",{});var w=i(ts);ns=l(w,"logits"),w.forEach(a),G=l(H,":"),H.forEach(a),fs=d(y),I(ms.$$.fragment,y),us=d(y),K=p(y,"P",{});var es=i(K);rs=l(es,"Next, rescale the logits to the original image size:"),es.forEach(a),ss=d(y),I(z.$$.fragment,y),this.h()},h(){g(n,"href","/docs/transformers/main/en/main_classes/pipelines#transformers.pipeline")},m(y,Q){c(y,o,Q),s(o,f),s(o,n),s(n,M),s(o,T),s(o,J),s(J,A),s(o,X),c(y,Y,Q),v(R,y,Q),c(y,F,Q),c(y,Z,Q),s(Z,W),s(Z,N),s(N,_),s(Z,os),s(Z,B),s(B,L),s(Z,b),c(y,V,Q),v(x,y,Q),c(y,P,Q),c(y,O,Q),s(O,as),s(O,ts),s(ts,ns),s(O,G),c(y,fs,Q),v(ms,y,Q),c(y,us,Q),c(y,K,Q),s(K,rs),c(y,ss,Q),v(z,y,Q),ps=!0},p:Ja,i(y){ps||(k(R.$$.fragment,y),k(x.$$.fragment,y),k(ms.$$.fragment,y),k(z.$$.fragment,y),ps=!0)},o(y){E(R.$$.fragment,y),E(x.$$.fragment,y),E(ms.$$.fragment,y),E(z.$$.fragment,y),ps=!1},d(y){y&&a(o),y&&a(Y),C(R,y),y&&a(F),y&&a(Z),y&&a(V),C(x,y),y&&a(P),y&&a(O),y&&a(fs),C(ms,y),y&&a(us),y&&a(K),y&&a(ss),C(z,y)}}}function gn(q){let o,f;return o=new Xe({props:{$$slots:{default:[yn]},$$scope:{ctx:q}}}),{c(){$(o.$$.fragment)},l(n){I(o.$$.fragment,n)},m(n,M){v(o,n,M),f=!0},p(n,M){const T={};M&2&&(T.$$scope={dirty:M,ctx:n}),o.$set(T)},i(n){f||(k(o.$$.fragment,n),f=!0)},o(n){E(o.$$.fragment,n),f=!1},d(n){C(o,n)}}}function jn(q){let o,f,n,M,T,J,A,X,Y,R,F,Z,W,N,_,os,B,L;return M=new cs({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUwQSUwQWltYWdlX3Byb2Nlc3NvciUyMCUzRCUyMEF1dG9JbWFnZVByb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoJTIyTWFyaWFLJTJGc2NlbmVfc2VnbWVudGF0aW9uJTIyKSUwQWlucHV0cyUyMCUzRCUyMGltYWdlX3Byb2Nlc3NvcihpbWFnZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIydGYlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor

<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;MariaK/scene_segmentation&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = image_processor(image, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`}}),Z=new cs({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yU2VtYW50aWNTZWdtZW50YXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMFRGQXV0b01vZGVsRm9yU2VtYW50aWNTZWdtZW50YXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMk1hcmlhSyUyRnNjZW5lX3NlZ21lbnRhdGlvbiUyMiklMEFsb2dpdHMlMjAlM0QlMjBtb2RlbCgqKmlucHV0cykubG9naXRz",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSemanticSegmentation

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForSemanticSegmentation.from_pretrained(<span class="hljs-string">&quot;MariaK/scene_segmentation&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>logits = model(**inputs).logits`}}),B=new cs({props:{code:"bG9naXRzJTIwJTNEJTIwdGYudHJhbnNwb3NlKGxvZ2l0cyUyQyUyMCU1QjAlMkMlMjAyJTJDJTIwMyUyQyUyMDElNUQpJTBBJTBBdXBzYW1wbGVkX2xvZ2l0cyUyMCUzRCUyMHRmLmltYWdlLnJlc2l6ZSglMEElMjAlMjAlMjAlMjBsb2dpdHMlMkMlMEElMjAlMjAlMjAlMjAlMjMlMjBXZSUyMHJldmVyc2UlMjB0aGUlMjBzaGFwZSUyMG9mJTIwJTYwaW1hZ2UlNjAlMjBiZWNhdXNlJTIwJTYwaW1hZ2Uuc2l6ZSU2MCUyMHJldHVybnMlMjB3aWR0aCUyMGFuZCUyMGhlaWdodC4lMEElMjAlMjAlMjAlMjBpbWFnZS5zaXplJTVCJTNBJTNBLTElNUQlMkMlMEEpJTBBJTBBcHJlZF9zZWclMjAlM0QlMjB0Zi5tYXRoLmFyZ21heCh1cHNhbXBsZWRfbG9naXRzJTJDJTIwYXhpcyUzRC0xKSU1QjAlNUQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>logits = tf.transpose(logits, [<span class="hljs-number">0</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">1</span>])

<span class="hljs-meta">&gt;&gt;&gt; </span>upsampled_logits = tf.image.resize(
<span class="hljs-meta">... </span>    logits,
<span class="hljs-meta">... </span>    <span class="hljs-comment"># We reverse the shape of \`image\` because \`image.size\` returns width and height.</span>
<span class="hljs-meta">... </span>    image.size[::-<span class="hljs-number">1</span>],
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>pred_seg = tf.math.argmax(upsampled_logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>]`}}),{c(){o=r("p"),f=t("Load an image processor to preprocess the image and return the input as TensorFlow tensors:"),n=u(),$(M.$$.fragment),T=u(),J=r("p"),A=t("Pass your input to the model and return the "),X=r("code"),Y=t("logits"),R=t(":"),F=u(),$(Z.$$.fragment),W=u(),N=r("p"),_=t("Next, rescale the logits to the original image size and apply argmax on the class dimension:"),os=u(),$(B.$$.fragment)},l(b){o=p(b,"P",{});var V=i(o);f=l(V,"Load an image processor to preprocess the image and return the input as TensorFlow tensors:"),V.forEach(a),n=d(b),I(M.$$.fragment,b),T=d(b),J=p(b,"P",{});var x=i(J);A=l(x,"Pass your input to the model and return the "),X=p(x,"CODE",{});var P=i(X);Y=l(P,"logits"),P.forEach(a),R=l(x,":"),x.forEach(a),F=d(b),I(Z.$$.fragment,b),W=d(b),N=p(b,"P",{});var O=i(N);_=l(O,"Next, rescale the logits to the original image size and apply argmax on the class dimension:"),O.forEach(a),os=d(b),I(B.$$.fragment,b)},m(b,V){c(b,o,V),s(o,f),c(b,n,V),v(M,b,V),c(b,T,V),c(b,J,V),s(J,A),s(J,X),s(X,Y),s(J,R),c(b,F,V),v(Z,b,V),c(b,W,V),c(b,N,V),s(N,_),c(b,os,V),v(B,b,V),L=!0},p:Ja,i(b){L||(k(M.$$.fragment,b),k(Z.$$.fragment,b),k(B.$$.fragment,b),L=!0)},o(b){E(M.$$.fragment,b),E(Z.$$.fragment,b),E(B.$$.fragment,b),L=!1},d(b){b&&a(o),b&&a(n),C(M,b),b&&a(T),b&&a(J),b&&a(F),C(Z,b),b&&a(W),b&&a(N),b&&a(os),C(B,b)}}}function wn(q){let o,f;return o=new Xe({props:{$$slots:{default:[jn]},$$scope:{ctx:q}}}),{c(){$(o.$$.fragment)},l(n){I(o.$$.fragment,n)},m(n,M){v(o,n,M),f=!0},p(n,M){const T={};M&2&&(T.$$scope={dirty:M,ctx:n}),o.$set(T)},i(n){f||(k(o.$$.fragment,n),f=!0)},o(n){E(o.$$.fragment,n),f=!1},d(n){C(o,n)}}}function bn(q){let o,f,n,M,T,J,A,X,Y,R,F,Z,W,N,_,os,B,L,b,V,x,P,O,as,ts,ns,G,fs,ms,us,K,rs,ss,z,ps,y,Q,is,ys,hs,ds,j,H,w,es,gs,js,Cs,S,Bs,bs,ks,Is,Us,_s,Es,Js,ws,Ts,Fs,As,ae,zs,Rs,Xs,Ys,U,ls,Gs,Ss,Vs,Ms,Zs,Ls,$s,Qs,xs,ne,oe,te,vs,Hs,Ds,Ks,le,m,D,Ws,oa,Me,ye,ra,ge,pa,je,Ye,Ps,we,be,Os,ia,Je,ca,Ns,Fe,re,Ve,se,qs,Te,pe,yt,Ta,gt,Fa,ie,jt,Ua,wt,bt,_a,Jt,Tt,Va,xe,xa,Ue,Na,_e,za,he,$e,$a,Ne,Ut,Ia,_t,Sa,ee,$t,ze,It,vt,Se,kt,Et,Qe,Ct,Wt,Qa,He,Ha,ce,Zt,De,Bt,Gt,Pe,At,Rt,Da,Ie,Pa,ve,qa,ke,Xt,va,Yt,Ft,La,fe,Ee,ka,qe,Vt,Ea,xt,Ka,Ce,Oa,We,st,ue,Ze,Ca,Le,Nt,Wa,zt,et,ma,St,at,ha,Qt,tt,Ke,lt,Oe,fa,el,nt,Be,ot,Ge,rt,me,Ht,sa,Dt,Pt,Za,qt,Lt,pt,ea,it,aa,ua,al,ct;return J=new ba({}),F=new sn({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/semantic_segmentation.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/semantic_segmentation.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/semantic_segmentation.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/semantic_segmentation.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/semantic_segmentation.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/semantic_segmentation.ipynb"}]}}),W=new Ol({props:{id:"dKE8SIt9C-w"}}),z=new sl({props:{$$slots:{default:[en]},$$scope:{ctx:q}}}),ys=new cs({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1xJTIwZGF0YXNldHMlMjB0cmFuc2Zvcm1lcnMlMjBldmFsdWF0ZQ==",highlighted:"pip install -q datasets transformers evaluate"}}),w=new cs({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()`}}),S=new ba({}),Js=new cs({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBZHMlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIyc2NlbmVfcGFyc2VfMTUwJTIyJTJDJTIwc3BsaXQlM0QlMjJ0cmFpbiU1QiUzQTUwJTVEJTIyKQ==",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>ds = load_dataset(<span class="hljs-string">&quot;scene_parse_150&quot;</span>, split=<span class="hljs-string">&quot;train[:50]&quot;</span>)`}}),ls=new cs({props:{code:"ZHMlMjAlM0QlMjBkcy50cmFpbl90ZXN0X3NwbGl0KHRlc3Rfc2l6ZSUzRDAuMiklMEF0cmFpbl9kcyUyMCUzRCUyMGRzJTVCJTIydHJhaW4lMjIlNUQlMEF0ZXN0X2RzJTIwJTNEJTIwZHMlNUIlMjJ0ZXN0JTIyJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>ds = ds.train_test_split(test_size=<span class="hljs-number">0.2</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>train_ds = ds[<span class="hljs-string">&quot;train&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>test_ds = ds[<span class="hljs-string">&quot;test&quot;</span>]`}}),Zs=new cs({props:{code:"dHJhaW5fZHMlNUIwJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>train_ds[<span class="hljs-number">0</span>]
{<span class="hljs-string">&#x27;image&#x27;</span>: &lt;PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=512x683 at <span class="hljs-number">0x7F9B0C201F90</span>&gt;,
 <span class="hljs-string">&#x27;annotation&#x27;</span>: &lt;PIL.PngImagePlugin.PngImageFile image mode=L size=512x683 at <span class="hljs-number">0x7F9B0C201DD0</span>&gt;,
 <span class="hljs-string">&#x27;scene_category&#x27;</span>: <span class="hljs-number">368</span>}`}}),re=new cs({props:{code:"aW1wb3J0JTIwanNvbiUwQWZyb20lMjBodWdnaW5nZmFjZV9odWIlMjBpbXBvcnQlMjBjYWNoZWRfZG93bmxvYWQlMkMlMjBoZl9odWJfdXJsJTBBJTBBcmVwb19pZCUyMCUzRCUyMCUyMmh1Z2dpbmdmYWNlJTJGbGFiZWwtZmlsZXMlMjIlMEFmaWxlbmFtZSUyMCUzRCUyMCUyMmFkZTIway1pZDJsYWJlbC5qc29uJTIyJTBBaWQybGFiZWwlMjAlM0QlMjBqc29uLmxvYWQob3BlbihjYWNoZWRfZG93bmxvYWQoaGZfaHViX3VybChyZXBvX2lkJTJDJTIwZmlsZW5hbWUlMkMlMjByZXBvX3R5cGUlM0QlMjJkYXRhc2V0JTIyKSklMkMlMjAlMjJyJTIyKSklMEFpZDJsYWJlbCUyMCUzRCUyMCU3QmludChrKSUzQSUyMHYlMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwaWQybGFiZWwuaXRlbXMoKSU3RCUwQWxhYmVsMmlkJTIwJTNEJTIwJTdCdiUzQSUyMGslMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwaWQybGFiZWwuaXRlbXMoKSU3RCUwQW51bV9sYWJlbHMlMjAlM0QlMjBsZW4oaWQybGFiZWwp",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-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> cached_download, hf_hub_url

<span class="hljs-meta">&gt;&gt;&gt; </span>repo_id = <span class="hljs-string">&quot;huggingface/label-files&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>filename = <span class="hljs-string">&quot;ade20k-hf-doc-builder.json&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>id2label = json.load(<span class="hljs-built_in">open</span>(cached_download(hf_hub_url(repo_id, filename, repo_type=<span class="hljs-string">&quot;dataset&quot;</span>)), <span class="hljs-string">&quot;r&quot;</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>id2label = {<span class="hljs-built_in">int</span>(k): v <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> id2label.items()}
<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>num_labels = <span class="hljs-built_in">len</span>(id2label)`}}),pe=new ba({}),xe=new cs({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJudmlkaWElMkZtaXQtYjAlMjIlMEFpbWFnZV9wcm9jZXNzb3IlMjAlM0QlMjBBdXRvSW1hZ2VQcm9jZXNzb3IuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQlMkMlMjByZWR1Y2VfbGFiZWxzJTNEVHJ1ZSk=",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;nvidia/mit-b0&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(checkpoint, reduce_labels=<span class="hljs-literal">True</span>)`}}),Ue=new Re({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[tn]},$$scope:{ctx:q}}}),_e=new Re({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[nn]},$$scope:{ctx:q}}}),Ne=new ba({}),He=new cs({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMm1lYW5faW91JTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> evaluate

<span class="hljs-meta">&gt;&gt;&gt; </span>metric = evaluate.load(<span class="hljs-string">&quot;mean_iou&quot;</span>)`}}),Ie=new Re({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[rn]},$$scope:{ctx:q}}}),ve=new Re({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[cn]},$$scope:{ctx:q}}}),qe=new ba({}),Ce=new Re({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[fn]},$$scope:{ctx:q}}}),We=new Re({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Mn]},$$scope:{ctx:q}}}),Le=new ba({}),Ke=new cs({props:{code:"aW1hZ2UlMjAlM0QlMjBkcyU1QjAlNUQlNUIlMjJpbWFnZSUyMiU1RCUwQWltYWdl",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>image = ds[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;image&quot;</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>image`}}),Be=new Re({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[gn]},$$scope:{ctx:q}}}),Ge=new Re({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[wn]},$$scope:{ctx:q}}}),ea=new cs({props:{code:"aW1wb3J0JTIwbWF0cGxvdGxpYi5weXBsb3QlMjBhcyUyMHBsdCUwQWltcG9ydCUyMG51bXB5JTIwYXMlMjBucCUwQSUwQWNvbG9yX3NlZyUyMCUzRCUyMG5wLnplcm9zKChwcmVkX3NlZy5zaGFwZSU1QjAlNUQlMkMlMjBwcmVkX3NlZy5zaGFwZSU1QjElNUQlMkMlMjAzKSUyQyUyMGR0eXBlJTNEbnAudWludDgpJTBBcGFsZXR0ZSUyMCUzRCUyMG5wLmFycmF5KGFkZV9wYWxldHRlKCkpJTBBZm9yJTIwbGFiZWwlMkMlMjBjb2xvciUyMGluJTIwZW51bWVyYXRlKHBhbGV0dGUpJTNBJTBBJTIwJTIwJTIwJTIwY29sb3Jfc2VnJTVCcHJlZF9zZWclMjAlM0QlM0QlMjBsYWJlbCUyQyUyMCUzQSU1RCUyMCUzRCUyMGNvbG9yJTBBY29sb3Jfc2VnJTIwJTNEJTIwY29sb3Jfc2VnJTVCLi4uJTJDJTIwJTNBJTNBLTElNUQlMjAlMjAlMjMlMjBjb252ZXJ0JTIwdG8lMjBCR1IlMEElMEFpbWclMjAlM0QlMjBucC5hcnJheShpbWFnZSklMjAqJTIwMC41JTIwJTJCJTIwY29sb3Jfc2VnJTIwKiUyMDAuNSUyMCUyMCUyMyUyMHBsb3QlMjB0aGUlMjBpbWFnZSUyMHdpdGglMjB0aGUlMjBzZWdtZW50YXRpb24lMjBtYXAlMEFpbWclMjAlM0QlMjBpbWcuYXN0eXBlKG5wLnVpbnQ4KSUwQSUwQXBsdC5maWd1cmUoZmlnc2l6ZSUzRCgxNSUyQyUyMDEwKSklMEFwbHQuaW1zaG93KGltZyklMEFwbHQuc2hvdygp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt
<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>color_seg = np.zeros((pred_seg.shape[<span class="hljs-number">0</span>], pred_seg.shape[<span class="hljs-number">1</span>], <span class="hljs-number">3</span>), dtype=np.uint8)
<span class="hljs-meta">&gt;&gt;&gt; </span>palette = np.array(ade_palette())
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> label, color <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(palette):
<span class="hljs-meta">... </span>    color_seg[pred_seg == label, :] = color
<span class="hljs-meta">&gt;&gt;&gt; </span>color_seg = color_seg[..., ::-<span class="hljs-number">1</span>]  <span class="hljs-comment"># convert to BGR</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>img = np.array(image) * <span class="hljs-number">0.5</span> + color_seg * <span class="hljs-number">0.5</span>  <span class="hljs-comment"># plot the image with the segmentation map</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>img = img.astype(np.uint8)

<span class="hljs-meta">&gt;&gt;&gt; </span>plt.figure(figsize=(<span class="hljs-number">15</span>, <span class="hljs-number">10</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.imshow(img)
<span class="hljs-meta">&gt;&gt;&gt; </span>plt.show()`}}),{c(){o=r("meta"),f=u(),n=r("h1"),M=r("a"),T=r("span"),$(J.$$.fragment),A=u(),X=r("span"),Y=t("Semantic segmentation"),R=u(),$(F.$$.fragment),Z=u(),$(W.$$.fragment),N=u(),_=r("p"),os=t("Semantic segmentation assigns a label or class to each individual pixel of an image. There are several types of segmentation, and in the case of semantic segmentation, no distinction is made between unique instances of the same object. Both objects are given the same label (for example, \u201Ccar\u201D instead of \u201Ccar-1\u201D and \u201Ccar-2\u201D). Common real-world applications of semantic segmentation include training self-driving cars to identify pedestrians and important traffic information, identifying cells and abnormalities in medical imagery, and monitoring environmental changes from satellite imagery."),B=u(),L=r("p"),b=t("This guide will show you how to:"),V=u(),x=r("ol"),P=r("li"),O=t("Finetune "),as=r("a"),ts=t("SegFormer"),ns=t(" on the "),G=r("a"),fs=t("SceneParse150"),ms=t(" dataset."),us=u(),K=r("li"),rs=t("Use your finetuned model for inference."),ss=u(),$(z.$$.fragment),ps=u(),y=r("p"),Q=t("Before you begin, make sure you have all the necessary libraries installed:"),is=u(),$(ys.$$.fragment),hs=u(),ds=r("p"),j=t("We encourage you to log in to your Hugging Face account so you can upload and share your model with the community. When prompted, enter your token to log in:"),H=u(),$(w.$$.fragment),es=u(),gs=r("h2"),js=r("a"),Cs=r("span"),$(S.$$.fragment),Bs=u(),bs=r("span"),ks=t("Load SceneParse150 dataset"),Is=u(),Us=r("p"),_s=t("Start by loading a smaller subset of the SceneParse150 dataset from the \u{1F917} Datasets library. This\u2019ll give you a chance to experiment and make sure everything works before spending more time training on the full dataset."),Es=u(),$(Js.$$.fragment),ws=u(),Ts=r("p"),Fs=t("Split the dataset\u2019s "),As=r("code"),ae=t("train"),zs=t(" split into a train and test set with the "),Rs=r("a"),Xs=t("train_test_split"),Ys=t(" method:"),U=u(),$(ls.$$.fragment),Gs=u(),Ss=r("p"),Vs=t("Then take a look at an example:"),Ms=u(),$(Zs.$$.fragment),Ls=u(),$s=r("ul"),Qs=r("li"),xs=r("code"),ne=t("image"),oe=t(": a PIL image of the scene."),te=u(),vs=r("li"),Hs=r("code"),Ds=t("annotation"),Ks=t(": a PIL image of the segmentation map, which is also the model\u2019s target."),le=u(),m=r("li"),D=r("code"),Ws=t("scene_category"),oa=t(": a category id that describes the image scene like \u201Ckitchen\u201D or \u201Coffice\u201D. In this guide, you\u2019ll only need "),Me=r("code"),ye=t("image"),ra=t(" and "),ge=r("code"),pa=t("annotation"),je=t(", both of which are PIL images."),Ye=u(),Ps=r("p"),we=t("You\u2019ll also want to create a dictionary that maps a label id to a label class which will be useful when you set up the model later. Download the mappings from the Hub and create the "),be=r("code"),Os=t("id2label"),ia=t(" and "),Je=r("code"),ca=t("label2id"),Ns=t(" dictionaries:"),Fe=u(),$(re.$$.fragment),Ve=u(),se=r("h2"),qs=r("a"),Te=r("span"),$(pe.$$.fragment),yt=u(),Ta=r("span"),gt=t("Preprocess"),Fa=u(),ie=r("p"),jt=t("The next step is to load a SegFormer image processor to prepare the images and annotations for the model. Some datasets, like this one, use the zero-index as the background class. However, the background class isn\u2019t actually included in the 150 classes, so you\u2019ll need to set "),Ua=r("code"),wt=t("reduce_labels=True"),bt=t(" to subtract one from all the labels. The zero-index is replaced by "),_a=r("code"),Jt=t("255"),Tt=t(" so it\u2019s ignored by SegFormer\u2019s loss function:"),Va=u(),$(xe.$$.fragment),xa=u(),$(Ue.$$.fragment),Na=u(),$(_e.$$.fragment),za=u(),he=r("h2"),$e=r("a"),$a=r("span"),$(Ne.$$.fragment),Ut=u(),Ia=r("span"),_t=t("Evaluate"),Sa=u(),ee=r("p"),$t=t("Including a metric during training is often helpful for evaluating your model\u2019s performance. You can quickly load a evaluation method with the \u{1F917} "),ze=r("a"),It=t("Evaluate"),vt=t(" library. For this task, load the "),Se=r("a"),kt=t("mean Intersection over Union"),Et=t(" (IoU) metric (see the \u{1F917} Evaluate "),Qe=r("a"),Ct=t("quick tour"),Wt=t(" to learn more about how to load and compute a metric):"),Qa=u(),$(He.$$.fragment),Ha=u(),ce=r("p"),Zt=t("Then create a function to "),De=r("a"),Bt=t("compute"),Gt=t(` the metrics. Your predictions need to be converted to
logits first, and then reshaped to match the size of the labels before you can call `),Pe=r("a"),At=t("compute"),Rt=t(":"),Da=u(),$(Ie.$$.fragment),Pa=u(),$(ve.$$.fragment),qa=u(),ke=r("p"),Xt=t("Your "),va=r("code"),Yt=t("compute_metrics"),Ft=t(" function is ready to go now, and you\u2019ll return to it when you setup your training."),La=u(),fe=r("h2"),Ee=r("a"),ka=r("span"),$(qe.$$.fragment),Vt=u(),Ea=r("span"),xt=t("Train"),Ka=u(),$(Ce.$$.fragment),Oa=u(),$(We.$$.fragment),st=u(),ue=r("h2"),Ze=r("a"),Ca=r("span"),$(Le.$$.fragment),Nt=u(),Wa=r("span"),zt=t("Inference"),et=u(),ma=r("p"),St=t("Great, now that you\u2019ve finetuned a model, you can use it for inference!"),at=u(),ha=r("p"),Qt=t("Load an image for inference:"),tt=u(),$(Ke.$$.fragment),lt=u(),Oe=r("div"),fa=r("img"),nt=u(),$(Be.$$.fragment),ot=u(),$(Ge.$$.fragment),rt=u(),me=r("p"),Ht=t("To visualize the results, load the "),sa=r("a"),Dt=t("dataset color palette"),Pt=t(" as "),Za=r("code"),qt=t("ade_palette()"),Lt=t(" that maps each class to their RGB values. Then you can combine and plot your image and the predicted segmentation map:"),pt=u(),$(ea.$$.fragment),it=u(),aa=r("div"),ua=r("img"),this.h()},l(e){const h=Ll('[data-svelte="svelte-1phssyn"]',document.head);o=p(h,"META",{name:!0,content:!0}),h.forEach(a),f=d(e),n=p(e,"H1",{class:!0});var ta=i(n);M=p(ta,"A",{id:!0,class:!0,href:!0});var Ba=i(M);T=p(Ba,"SPAN",{});var Ga=i(T);I(J.$$.fragment,Ga),Ga.forEach(a),Ba.forEach(a),A=d(ta),X=p(ta,"SPAN",{});var Aa=i(X);Y=l(Aa,"Semantic segmentation"),Aa.forEach(a),ta.forEach(a),R=d(e),I(F.$$.fragment,e),Z=d(e),I(W.$$.fragment,e),N=d(e),_=p(e,"P",{});var Ra=i(_);os=l(Ra,"Semantic segmentation assigns a label or class to each individual pixel of an image. There are several types of segmentation, and in the case of semantic segmentation, no distinction is made between unique instances of the same object. Both objects are given the same label (for example, \u201Ccar\u201D instead of \u201Ccar-1\u201D and \u201Ccar-2\u201D). Common real-world applications of semantic segmentation include training self-driving cars to identify pedestrians and important traffic information, identifying cells and abnormalities in medical imagery, and monitoring environmental changes from satellite imagery."),Ra.forEach(a),B=d(e),L=p(e,"P",{});var Xa=i(L);b=l(Xa,"This guide will show you how to:"),Xa.forEach(a),V=d(e),x=p(e,"OL",{});var la=i(x);P=p(la,"LI",{});var de=i(P);O=l(de,"Finetune "),as=p(de,"A",{href:!0,rel:!0});var Ya=i(as);ts=l(Ya,"SegFormer"),Ya.forEach(a),ns=l(de," on the "),G=p(de,"A",{href:!0,rel:!0});var tl=i(G);fs=l(tl,"SceneParse150"),tl.forEach(a),ms=l(de," dataset."),de.forEach(a),us=d(la),K=p(la,"LI",{});var ll=i(K);rs=l(ll,"Use your finetuned model for inference."),ll.forEach(a),la.forEach(a),ss=d(e),I(z.$$.fragment,e),ps=d(e),y=p(e,"P",{});var nl=i(y);Q=l(nl,"Before you begin, make sure you have all the necessary libraries installed:"),nl.forEach(a),is=d(e),I(ys.$$.fragment,e),hs=d(e),ds=p(e,"P",{});var ol=i(ds);j=l(ol,"We encourage you to log in to your Hugging Face account so you can upload and share your model with the community. When prompted, enter your token to log in:"),ol.forEach(a),H=d(e),I(w.$$.fragment,e),es=d(e),gs=p(e,"H2",{class:!0});var mt=i(gs);js=p(mt,"A",{id:!0,class:!0,href:!0});var rl=i(js);Cs=p(rl,"SPAN",{});var pl=i(Cs);I(S.$$.fragment,pl),pl.forEach(a),rl.forEach(a),Bs=d(mt),bs=p(mt,"SPAN",{});var il=i(bs);ks=l(il,"Load SceneParse150 dataset"),il.forEach(a),mt.forEach(a),Is=d(e),Us=p(e,"P",{});var cl=i(Us);_s=l(cl,"Start by loading a smaller subset of the SceneParse150 dataset from the \u{1F917} Datasets library. This\u2019ll give you a chance to experiment and make sure everything works before spending more time training on the full dataset."),cl.forEach(a),Es=d(e),I(Js.$$.fragment,e),ws=d(e),Ts=p(e,"P",{});var da=i(Ts);Fs=l(da,"Split the dataset\u2019s "),As=p(da,"CODE",{});var ml=i(As);ae=l(ml,"train"),ml.forEach(a),zs=l(da," split into a train and test set with the "),Rs=p(da,"A",{href:!0,rel:!0});var hl=i(Rs);Xs=l(hl,"train_test_split"),hl.forEach(a),Ys=l(da," method:"),da.forEach(a),U=d(e),I(ls.$$.fragment,e),Gs=d(e),Ss=p(e,"P",{});var fl=i(Ss);Vs=l(fl,"Then take a look at an example:"),fl.forEach(a),Ms=d(e),I(Zs.$$.fragment,e),Ls=d(e),$s=p(e,"UL",{});var Ma=i($s);Qs=p(Ma,"LI",{});var Kt=i(Qs);xs=p(Kt,"CODE",{});var ul=i(xs);ne=l(ul,"image"),ul.forEach(a),oe=l(Kt,": a PIL image of the scene."),Kt.forEach(a),te=d(Ma),vs=p(Ma,"LI",{});var Ot=i(vs);Hs=p(Ot,"CODE",{});var dl=i(Hs);Ds=l(dl,"annotation"),dl.forEach(a),Ks=l(Ot,": a PIL image of the segmentation map, which is also the model\u2019s target."),Ot.forEach(a),le=d(Ma),m=p(Ma,"LI",{});var na=i(m);D=p(na,"CODE",{});var Ml=i(D);Ws=l(Ml,"scene_category"),Ml.forEach(a),oa=l(na,": a category id that describes the image scene like \u201Ckitchen\u201D or \u201Coffice\u201D. In this guide, you\u2019ll only need "),Me=p(na,"CODE",{});var yl=i(Me);ye=l(yl,"image"),yl.forEach(a),ra=l(na," and "),ge=p(na,"CODE",{});var gl=i(ge);pa=l(gl,"annotation"),gl.forEach(a),je=l(na,", both of which are PIL images."),na.forEach(a),Ma.forEach(a),Ye=d(e),Ps=p(e,"P",{});var ya=i(Ps);we=l(ya,"You\u2019ll also want to create a dictionary that maps a label id to a label class which will be useful when you set up the model later. Download the mappings from the Hub and create the "),be=p(ya,"CODE",{});var jl=i(be);Os=l(jl,"id2label"),jl.forEach(a),ia=l(ya," and "),Je=p(ya,"CODE",{});var wl=i(Je);ca=l(wl,"label2id"),wl.forEach(a),Ns=l(ya," dictionaries:"),ya.forEach(a),Fe=d(e),I(re.$$.fragment,e),Ve=d(e),se=p(e,"H2",{class:!0});var ht=i(se);qs=p(ht,"A",{id:!0,class:!0,href:!0});var bl=i(qs);Te=p(bl,"SPAN",{});var Jl=i(Te);I(pe.$$.fragment,Jl),Jl.forEach(a),bl.forEach(a),yt=d(ht),Ta=p(ht,"SPAN",{});var Tl=i(Ta);gt=l(Tl,"Preprocess"),Tl.forEach(a),ht.forEach(a),Fa=d(e),ie=p(e,"P",{});var ga=i(ie);jt=l(ga,"The next step is to load a SegFormer image processor to prepare the images and annotations for the model. Some datasets, like this one, use the zero-index as the background class. However, the background class isn\u2019t actually included in the 150 classes, so you\u2019ll need to set "),Ua=p(ga,"CODE",{});var Ul=i(Ua);wt=l(Ul,"reduce_labels=True"),Ul.forEach(a),bt=l(ga," to subtract one from all the labels. The zero-index is replaced by "),_a=p(ga,"CODE",{});var _l=i(_a);Jt=l(_l,"255"),_l.forEach(a),Tt=l(ga," so it\u2019s ignored by SegFormer\u2019s loss function:"),ga.forEach(a),Va=d(e),I(xe.$$.fragment,e),xa=d(e),I(Ue.$$.fragment,e),Na=d(e),I(_e.$$.fragment,e),za=d(e),he=p(e,"H2",{class:!0});var ft=i(he);$e=p(ft,"A",{id:!0,class:!0,href:!0});var $l=i($e);$a=p($l,"SPAN",{});var Il=i($a);I(Ne.$$.fragment,Il),Il.forEach(a),$l.forEach(a),Ut=d(ft),Ia=p(ft,"SPAN",{});var vl=i(Ia);_t=l(vl,"Evaluate"),vl.forEach(a),ft.forEach(a),Sa=d(e),ee=p(e,"P",{});var Ae=i(ee);$t=l(Ae,"Including a metric during training is often helpful for evaluating your model\u2019s performance. You can quickly load a evaluation method with the \u{1F917} "),ze=p(Ae,"A",{href:!0,rel:!0});var kl=i(ze);It=l(kl,"Evaluate"),kl.forEach(a),vt=l(Ae," library. For this task, load the "),Se=p(Ae,"A",{href:!0,rel:!0});var El=i(Se);kt=l(El,"mean Intersection over Union"),El.forEach(a),Et=l(Ae," (IoU) metric (see the \u{1F917} Evaluate "),Qe=p(Ae,"A",{href:!0,rel:!0});var Cl=i(Qe);Ct=l(Cl,"quick tour"),Cl.forEach(a),Wt=l(Ae," to learn more about how to load and compute a metric):"),Ae.forEach(a),Qa=d(e),I(He.$$.fragment,e),Ha=d(e),ce=p(e,"P",{});var ja=i(ce);Zt=l(ja,"Then create a function to "),De=p(ja,"A",{href:!0,rel:!0});var Wl=i(De);Bt=l(Wl,"compute"),Wl.forEach(a),Gt=l(ja,` the metrics. Your predictions need to be converted to
logits first, and then reshaped to match the size of the labels before you can call `),Pe=p(ja,"A",{href:!0,rel:!0});var Zl=i(Pe);At=l(Zl,"compute"),Zl.forEach(a),Rt=l(ja,":"),ja.forEach(a),Da=d(e),I(Ie.$$.fragment,e),Pa=d(e),I(ve.$$.fragment,e),qa=d(e),ke=p(e,"P",{});var ut=i(ke);Xt=l(ut,"Your "),va=p(ut,"CODE",{});var Bl=i(va);Yt=l(Bl,"compute_metrics"),Bl.forEach(a),Ft=l(ut," function is ready to go now, and you\u2019ll return to it when you setup your training."),ut.forEach(a),La=d(e),fe=p(e,"H2",{class:!0});var dt=i(fe);Ee=p(dt,"A",{id:!0,class:!0,href:!0});var Gl=i(Ee);ka=p(Gl,"SPAN",{});var Al=i(ka);I(qe.$$.fragment,Al),Al.forEach(a),Gl.forEach(a),Vt=d(dt),Ea=p(dt,"SPAN",{});var Rl=i(Ea);xt=l(Rl,"Train"),Rl.forEach(a),dt.forEach(a),Ka=d(e),I(Ce.$$.fragment,e),Oa=d(e),I(We.$$.fragment,e),st=d(e),ue=p(e,"H2",{class:!0});var Mt=i(ue);Ze=p(Mt,"A",{id:!0,class:!0,href:!0});var Xl=i(Ze);Ca=p(Xl,"SPAN",{});var Yl=i(Ca);I(Le.$$.fragment,Yl),Yl.forEach(a),Xl.forEach(a),Nt=d(Mt),Wa=p(Mt,"SPAN",{});var Fl=i(Wa);zt=l(Fl,"Inference"),Fl.forEach(a),Mt.forEach(a),et=d(e),ma=p(e,"P",{});var Vl=i(ma);St=l(Vl,"Great, now that you\u2019ve finetuned a model, you can use it for inference!"),Vl.forEach(a),at=d(e),ha=p(e,"P",{});var xl=i(ha);Qt=l(xl,"Load an image for inference:"),xl.forEach(a),tt=d(e),I(Ke.$$.fragment,e),lt=d(e),Oe=p(e,"DIV",{class:!0});var Nl=i(Oe);fa=p(Nl,"IMG",{src:!0,alt:!0}),Nl.forEach(a),nt=d(e),I(Be.$$.fragment,e),ot=d(e),I(Ge.$$.fragment,e),rt=d(e),me=p(e,"P",{});var wa=i(me);Ht=l(wa,"To visualize the results, load the "),sa=p(wa,"A",{href:!0,rel:!0});var zl=i(sa);Dt=l(zl,"dataset color palette"),zl.forEach(a),Pt=l(wa," as "),Za=p(wa,"CODE",{});var Sl=i(Za);qt=l(Sl,"ade_palette()"),Sl.forEach(a),Lt=l(wa," that maps each class to their RGB values. Then you can combine and plot your image and the predicted segmentation map:"),wa.forEach(a),pt=d(e),I(ea.$$.fragment,e),it=d(e),aa=p(e,"DIV",{class:!0});var Ql=i(aa);ua=p(Ql,"IMG",{src:!0,alt:!0}),Ql.forEach(a),this.h()},h(){g(o,"name","hf:doc:metadata"),g(o,"content",JSON.stringify(Jn)),g(M,"id","semantic-segmentation"),g(M,"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"),g(M,"href","#semantic-segmentation"),g(n,"class","relative group"),g(as,"href","https://huggingface.co/docs/transformers/main/en/model_doc/segformer#segformer"),g(as,"rel","nofollow"),g(G,"href","https://huggingface.co/datasets/scene_parse_150"),g(G,"rel","nofollow"),g(js,"id","load-sceneparse150-dataset"),g(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"),g(js,"href","#load-sceneparse150-dataset"),g(gs,"class","relative group"),g(Rs,"href","https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.train_test_split"),g(Rs,"rel","nofollow"),g(qs,"id","preprocess"),g(qs,"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"),g(qs,"href","#preprocess"),g(se,"class","relative group"),g($e,"id","evaluate"),g($e,"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"),g($e,"href","#evaluate"),g(he,"class","relative group"),g(ze,"href","https://huggingface.co/docs/evaluate/index"),g(ze,"rel","nofollow"),g(Se,"href","https://huggingface.co/spaces/evaluate-metric/accuracy"),g(Se,"rel","nofollow"),g(Qe,"href","https://huggingface.co/docs/evaluate/a_quick_tour"),g(Qe,"rel","nofollow"),g(De,"href","https://huggingface.co/docs/evaluate/main/en/package_reference/main_classes#evaluate.EvaluationModule.compute"),g(De,"rel","nofollow"),g(Pe,"href","https://huggingface.co/docs/evaluate/main/en/package_reference/main_classes#evaluate.EvaluationModule.compute"),g(Pe,"rel","nofollow"),g(Ee,"id","train"),g(Ee,"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"),g(Ee,"href","#train"),g(fe,"class","relative group"),g(Ze,"id","inference"),g(Ze,"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"),g(Ze,"href","#inference"),g(ue,"class","relative group"),Hl(fa.src,el="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/semantic-seg-image.png")||g(fa,"src",el),g(fa,"alt","Image of bedroom"),g(Oe,"class","flex justify-center"),g(sa,"href","https://github.com/tensorflow/models/blob/3f1ca33afe3c1631b733ea7e40c294273b9e406d/research/deeplab/utils/get_dataset_colormap.py#L51"),g(sa,"rel","nofollow"),Hl(ua.src,al="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/semantic-seg-preds.png")||g(ua,"src",al),g(ua,"alt","Image of bedroom overlaid with segmentation map"),g(aa,"class","flex justify-center")},m(e,h){s(document.head,o),c(e,f,h),c(e,n,h),s(n,M),s(M,T),v(J,T,null),s(n,A),s(n,X),s(X,Y),c(e,R,h),v(F,e,h),c(e,Z,h),v(W,e,h),c(e,N,h),c(e,_,h),s(_,os),c(e,B,h),c(e,L,h),s(L,b),c(e,V,h),c(e,x,h),s(x,P),s(P,O),s(P,as),s(as,ts),s(P,ns),s(P,G),s(G,fs),s(P,ms),s(x,us),s(x,K),s(K,rs),c(e,ss,h),v(z,e,h),c(e,ps,h),c(e,y,h),s(y,Q),c(e,is,h),v(ys,e,h),c(e,hs,h),c(e,ds,h),s(ds,j),c(e,H,h),v(w,e,h),c(e,es,h),c(e,gs,h),s(gs,js),s(js,Cs),v(S,Cs,null),s(gs,Bs),s(gs,bs),s(bs,ks),c(e,Is,h),c(e,Us,h),s(Us,_s),c(e,Es,h),v(Js,e,h),c(e,ws,h),c(e,Ts,h),s(Ts,Fs),s(Ts,As),s(As,ae),s(Ts,zs),s(Ts,Rs),s(Rs,Xs),s(Ts,Ys),c(e,U,h),v(ls,e,h),c(e,Gs,h),c(e,Ss,h),s(Ss,Vs),c(e,Ms,h),v(Zs,e,h),c(e,Ls,h),c(e,$s,h),s($s,Qs),s(Qs,xs),s(xs,ne),s(Qs,oe),s($s,te),s($s,vs),s(vs,Hs),s(Hs,Ds),s(vs,Ks),s($s,le),s($s,m),s(m,D),s(D,Ws),s(m,oa),s(m,Me),s(Me,ye),s(m,ra),s(m,ge),s(ge,pa),s(m,je),c(e,Ye,h),c(e,Ps,h),s(Ps,we),s(Ps,be),s(be,Os),s(Ps,ia),s(Ps,Je),s(Je,ca),s(Ps,Ns),c(e,Fe,h),v(re,e,h),c(e,Ve,h),c(e,se,h),s(se,qs),s(qs,Te),v(pe,Te,null),s(se,yt),s(se,Ta),s(Ta,gt),c(e,Fa,h),c(e,ie,h),s(ie,jt),s(ie,Ua),s(Ua,wt),s(ie,bt),s(ie,_a),s(_a,Jt),s(ie,Tt),c(e,Va,h),v(xe,e,h),c(e,xa,h),v(Ue,e,h),c(e,Na,h),v(_e,e,h),c(e,za,h),c(e,he,h),s(he,$e),s($e,$a),v(Ne,$a,null),s(he,Ut),s(he,Ia),s(Ia,_t),c(e,Sa,h),c(e,ee,h),s(ee,$t),s(ee,ze),s(ze,It),s(ee,vt),s(ee,Se),s(Se,kt),s(ee,Et),s(ee,Qe),s(Qe,Ct),s(ee,Wt),c(e,Qa,h),v(He,e,h),c(e,Ha,h),c(e,ce,h),s(ce,Zt),s(ce,De),s(De,Bt),s(ce,Gt),s(ce,Pe),s(Pe,At),s(ce,Rt),c(e,Da,h),v(Ie,e,h),c(e,Pa,h),v(ve,e,h),c(e,qa,h),c(e,ke,h),s(ke,Xt),s(ke,va),s(va,Yt),s(ke,Ft),c(e,La,h),c(e,fe,h),s(fe,Ee),s(Ee,ka),v(qe,ka,null),s(fe,Vt),s(fe,Ea),s(Ea,xt),c(e,Ka,h),v(Ce,e,h),c(e,Oa,h),v(We,e,h),c(e,st,h),c(e,ue,h),s(ue,Ze),s(Ze,Ca),v(Le,Ca,null),s(ue,Nt),s(ue,Wa),s(Wa,zt),c(e,et,h),c(e,ma,h),s(ma,St),c(e,at,h),c(e,ha,h),s(ha,Qt),c(e,tt,h),v(Ke,e,h),c(e,lt,h),c(e,Oe,h),s(Oe,fa),c(e,nt,h),v(Be,e,h),c(e,ot,h),v(Ge,e,h),c(e,rt,h),c(e,me,h),s(me,Ht),s(me,sa),s(sa,Dt),s(me,Pt),s(me,Za),s(Za,qt),s(me,Lt),c(e,pt,h),v(ea,e,h),c(e,it,h),c(e,aa,h),s(aa,ua),ct=!0},p(e,[h]){const ta={};h&2&&(ta.$$scope={dirty:h,ctx:e}),z.$set(ta);const Ba={};h&2&&(Ba.$$scope={dirty:h,ctx:e}),Ue.$set(Ba);const Ga={};h&2&&(Ga.$$scope={dirty:h,ctx:e}),_e.$set(Ga);const Aa={};h&2&&(Aa.$$scope={dirty:h,ctx:e}),Ie.$set(Aa);const Ra={};h&2&&(Ra.$$scope={dirty:h,ctx:e}),ve.$set(Ra);const Xa={};h&2&&(Xa.$$scope={dirty:h,ctx:e}),Ce.$set(Xa);const la={};h&2&&(la.$$scope={dirty:h,ctx:e}),We.$set(la);const de={};h&2&&(de.$$scope={dirty:h,ctx:e}),Be.$set(de);const Ya={};h&2&&(Ya.$$scope={dirty:h,ctx:e}),Ge.$set(Ya)},i(e){ct||(k(J.$$.fragment,e),k(F.$$.fragment,e),k(W.$$.fragment,e),k(z.$$.fragment,e),k(ys.$$.fragment,e),k(w.$$.fragment,e),k(S.$$.fragment,e),k(Js.$$.fragment,e),k(ls.$$.fragment,e),k(Zs.$$.fragment,e),k(re.$$.fragment,e),k(pe.$$.fragment,e),k(xe.$$.fragment,e),k(Ue.$$.fragment,e),k(_e.$$.fragment,e),k(Ne.$$.fragment,e),k(He.$$.fragment,e),k(Ie.$$.fragment,e),k(ve.$$.fragment,e),k(qe.$$.fragment,e),k(Ce.$$.fragment,e),k(We.$$.fragment,e),k(Le.$$.fragment,e),k(Ke.$$.fragment,e),k(Be.$$.fragment,e),k(Ge.$$.fragment,e),k(ea.$$.fragment,e),ct=!0)},o(e){E(J.$$.fragment,e),E(F.$$.fragment,e),E(W.$$.fragment,e),E(z.$$.fragment,e),E(ys.$$.fragment,e),E(w.$$.fragment,e),E(S.$$.fragment,e),E(Js.$$.fragment,e),E(ls.$$.fragment,e),E(Zs.$$.fragment,e),E(re.$$.fragment,e),E(pe.$$.fragment,e),E(xe.$$.fragment,e),E(Ue.$$.fragment,e),E(_e.$$.fragment,e),E(Ne.$$.fragment,e),E(He.$$.fragment,e),E(Ie.$$.fragment,e),E(ve.$$.fragment,e),E(qe.$$.fragment,e),E(Ce.$$.fragment,e),E(We.$$.fragment,e),E(Le.$$.fragment,e),E(Ke.$$.fragment,e),E(Be.$$.fragment,e),E(Ge.$$.fragment,e),E(ea.$$.fragment,e),ct=!1},d(e){a(o),e&&a(f),e&&a(n),C(J),e&&a(R),C(F,e),e&&a(Z),C(W,e),e&&a(N),e&&a(_),e&&a(B),e&&a(L),e&&a(V),e&&a(x),e&&a(ss),C(z,e),e&&a(ps),e&&a(y),e&&a(is),C(ys,e),e&&a(hs),e&&a(ds),e&&a(H),C(w,e),e&&a(es),e&&a(gs),C(S),e&&a(Is),e&&a(Us),e&&a(Es),C(Js,e),e&&a(ws),e&&a(Ts),e&&a(U),C(ls,e),e&&a(Gs),e&&a(Ss),e&&a(Ms),C(Zs,e),e&&a(Ls),e&&a($s),e&&a(Ye),e&&a(Ps),e&&a(Fe),C(re,e),e&&a(Ve),e&&a(se),C(pe),e&&a(Fa),e&&a(ie),e&&a(Va),C(xe,e),e&&a(xa),C(Ue,e),e&&a(Na),C(_e,e),e&&a(za),e&&a(he),C(Ne),e&&a(Sa),e&&a(ee),e&&a(Qa),C(He,e),e&&a(Ha),e&&a(ce),e&&a(Da),C(Ie,e),e&&a(Pa),C(ve,e),e&&a(qa),e&&a(ke),e&&a(La),e&&a(fe),C(qe),e&&a(Ka),C(Ce,e),e&&a(Oa),C(We,e),e&&a(st),e&&a(ue),C(Le),e&&a(et),e&&a(ma),e&&a(at),e&&a(ha),e&&a(tt),C(Ke,e),e&&a(lt),e&&a(Oe),e&&a(nt),C(Be,e),e&&a(ot),C(Ge,e),e&&a(rt),e&&a(me),e&&a(pt),C(ea,e),e&&a(it),e&&a(aa)}}}const Jn={local:"semantic-segmentation",sections:[{local:"load-sceneparse150-dataset",title:"Load SceneParse150 dataset"},{local:"preprocess",title:"Preprocess"},{local:"evaluate",title:"Evaluate"},{local:"train",title:"Train"},{local:"inference",title:"Inference"}],title:"Semantic segmentation"};function Tn(q){return Kl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Cn extends Dl{constructor(o){super();Pl(this,o,Tn,bn,ql,{})}}export{Cn as default,Jn as metadata};
