import{s as Ha,o as Qa,n as ss}from"../chunks/scheduler.9bc65507.js";import{S as za,i as Aa,g as T,s as m,r as u,A as Ea,h as U,f as l,c as i,j as Na,u as j,x as W,k as ya,y as Sa,a as t,v as y,d,t as f,w,m as La,n as Da}from"../chunks/index.707bf1b6.js";import{T as da}from"../chunks/Tip.c2ecdbf4.js";import{Y as qa}from"../chunks/Youtube.e1129c6f.js";import{C as G}from"../chunks/CodeBlock.54a9f38d.js";import{D as Ka}from"../chunks/DocNotebookDropdown.3e6b3817.js";import{F as cs,M as Ms}from"../chunks/Markdown.8ab98a13.js";import{H as Gs}from"../chunks/Heading.342b1fa6.js";function Pa(k){let e,c,a='<a href="../model_doc/beit">BEiT</a>, <a href="../model_doc/data2vec-vision">Data2VecVision</a>, <a href="../model_doc/dpt">DPT</a>, <a href="../model_doc/mobilenet_v2">MobileNetV2</a>, <a href="../model_doc/mobilevit">MobileViT</a>, <a href="../model_doc/mobilevitv2">MobileViTV2</a>, <a href="../model_doc/segformer">SegFormer</a>, <a href="../model_doc/upernet">UPerNet</a>';return{c(){e=La(`The task illustrated in this tutorial is supported by the following model architectures:

`),c=T("p"),c.innerHTML=a},l(o){e=Da(o,`The task illustrated in this tutorial is supported by the following model architectures:

`),c=U(o,"P",{"data-svelte-h":!0}),W(c)!=="svelte-19l83ao"&&(c.innerHTML=a)},m(o,g){t(o,e,g),t(o,c,g)},p:ss,d(o){o&&(l(e),l(c))}}}function Oa(k){let e,c='It is common to apply some data augmentations to an image dataset to make a model more robust against overfitting. In this guide, you’ll use the <a href="https://pytorch.org/vision/stable/generated/torchvision.transforms.ColorJitter.html" rel="nofollow"><code>ColorJitter</code></a> function from <a href="https://pytorch.org/vision/stable/index.html" rel="nofollow">torchvision</a> to randomly change the color properties of an image, but you can also use any image library you like.',a,o,g,_,X="Now create two preprocessing functions to prepare the images and annotations for the model. These functions convert the images into <code>pixel_values</code> and annotations to <code>labels</code>. For the training set, <code>jitter</code> is applied before providing the images to the image processor. For the test set, the image processor crops and normalizes the <code>images</code>, and only crops the <code>labels</code> because no data augmentation is applied during testing.",Z,$,R,C,Y='To apply the <code>jitter</code> over the entire dataset, use the 🤗 Datasets <a href="https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.set_transform" rel="nofollow">set_transform</a> function. The transform is applied on the fly which is faster and consumes less disk space:',x,J,V;return o=new G({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>)`,wrap:!1}}),$=new G({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`,wrap:!1}}),J=new G({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)`,wrap:!1}}),{c(){e=T("p"),e.innerHTML=c,a=m(),u(o.$$.fragment),g=m(),_=T("p"),_.innerHTML=X,Z=m(),u($.$$.fragment),R=m(),C=T("p"),C.innerHTML=Y,x=m(),u(J.$$.fragment)},l(r){e=U(r,"P",{"data-svelte-h":!0}),W(e)!=="svelte-43dxhy"&&(e.innerHTML=c),a=i(r),j(o.$$.fragment,r),g=i(r),_=U(r,"P",{"data-svelte-h":!0}),W(_)!=="svelte-qerdt3"&&(_.innerHTML=X),Z=i(r),j($.$$.fragment,r),R=i(r),C=U(r,"P",{"data-svelte-h":!0}),W(C)!=="svelte-tijv00"&&(C.innerHTML=Y),x=i(r),j(J.$$.fragment,r)},m(r,b){t(r,e,b),t(r,a,b),y(o,r,b),t(r,g,b),t(r,_,b),t(r,Z,b),y($,r,b),t(r,R,b),t(r,C,b),t(r,x,b),y(J,r,b),V=!0},p:ss,i(r){V||(d(o.$$.fragment,r),d($.$$.fragment,r),d(J.$$.fragment,r),V=!0)},o(r){f(o.$$.fragment,r),f($.$$.fragment,r),f(J.$$.fragment,r),V=!1},d(r){r&&(l(e),l(a),l(g),l(_),l(Z),l(R),l(C),l(x)),w(o,r),w($,r),w(J,r)}}}function se(k){let e,c;return e=new Ms({props:{$$slots:{default:[Oa]},$$scope:{ctx:k}}}),{c(){u(e.$$.fragment)},l(a){j(e.$$.fragment,a)},m(a,o){y(e,a,o),c=!0},p(a,o){const g={};o&2&&(g.$$scope={dirty:o,ctx:a}),e.$set(g)},i(a){c||(d(e.$$.fragment,a),c=!0)},o(a){f(e.$$.fragment,a),c=!1},d(a){w(e,a)}}}function ae(k){let e,c=`It is common to apply some data augmentations to an image dataset to make a model more robust against overfitting.
In this guide, you’ll use <a href="https://www.tensorflow.org/api_docs/python/tf/image" rel="nofollow"><code>tf.image</code></a> 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,o,g="<li>training data transformations that include image augmentation</li> <li>validation data transformations that only transpose the images, since computer vision models in 🤗 Transformers expect channels-first layout</li>",_,X,Z,$,R=`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 <code>image_processor</code> to convert the images into <code>pixel_values</code> and
annotations to <code>labels</code>. <code>ImageProcessor</code> also takes care of resizing and normalizing the images.`,C,Y,x,J,V=`To apply the preprocessing transformations over the entire dataset, use the 🤗 Datasets <a href="https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.set_transform" rel="nofollow">set_transform</a> function.
The transform is applied on the fly which is faster and consumes less disk space:`,r,b,F;return X=new G({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`,wrap:!1}}),Y=new G({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`,wrap:!1}}),b=new G({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)`,wrap:!1}}),{c(){e=T("p"),e.innerHTML=c,a=m(),o=T("ul"),o.innerHTML=g,_=m(),u(X.$$.fragment),Z=m(),$=T("p"),$.innerHTML=R,C=m(),u(Y.$$.fragment),x=m(),J=T("p"),J.innerHTML=V,r=m(),u(b.$$.fragment)},l(h){e=U(h,"P",{"data-svelte-h":!0}),W(e)!=="svelte-1rj6vla"&&(e.innerHTML=c),a=i(h),o=U(h,"UL",{"data-svelte-h":!0}),W(o)!=="svelte-lmmfid"&&(o.innerHTML=g),_=i(h),j(X.$$.fragment,h),Z=i(h),$=U(h,"P",{"data-svelte-h":!0}),W($)!=="svelte-hpi41l"&&($.innerHTML=R),C=i(h),j(Y.$$.fragment,h),x=i(h),J=U(h,"P",{"data-svelte-h":!0}),W(J)!=="svelte-19lox7v"&&(J.innerHTML=V),r=i(h),j(b.$$.fragment,h)},m(h,B){t(h,e,B),t(h,a,B),t(h,o,B),t(h,_,B),y(X,h,B),t(h,Z,B),t(h,$,B),t(h,C,B),y(Y,h,B),t(h,x,B),t(h,J,B),t(h,r,B),y(b,h,B),F=!0},p:ss,i(h){F||(d(X.$$.fragment,h),d(Y.$$.fragment,h),d(b.$$.fragment,h),F=!0)},o(h){f(X.$$.fragment,h),f(Y.$$.fragment,h),f(b.$$.fragment,h),F=!1},d(h){h&&(l(e),l(a),l(o),l(_),l(Z),l($),l(C),l(x),l(J),l(r)),w(X,h),w(Y,h),w(b,h)}}}function ee(k){let e,c;return e=new Ms({props:{$$slots:{default:[ae]},$$scope:{ctx:k}}}),{c(){u(e.$$.fragment)},l(a){j(e.$$.fragment,a)},m(a,o){y(e,a,o),c=!0},p(a,o){const g={};o&2&&(g.$$scope={dirty:o,ctx:a}),e.$set(g)},i(a){c||(d(e.$$.fragment,a),c=!0)},o(a){f(e.$$.fragment,a),c=!1},d(a){w(e,a)}}}function le(k){let e,c;return e=new G({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBaW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdG9yY2glMjBpbXBvcnQlMjBubiUwQSUwQWRlZiUyMGNvbXB1dGVfbWV0cmljcyhldmFsX3ByZWQpJTNBJTBBJTIwJTIwJTIwJTIwd2l0aCUyMHRvcmNoLm5vX2dyYWQoKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxvZ2l0cyUyQyUyMGxhYmVscyUyMCUzRCUyMGV2YWxfcHJlZCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxvZ2l0c190ZW5zb3IlMjAlM0QlMjB0b3JjaC5mcm9tX251bXB5KGxvZ2l0cyklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsb2dpdHNfdGVuc29yJTIwJTNEJTIwbm4uZnVuY3Rpb25hbC5pbnRlcnBvbGF0ZSglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsb2dpdHNfdGVuc29yJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2l6ZSUzRGxhYmVscy5zaGFwZSU1Qi0yJTNBJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbW9kZSUzRCUyMmJpbGluZWFyJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYWxpZ25fY29ybmVycyUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKS5hcmdtYXgoZGltJTNEMSklMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmVkX2xhYmVscyUyMCUzRCUyMGxvZ2l0c190ZW5zb3IuZGV0YWNoKCkuY3B1KCkubnVtcHkoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG1ldHJpY3MlMjAlM0QlMjBtZXRyaWMuY29tcHV0ZSglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUzRHByZWRfbGFiZWxzJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmVmZXJlbmNlcyUzRGxhYmVscyUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9sYWJlbHMlM0RudW1fbGFiZWxzJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaWdub3JlX2luZGV4JTNEMjU1JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmVkdWNlX2xhYmVscyUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZvciUyMGtleSUyQyUyMHZhbHVlJTIwaW4lMjBtZXRyaWNzLml0ZW1zKCklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpZiUyMGlzaW5zdGFuY2UodmFsdWUlMkMlMjBucC5uZGFycmF5KSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG1ldHJpY3MlNUJrZXklNUQlMjAlM0QlMjB2YWx1ZS50b2xpc3QoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJldHVybiUyMG1ldHJpY3M=",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">isinstance</span>(value, np.ndarray):
<span class="hljs-meta">... </span>                metrics[key] = value.tolist()
<span class="hljs-meta">... </span>        <span class="hljs-keyword">return</span> metrics`,wrap:!1}}),{c(){u(e.$$.fragment)},l(a){j(e.$$.fragment,a)},m(a,o){y(e,a,o),c=!0},p:ss,i(a){c||(d(e.$$.fragment,a),c=!0)},o(a){f(e.$$.fragment,a),c=!1},d(a){w(e,a)}}}function te(k){let e,c;return e=new Ms({props:{$$slots:{default:[le]},$$scope:{ctx:k}}}),{c(){u(e.$$.fragment)},l(a){j(e.$$.fragment,a)},m(a,o){y(e,a,o),c=!0},p(a,o){const g={};o&2&&(g.$$scope={dirty:o,ctx:a}),e.$set(g)},i(a){c||(d(e.$$.fragment,a),c=!0)},o(a){f(e.$$.fragment,a),c=!1},d(a){w(e,a)}}}function ne(k){let e,c;return e=new G({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()}`,wrap:!1}}),{c(){u(e.$$.fragment)},l(a){j(e.$$.fragment,a)},m(a,o){y(e,a,o),c=!0},p:ss,i(a){c||(d(e.$$.fragment,a),c=!0)},o(a){f(e.$$.fragment,a),c=!1},d(a){w(e,a)}}}function pe(k){let e,c;return e=new Ms({props:{$$slots:{default:[ne]},$$scope:{ctx:k}}}),{c(){u(e.$$.fragment)},l(a){j(e.$$.fragment,a)},m(a,o){y(e,a,o),c=!0},p(a,o){const g={};o&2&&(g.$$scope={dirty:o,ctx:a}),e.$set(g)},i(a){c||(d(e.$$.fragment,a),c=!0)},o(a){f(e.$$.fragment,a),c=!1},d(a){w(e,a)}}}function re(k){let e,c='If you aren’t familiar with finetuning a model with the <a href="/docs/transformers/main/en/main_classes/trainer#transformers.Trainer">Trainer</a>, take a look at the basic tutorial <a href="../training#finetune-with-trainer">here</a>!';return{c(){e=T("p"),e.innerHTML=c},l(a){e=U(a,"P",{"data-svelte-h":!0}),W(e)!=="svelte-inlhq6"&&(e.innerHTML=c)},m(a,o){t(a,e,o)},p:ss,d(a){a&&l(e)}}}function oe(k){let e,c,a,o='You’re ready to start training your model now! Load SegFormer with <a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoModelForSemanticSegmentation">AutoModelForSemanticSegmentation</a>, and pass the model the mapping between label ids and label classes:',g,_,X,Z,$="At this point, only three steps remain:",R,C,Y='<li>Define your training hyperparameters in <a href="/docs/transformers/main/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a>. It is important you don’t remove unused columns because this’ll drop the <code>image</code> column. Without the <code>image</code> column, you can’t create <code>pixel_values</code>. Set <code>remove_unused_columns=False</code> to prevent this behavior! The only other required parameter is <code>output_dir</code> which specifies where to save your model. You’ll push this model to the Hub by setting <code>push_to_hub=True</code> (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the <a href="/docs/transformers/main/en/main_classes/trainer#transformers.Trainer">Trainer</a> will evaluate the IoU metric and save the training checkpoint.</li> <li>Pass the training arguments to <a href="/docs/transformers/main/en/main_classes/trainer#transformers.Trainer">Trainer</a> along with the model, dataset, tokenizer, data collator, and <code>compute_metrics</code> function.</li> <li>Call <a href="/docs/transformers/main/en/main_classes/trainer#transformers.Trainer.train">train()</a> to finetune your model.</li>',x,J,V,r,b='Once training is completed, share your model to the Hub with the <a href="/docs/transformers/main/en/main_classes/trainer#transformers.Trainer.push_to_hub">push_to_hub()</a> method so everyone can use your model:',F,h,B;return e=new da({props:{$$slots:{default:[re]},$$scope:{ctx:k}}}),_=new G({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)`,wrap:!1}}),J=new G({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()`,wrap:!1}}),h=new G({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()',wrap:!1}}),{c(){u(e.$$.fragment),c=m(),a=T("p"),a.innerHTML=o,g=m(),u(_.$$.fragment),X=m(),Z=T("p"),Z.textContent=$,R=m(),C=T("ol"),C.innerHTML=Y,x=m(),u(J.$$.fragment),V=m(),r=T("p"),r.innerHTML=b,F=m(),u(h.$$.fragment)},l(p){j(e.$$.fragment,p),c=i(p),a=U(p,"P",{"data-svelte-h":!0}),W(a)!=="svelte-1bjkl0k"&&(a.innerHTML=o),g=i(p),j(_.$$.fragment,p),X=i(p),Z=U(p,"P",{"data-svelte-h":!0}),W(Z)!=="svelte-l42k0i"&&(Z.textContent=$),R=i(p),C=U(p,"OL",{"data-svelte-h":!0}),W(C)!=="svelte-6v7ckc"&&(C.innerHTML=Y),x=i(p),j(J.$$.fragment,p),V=i(p),r=U(p,"P",{"data-svelte-h":!0}),W(r)!=="svelte-1v13hlo"&&(r.innerHTML=b),F=i(p),j(h.$$.fragment,p)},m(p,I){y(e,p,I),t(p,c,I),t(p,a,I),t(p,g,I),y(_,p,I),t(p,X,I),t(p,Z,I),t(p,R,I),t(p,C,I),t(p,x,I),y(J,p,I),t(p,V,I),t(p,r,I),t(p,F,I),y(h,p,I),B=!0},p(p,I){const E={};I&2&&(E.$$scope={dirty:I,ctx:p}),e.$set(E)},i(p){B||(d(e.$$.fragment,p),d(_.$$.fragment,p),d(J.$$.fragment,p),d(h.$$.fragment,p),B=!0)},o(p){f(e.$$.fragment,p),f(_.$$.fragment,p),f(J.$$.fragment,p),f(h.$$.fragment,p),B=!1},d(p){p&&(l(c),l(a),l(g),l(X),l(Z),l(R),l(C),l(x),l(V),l(r),l(F)),w(e,p),w(_,p),w(J,p),w(h,p)}}}function me(k){let e,c;return e=new Ms({props:{$$slots:{default:[oe]},$$scope:{ctx:k}}}),{c(){u(e.$$.fragment)},l(a){j(e.$$.fragment,a)},m(a,o){y(e,a,o),c=!0},p(a,o){const g={};o&2&&(g.$$scope={dirty:o,ctx:a}),e.$set(g)},i(a){c||(d(e.$$.fragment,a),c=!0)},o(a){f(e.$$.fragment,a),c=!1},d(a){w(e,a)}}}function ie(k){let e,c='If you are unfamiliar with fine-tuning a model with Keras, check out the <a href="./training#train-a-tensorflow-model-with-keras">basic tutorial</a> first!';return{c(){e=T("p"),e.innerHTML=c},l(a){e=U(a,"P",{"data-svelte-h":!0}),W(e)!=="svelte-1egt5s9"&&(e.innerHTML=c)},m(a,o){t(a,e,o)},p:ss,d(a){a&&l(e)}}}function ce(k){let e,c,a,o="To fine-tune a model in TensorFlow, follow these steps:",g,_,X="<li>Define the training hyperparameters, and set up an optimizer and a learning rate schedule.</li> <li>Instantiate a pretrained model.</li> <li>Convert a 🤗 Dataset to a <code>tf.data.Dataset</code>.</li> <li>Compile your model.</li> <li>Add callbacks to calculate metrics and upload your model to 🤗 Hub</li> <li>Use the <code>fit()</code> method to run the training.</li>",Z,$,R="Start by defining the hyperparameters, optimizer and learning rate schedule:",C,Y,x,J,V=`Then, load SegFormer with <a href="/docs/transformers/main/en/model_doc/auto#transformers.TFAutoModelForSemanticSegmentation">TFAutoModelForSemanticSegmentation</a> 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’t need to specify one unless you want to:`,r,b,F,h,B='Convert your datasets to the <code>tf.data.Dataset</code> format using the <a href="https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.to_tf_dataset" rel="nofollow">to_tf_dataset</a> and the <a href="/docs/transformers/main/en/main_classes/data_collator#transformers.DefaultDataCollator">DefaultDataCollator</a>:',p,I,E,z,S=`To compute the accuracy from the predictions and push your model to the 🤗 Hub, use <a href="../main_classes/keras_callbacks">Keras callbacks</a>.
Pass your <code>compute_metrics</code> function to <a href="/docs/transformers/main/en/main_classes/keras_callbacks#transformers.KerasMetricCallback">KerasMetricCallback</a>,
and use the <a href="/docs/transformers/main/en/main_classes/keras_callbacks#transformers.PushToHubCallback">PushToHubCallback</a> to upload the model:`,q,N,hs,A,L=`Finally, you are ready to train your model! Call <code>fit()</code> with your training and validation datasets, the number of epochs,
and your callbacks to fine-tune the model:`,K,H,P,Q,Xs="Congratulations! You have fine-tuned your model and shared it on the 🤗 Hub. You can now use it for inference!",O;return e=new da({props:{$$slots:{default:[ie]},$$scope:{ctx:k}}}),Y=new G({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>)`,wrap:!1}}),b=new G({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>`,wrap:!1}}),I=new G({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>)`,wrap:!1}}),N=new G({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]`,wrap:!1}}),H=new G({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>)`,wrap:!1}}),{c(){u(e.$$.fragment),c=m(),a=T("p"),a.textContent=o,g=m(),_=T("ol"),_.innerHTML=X,Z=m(),$=T("p"),$.textContent=R,C=m(),u(Y.$$.fragment),x=m(),J=T("p"),J.innerHTML=V,r=m(),u(b.$$.fragment),F=m(),h=T("p"),h.innerHTML=B,p=m(),u(I.$$.fragment),E=m(),z=T("p"),z.innerHTML=S,q=m(),u(N.$$.fragment),hs=m(),A=T("p"),A.innerHTML=L,K=m(),u(H.$$.fragment),P=m(),Q=T("p"),Q.textContent=Xs},l(M){j(e.$$.fragment,M),c=i(M),a=U(M,"P",{"data-svelte-h":!0}),W(a)!=="svelte-s07fxj"&&(a.textContent=o),g=i(M),_=U(M,"OL",{"data-svelte-h":!0}),W(_)!=="svelte-1e3w1hr"&&(_.innerHTML=X),Z=i(M),$=U(M,"P",{"data-svelte-h":!0}),W($)!=="svelte-ccl3wn"&&($.textContent=R),C=i(M),j(Y.$$.fragment,M),x=i(M),J=U(M,"P",{"data-svelte-h":!0}),W(J)!=="svelte-1xg5478"&&(J.innerHTML=V),r=i(M),j(b.$$.fragment,M),F=i(M),h=U(M,"P",{"data-svelte-h":!0}),W(h)!=="svelte-7cvdbm"&&(h.innerHTML=B),p=i(M),j(I.$$.fragment,M),E=i(M),z=U(M,"P",{"data-svelte-h":!0}),W(z)!=="svelte-1b1pfl3"&&(z.innerHTML=S),q=i(M),j(N.$$.fragment,M),hs=i(M),A=U(M,"P",{"data-svelte-h":!0}),W(A)!=="svelte-1occr1z"&&(A.innerHTML=L),K=i(M),j(H.$$.fragment,M),P=i(M),Q=U(M,"P",{"data-svelte-h":!0}),W(Q)!=="svelte-1r99pbn"&&(Q.textContent=Xs)},m(M,v){y(e,M,v),t(M,c,v),t(M,a,v),t(M,g,v),t(M,_,v),t(M,Z,v),t(M,$,v),t(M,C,v),y(Y,M,v),t(M,x,v),t(M,J,v),t(M,r,v),y(b,M,v),t(M,F,v),t(M,h,v),t(M,p,v),y(I,M,v),t(M,E,v),t(M,z,v),t(M,q,v),y(N,M,v),t(M,hs,v),t(M,A,v),t(M,K,v),y(H,M,v),t(M,P,v),t(M,Q,v),O=!0},p(M,v){const D={};v&2&&(D.$$scope={dirty:v,ctx:M}),e.$set(D)},i(M){O||(d(e.$$.fragment,M),d(Y.$$.fragment,M),d(b.$$.fragment,M),d(I.$$.fragment,M),d(N.$$.fragment,M),d(H.$$.fragment,M),O=!0)},o(M){f(e.$$.fragment,M),f(Y.$$.fragment,M),f(b.$$.fragment,M),f(I.$$.fragment,M),f(N.$$.fragment,M),f(H.$$.fragment,M),O=!1},d(M){M&&(l(c),l(a),l(g),l(_),l(Z),l($),l(C),l(x),l(J),l(r),l(F),l(h),l(p),l(E),l(z),l(q),l(hs),l(A),l(K),l(P),l(Q)),w(e,M),w(Y,M),w(b,M),w(I,M),w(N,M),w(H,M)}}}function Me(k){let e,c;return e=new Ms({props:{$$slots:{default:[ce]},$$scope:{ctx:k}}}),{c(){u(e.$$.fragment)},l(a){j(e.$$.fragment,a)},m(a,o){y(e,a,o),c=!0},p(a,o){const g={};o&2&&(g.$$scope={dirty:o,ctx:a}),e.$set(g)},i(a){c||(d(e.$$.fragment,a),c=!0)},o(a){f(e.$$.fragment,a),c=!1},d(a){w(e,a)}}}function he(k){let e,c='The simplest way to try out your finetuned model for inference is to use it in a <a href="/docs/transformers/main/en/main_classes/pipelines#transformers.pipeline">pipeline()</a>. Instantiate a <code>pipeline</code> for image segmentation with your model, and pass your image to it:',a,o,g,_,X="You can also manually replicate the results of the <code>pipeline</code> if you’d like. Process the image with an image processor and place the <code>pixel_values</code> on a GPU:",Z,$,R,C,Y="Pass your input to the model and return the <code>logits</code>:",x,J,V,r,b="Next, rescale the logits to the original image size:",F,h,B;return o=new G({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;}]`,wrap:!1}}),$=new G({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)`,wrap:!1}}),J=new G({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()`,wrap:!1}}),h=new G({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>]`,wrap:!1}}),{c(){e=T("p"),e.innerHTML=c,a=m(),u(o.$$.fragment),g=m(),_=T("p"),_.innerHTML=X,Z=m(),u($.$$.fragment),R=m(),C=T("p"),C.innerHTML=Y,x=m(),u(J.$$.fragment),V=m(),r=T("p"),r.textContent=b,F=m(),u(h.$$.fragment)},l(p){e=U(p,"P",{"data-svelte-h":!0}),W(e)!=="svelte-uiomix"&&(e.innerHTML=c),a=i(p),j(o.$$.fragment,p),g=i(p),_=U(p,"P",{"data-svelte-h":!0}),W(_)!=="svelte-58ednc"&&(_.innerHTML=X),Z=i(p),j($.$$.fragment,p),R=i(p),C=U(p,"P",{"data-svelte-h":!0}),W(C)!=="svelte-oyplyw"&&(C.innerHTML=Y),x=i(p),j(J.$$.fragment,p),V=i(p),r=U(p,"P",{"data-svelte-h":!0}),W(r)!=="svelte-tk6q3q"&&(r.textContent=b),F=i(p),j(h.$$.fragment,p)},m(p,I){t(p,e,I),t(p,a,I),y(o,p,I),t(p,g,I),t(p,_,I),t(p,Z,I),y($,p,I),t(p,R,I),t(p,C,I),t(p,x,I),y(J,p,I),t(p,V,I),t(p,r,I),t(p,F,I),y(h,p,I),B=!0},p:ss,i(p){B||(d(o.$$.fragment,p),d($.$$.fragment,p),d(J.$$.fragment,p),d(h.$$.fragment,p),B=!0)},o(p){f(o.$$.fragment,p),f($.$$.fragment,p),f(J.$$.fragment,p),f(h.$$.fragment,p),B=!1},d(p){p&&(l(e),l(a),l(g),l(_),l(Z),l(R),l(C),l(x),l(V),l(r),l(F)),w(o,p),w($,p),w(J,p),w(h,p)}}}function ge(k){let e,c;return e=new Ms({props:{$$slots:{default:[he]},$$scope:{ctx:k}}}),{c(){u(e.$$.fragment)},l(a){j(e.$$.fragment,a)},m(a,o){y(e,a,o),c=!0},p(a,o){const g={};o&2&&(g.$$scope={dirty:o,ctx:a}),e.$set(g)},i(a){c||(d(e.$$.fragment,a),c=!0)},o(a){f(e.$$.fragment,a),c=!1},d(a){w(e,a)}}}function ue(k){let e,c="Load an image processor to preprocess the image and return the input as TensorFlow tensors:",a,o,g,_,X="Pass your input to the model and return the <code>logits</code>:",Z,$,R,C,Y="Next, rescale the logits to the original image size and apply argmax on the class dimension:",x,J,V;return o=new G({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>)`,wrap:!1}}),$=new G({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`,wrap:!1}}),J=new G({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>]`,wrap:!1}}),{c(){e=T("p"),e.textContent=c,a=m(),u(o.$$.fragment),g=m(),_=T("p"),_.innerHTML=X,Z=m(),u($.$$.fragment),R=m(),C=T("p"),C.textContent=Y,x=m(),u(J.$$.fragment)},l(r){e=U(r,"P",{"data-svelte-h":!0}),W(e)!=="svelte-1r2yss0"&&(e.textContent=c),a=i(r),j(o.$$.fragment,r),g=i(r),_=U(r,"P",{"data-svelte-h":!0}),W(_)!=="svelte-oyplyw"&&(_.innerHTML=X),Z=i(r),j($.$$.fragment,r),R=i(r),C=U(r,"P",{"data-svelte-h":!0}),W(C)!=="svelte-enih9r"&&(C.textContent=Y),x=i(r),j(J.$$.fragment,r)},m(r,b){t(r,e,b),t(r,a,b),y(o,r,b),t(r,g,b),t(r,_,b),t(r,Z,b),y($,r,b),t(r,R,b),t(r,C,b),t(r,x,b),y(J,r,b),V=!0},p:ss,i(r){V||(d(o.$$.fragment,r),d($.$$.fragment,r),d(J.$$.fragment,r),V=!0)},o(r){f(o.$$.fragment,r),f($.$$.fragment,r),f(J.$$.fragment,r),V=!1},d(r){r&&(l(e),l(a),l(g),l(_),l(Z),l(R),l(C),l(x)),w(o,r),w($,r),w(J,r)}}}function je(k){let e,c;return e=new Ms({props:{$$slots:{default:[ue]},$$scope:{ctx:k}}}),{c(){u(e.$$.fragment)},l(a){j(e.$$.fragment,a)},m(a,o){y(e,a,o),c=!0},p(a,o){const g={};o&2&&(g.$$scope={dirty:o,ctx:a}),e.$set(g)},i(a){c||(d(e.$$.fragment,a),c=!0)},o(a){f(e.$$.fragment,a),c=!1},d(a){w(e,a)}}}function ye(k){let e,c,a,o,g,_,X,Z,$,R,C,Y="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, “car” instead of “car-1” and “car-2”). 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.",x,J,V="This guide will show you how to:",r,b,F='<li>Finetune <a href="https://huggingface.co/docs/transformers/main/en/model_doc/segformer#segformer" rel="nofollow">SegFormer</a> on the <a href="https://huggingface.co/datasets/scene_parse_150" rel="nofollow">SceneParse150</a> dataset.</li> <li>Use your finetuned model for inference.</li>',h,B,p,I,E="Before you begin, make sure you have all the necessary libraries installed:",z,S,q,N,hs="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:",A,L,K,H,P,Q,Xs="Start by loading a smaller subset of the SceneParse150 dataset from the 🤗 Datasets library. This’ll give you a chance to experiment and make sure everything works before spending more time training on the full dataset.",O,M,v,D,fa='Split the dataset’s <code>train</code> split into a train and test set with the <a href="https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.train_test_split" rel="nofollow">train_test_split</a> method:',Ys,gs,Vs,us,wa="Then take a look at an example:",Fs,js,Ns,ys,Ja="<li><code>image</code>: a PIL image of the scene.</li> <li><code>annotation</code>: a PIL image of the segmentation map, which is also the model’s target.</li> <li><code>scene_category</code>: a category id that describes the image scene like “kitchen” or “office”. In this guide, you’ll only need <code>image</code> and <code>annotation</code>, both of which are PIL images.</li>",Hs,ds,ba="You’ll 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 <code>id2label</code> and <code>label2id</code> dictionaries:",Qs,fs,zs,ws,As,Js,Ta="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’t actually included in the 150 classes, so you’ll need to set <code>reduce_labels=True</code> to subtract one from all the labels. The zero-index is replaced by <code>255</code> so it’s ignored by SegFormer’s loss function:",Es,bs,Ss,as,Ls,es,Ds,Ts,qs,Us,Ua='Including a metric during training is often helpful for evaluating your model’s performance. You can quickly load an evaluation method with the 🤗 <a href="https://huggingface.co/docs/evaluate/index" rel="nofollow">Evaluate</a> library. For this task, load the <a href="https://huggingface.co/spaces/evaluate-metric/accuracy" rel="nofollow">mean Intersection over Union</a> (IoU) metric (see the 🤗 Evaluate <a href="https://huggingface.co/docs/evaluate/a_quick_tour" rel="nofollow">quick tour</a> to learn more about how to load and compute a metric):',Ks,$s,Ps,Is,$a=`Then create a function to <a href="https://huggingface.co/docs/evaluate/main/en/package_reference/main_classes#evaluate.EvaluationModule.compute" rel="nofollow">compute</a> 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 <a href="https://huggingface.co/docs/evaluate/main/en/package_reference/main_classes#evaluate.EvaluationModule.compute" rel="nofollow">compute</a>:`,Os,ls,sa,ts,aa,_s,Ia="Your <code>compute_metrics</code> function is ready to go now, and you’ll return to it when you setup your training.",ea,Cs,la,ns,ta,ps,na,Ws,pa,ks,_a="Great, now that you’ve finetuned a model, you can use it for inference!",ra,Zs,Ca="Load an image for inference:",oa,Bs,ma,rs,Wa='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/semantic-seg-image.png" alt="Image of bedroom"/>',ia,os,ca,ms,Ma,vs,ka='To visualize the results, load the <a href="https://github.com/tensorflow/models/blob/3f1ca33afe3c1631b733ea7e40c294273b9e406d/research/deeplab/utils/get_dataset_colormap.py#L51" rel="nofollow">dataset color palette</a> as <code>ade_palette()</code> that maps each class to their RGB values. Then you can combine and plot your image and the predicted segmentation map:',ha,xs,ga,is,Za='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/semantic-seg-preds.png" alt="Image of bedroom overlaid with segmentation map"/>',ua,Rs,ja;return g=new Gs({props:{title:"Semantic segmentation",local:"semantic-segmentation",headingTag:"h1"}}),X=new Ka({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"}]}}),$=new qa({props:{id:"dKE8SIt9C-w"}}),B=new da({props:{$$slots:{default:[Pa]},$$scope:{ctx:k}}}),S=new G({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1xJTIwZGF0YXNldHMlMjB0cmFuc2Zvcm1lcnMlMjBldmFsdWF0ZQ==",highlighted:"pip install -q datasets transformers evaluate",wrap:!1}}),L=new G({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

<span class="hljs-meta">&gt;&gt;&gt; </span>notebook_login()`,wrap:!1}}),H=new Gs({props:{title:"Load SceneParse150 dataset",local:"load-sceneparse150-dataset",headingTag:"h2"}}),M=new G({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>)`,wrap:!1}}),gs=new G({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>]`,wrap:!1}}),js=new G({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>}`,wrap:!1}}),fs=new G({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-id2label.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)`,wrap:!1}}),ws=new Gs({props:{title:"Preprocess",local:"preprocess",headingTag:"h2"}}),bs=new G({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>)`,wrap:!1}}),as=new cs({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[se]},$$scope:{ctx:k}}}),es=new cs({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[ee]},$$scope:{ctx:k}}}),Ts=new Gs({props:{title:"Evaluate",local:"evaluate",headingTag:"h2"}}),$s=new G({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>)`,wrap:!1}}),ls=new cs({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[te]},$$scope:{ctx:k}}}),ts=new cs({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[pe]},$$scope:{ctx:k}}}),Cs=new Gs({props:{title:"Train",local:"train",headingTag:"h2"}}),ns=new cs({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[me]},$$scope:{ctx:k}}}),ps=new cs({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Me]},$$scope:{ctx:k}}}),Ws=new Gs({props:{title:"Inference",local:"inference",headingTag:"h2"}}),Bs=new G({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`,wrap:!1}}),os=new cs({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[ge]},$$scope:{ctx:k}}}),ms=new cs({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[je]},$$scope:{ctx:k}}}),xs=new G({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()`,wrap:!1}}),{c(){e=T("meta"),c=m(),a=T("p"),o=m(),u(g.$$.fragment),_=m(),u(X.$$.fragment),Z=m(),u($.$$.fragment),R=m(),C=T("p"),C.textContent=Y,x=m(),J=T("p"),J.textContent=V,r=m(),b=T("ol"),b.innerHTML=F,h=m(),u(B.$$.fragment),p=m(),I=T("p"),I.textContent=E,z=m(),u(S.$$.fragment),q=m(),N=T("p"),N.textContent=hs,A=m(),u(L.$$.fragment),K=m(),u(H.$$.fragment),P=m(),Q=T("p"),Q.textContent=Xs,O=m(),u(M.$$.fragment),v=m(),D=T("p"),D.innerHTML=fa,Ys=m(),u(gs.$$.fragment),Vs=m(),us=T("p"),us.textContent=wa,Fs=m(),u(js.$$.fragment),Ns=m(),ys=T("ul"),ys.innerHTML=Ja,Hs=m(),ds=T("p"),ds.innerHTML=ba,Qs=m(),u(fs.$$.fragment),zs=m(),u(ws.$$.fragment),As=m(),Js=T("p"),Js.innerHTML=Ta,Es=m(),u(bs.$$.fragment),Ss=m(),u(as.$$.fragment),Ls=m(),u(es.$$.fragment),Ds=m(),u(Ts.$$.fragment),qs=m(),Us=T("p"),Us.innerHTML=Ua,Ks=m(),u($s.$$.fragment),Ps=m(),Is=T("p"),Is.innerHTML=$a,Os=m(),u(ls.$$.fragment),sa=m(),u(ts.$$.fragment),aa=m(),_s=T("p"),_s.innerHTML=Ia,ea=m(),u(Cs.$$.fragment),la=m(),u(ns.$$.fragment),ta=m(),u(ps.$$.fragment),na=m(),u(Ws.$$.fragment),pa=m(),ks=T("p"),ks.textContent=_a,ra=m(),Zs=T("p"),Zs.textContent=Ca,oa=m(),u(Bs.$$.fragment),ma=m(),rs=T("div"),rs.innerHTML=Wa,ia=m(),u(os.$$.fragment),ca=m(),u(ms.$$.fragment),Ma=m(),vs=T("p"),vs.innerHTML=ka,ha=m(),u(xs.$$.fragment),ga=m(),is=T("div"),is.innerHTML=Za,ua=m(),Rs=T("p"),this.h()},l(s){const n=Ea("svelte-u9bgzb",document.head);e=U(n,"META",{name:!0,content:!0}),n.forEach(l),c=i(s),a=U(s,"P",{}),Na(a).forEach(l),o=i(s),j(g.$$.fragment,s),_=i(s),j(X.$$.fragment,s),Z=i(s),j($.$$.fragment,s),R=i(s),C=U(s,"P",{"data-svelte-h":!0}),W(C)!=="svelte-1sbjiw"&&(C.textContent=Y),x=i(s),J=U(s,"P",{"data-svelte-h":!0}),W(J)!=="svelte-1aff4p7"&&(J.textContent=V),r=i(s),b=U(s,"OL",{"data-svelte-h":!0}),W(b)!=="svelte-u87rmm"&&(b.innerHTML=F),h=i(s),j(B.$$.fragment,s),p=i(s),I=U(s,"P",{"data-svelte-h":!0}),W(I)!=="svelte-1c9nexd"&&(I.textContent=E),z=i(s),j(S.$$.fragment,s),q=i(s),N=U(s,"P",{"data-svelte-h":!0}),W(N)!=="svelte-27hn0u"&&(N.textContent=hs),A=i(s),j(L.$$.fragment,s),K=i(s),j(H.$$.fragment,s),P=i(s),Q=U(s,"P",{"data-svelte-h":!0}),W(Q)!=="svelte-ldhwp2"&&(Q.textContent=Xs),O=i(s),j(M.$$.fragment,s),v=i(s),D=U(s,"P",{"data-svelte-h":!0}),W(D)!=="svelte-rugbz4"&&(D.innerHTML=fa),Ys=i(s),j(gs.$$.fragment,s),Vs=i(s),us=U(s,"P",{"data-svelte-h":!0}),W(us)!=="svelte-1m91ua0"&&(us.textContent=wa),Fs=i(s),j(js.$$.fragment,s),Ns=i(s),ys=U(s,"UL",{"data-svelte-h":!0}),W(ys)!=="svelte-1gb3b0f"&&(ys.innerHTML=Ja),Hs=i(s),ds=U(s,"P",{"data-svelte-h":!0}),W(ds)!=="svelte-j46pio"&&(ds.innerHTML=ba),Qs=i(s),j(fs.$$.fragment,s),zs=i(s),j(ws.$$.fragment,s),As=i(s),Js=U(s,"P",{"data-svelte-h":!0}),W(Js)!=="svelte-7ebr"&&(Js.innerHTML=Ta),Es=i(s),j(bs.$$.fragment,s),Ss=i(s),j(as.$$.fragment,s),Ls=i(s),j(es.$$.fragment,s),Ds=i(s),j(Ts.$$.fragment,s),qs=i(s),Us=U(s,"P",{"data-svelte-h":!0}),W(Us)!=="svelte-vg2xml"&&(Us.innerHTML=Ua),Ks=i(s),j($s.$$.fragment,s),Ps=i(s),Is=U(s,"P",{"data-svelte-h":!0}),W(Is)!=="svelte-aq72n8"&&(Is.innerHTML=$a),Os=i(s),j(ls.$$.fragment,s),sa=i(s),j(ts.$$.fragment,s),aa=i(s),_s=U(s,"P",{"data-svelte-h":!0}),W(_s)!=="svelte-183aynn"&&(_s.innerHTML=Ia),ea=i(s),j(Cs.$$.fragment,s),la=i(s),j(ns.$$.fragment,s),ta=i(s),j(ps.$$.fragment,s),na=i(s),j(Ws.$$.fragment,s),pa=i(s),ks=U(s,"P",{"data-svelte-h":!0}),W(ks)!=="svelte-633ppb"&&(ks.textContent=_a),ra=i(s),Zs=U(s,"P",{"data-svelte-h":!0}),W(Zs)!=="svelte-1g0hugc"&&(Zs.textContent=Ca),oa=i(s),j(Bs.$$.fragment,s),ma=i(s),rs=U(s,"DIV",{class:!0,"data-svelte-h":!0}),W(rs)!=="svelte-11jfm1f"&&(rs.innerHTML=Wa),ia=i(s),j(os.$$.fragment,s),ca=i(s),j(ms.$$.fragment,s),Ma=i(s),vs=U(s,"P",{"data-svelte-h":!0}),W(vs)!=="svelte-1ng77tx"&&(vs.innerHTML=ka),ha=i(s),j(xs.$$.fragment,s),ga=i(s),is=U(s,"DIV",{class:!0,"data-svelte-h":!0}),W(is)!=="svelte-nsecok"&&(is.innerHTML=Za),ua=i(s),Rs=U(s,"P",{}),Na(Rs).forEach(l),this.h()},h(){ya(e,"name","hf:doc:metadata"),ya(e,"content",de),ya(rs,"class","flex justify-center"),ya(is,"class","flex justify-center")},m(s,n){Sa(document.head,e),t(s,c,n),t(s,a,n),t(s,o,n),y(g,s,n),t(s,_,n),y(X,s,n),t(s,Z,n),y($,s,n),t(s,R,n),t(s,C,n),t(s,x,n),t(s,J,n),t(s,r,n),t(s,b,n),t(s,h,n),y(B,s,n),t(s,p,n),t(s,I,n),t(s,z,n),y(S,s,n),t(s,q,n),t(s,N,n),t(s,A,n),y(L,s,n),t(s,K,n),y(H,s,n),t(s,P,n),t(s,Q,n),t(s,O,n),y(M,s,n),t(s,v,n),t(s,D,n),t(s,Ys,n),y(gs,s,n),t(s,Vs,n),t(s,us,n),t(s,Fs,n),y(js,s,n),t(s,Ns,n),t(s,ys,n),t(s,Hs,n),t(s,ds,n),t(s,Qs,n),y(fs,s,n),t(s,zs,n),y(ws,s,n),t(s,As,n),t(s,Js,n),t(s,Es,n),y(bs,s,n),t(s,Ss,n),y(as,s,n),t(s,Ls,n),y(es,s,n),t(s,Ds,n),y(Ts,s,n),t(s,qs,n),t(s,Us,n),t(s,Ks,n),y($s,s,n),t(s,Ps,n),t(s,Is,n),t(s,Os,n),y(ls,s,n),t(s,sa,n),y(ts,s,n),t(s,aa,n),t(s,_s,n),t(s,ea,n),y(Cs,s,n),t(s,la,n),y(ns,s,n),t(s,ta,n),y(ps,s,n),t(s,na,n),y(Ws,s,n),t(s,pa,n),t(s,ks,n),t(s,ra,n),t(s,Zs,n),t(s,oa,n),y(Bs,s,n),t(s,ma,n),t(s,rs,n),t(s,ia,n),y(os,s,n),t(s,ca,n),y(ms,s,n),t(s,Ma,n),t(s,vs,n),t(s,ha,n),y(xs,s,n),t(s,ga,n),t(s,is,n),t(s,ua,n),t(s,Rs,n),ja=!0},p(s,[n]){const Ba={};n&2&&(Ba.$$scope={dirty:n,ctx:s}),B.$set(Ba);const va={};n&2&&(va.$$scope={dirty:n,ctx:s}),as.$set(va);const xa={};n&2&&(xa.$$scope={dirty:n,ctx:s}),es.$set(xa);const Ga={};n&2&&(Ga.$$scope={dirty:n,ctx:s}),ls.$set(Ga);const Xa={};n&2&&(Xa.$$scope={dirty:n,ctx:s}),ts.$set(Xa);const Ra={};n&2&&(Ra.$$scope={dirty:n,ctx:s}),ns.$set(Ra);const Ya={};n&2&&(Ya.$$scope={dirty:n,ctx:s}),ps.$set(Ya);const Va={};n&2&&(Va.$$scope={dirty:n,ctx:s}),os.$set(Va);const Fa={};n&2&&(Fa.$$scope={dirty:n,ctx:s}),ms.$set(Fa)},i(s){ja||(d(g.$$.fragment,s),d(X.$$.fragment,s),d($.$$.fragment,s),d(B.$$.fragment,s),d(S.$$.fragment,s),d(L.$$.fragment,s),d(H.$$.fragment,s),d(M.$$.fragment,s),d(gs.$$.fragment,s),d(js.$$.fragment,s),d(fs.$$.fragment,s),d(ws.$$.fragment,s),d(bs.$$.fragment,s),d(as.$$.fragment,s),d(es.$$.fragment,s),d(Ts.$$.fragment,s),d($s.$$.fragment,s),d(ls.$$.fragment,s),d(ts.$$.fragment,s),d(Cs.$$.fragment,s),d(ns.$$.fragment,s),d(ps.$$.fragment,s),d(Ws.$$.fragment,s),d(Bs.$$.fragment,s),d(os.$$.fragment,s),d(ms.$$.fragment,s),d(xs.$$.fragment,s),ja=!0)},o(s){f(g.$$.fragment,s),f(X.$$.fragment,s),f($.$$.fragment,s),f(B.$$.fragment,s),f(S.$$.fragment,s),f(L.$$.fragment,s),f(H.$$.fragment,s),f(M.$$.fragment,s),f(gs.$$.fragment,s),f(js.$$.fragment,s),f(fs.$$.fragment,s),f(ws.$$.fragment,s),f(bs.$$.fragment,s),f(as.$$.fragment,s),f(es.$$.fragment,s),f(Ts.$$.fragment,s),f($s.$$.fragment,s),f(ls.$$.fragment,s),f(ts.$$.fragment,s),f(Cs.$$.fragment,s),f(ns.$$.fragment,s),f(ps.$$.fragment,s),f(Ws.$$.fragment,s),f(Bs.$$.fragment,s),f(os.$$.fragment,s),f(ms.$$.fragment,s),f(xs.$$.fragment,s),ja=!1},d(s){s&&(l(c),l(a),l(o),l(_),l(Z),l(R),l(C),l(x),l(J),l(r),l(b),l(h),l(p),l(I),l(z),l(q),l(N),l(A),l(K),l(P),l(Q),l(O),l(v),l(D),l(Ys),l(Vs),l(us),l(Fs),l(Ns),l(ys),l(Hs),l(ds),l(Qs),l(zs),l(As),l(Js),l(Es),l(Ss),l(Ls),l(Ds),l(qs),l(Us),l(Ks),l(Ps),l(Is),l(Os),l(sa),l(aa),l(_s),l(ea),l(la),l(ta),l(na),l(pa),l(ks),l(ra),l(Zs),l(oa),l(ma),l(rs),l(ia),l(ca),l(Ma),l(vs),l(ha),l(ga),l(is),l(ua),l(Rs)),l(e),w(g,s),w(X,s),w($,s),w(B,s),w(S,s),w(L,s),w(H,s),w(M,s),w(gs,s),w(js,s),w(fs,s),w(ws,s),w(bs,s),w(as,s),w(es,s),w(Ts,s),w($s,s),w(ls,s),w(ts,s),w(Cs,s),w(ns,s),w(ps,s),w(Ws,s),w(Bs,s),w(os,s),w(ms,s),w(xs,s)}}}const de='{"title":"Semantic segmentation","local":"semantic-segmentation","sections":[{"title":"Load SceneParse150 dataset","local":"load-sceneparse150-dataset","sections":[],"depth":2},{"title":"Preprocess","local":"preprocess","sections":[],"depth":2},{"title":"Evaluate","local":"evaluate","sections":[],"depth":2},{"title":"Train","local":"train","sections":[],"depth":2},{"title":"Inference","local":"inference","sections":[],"depth":2}],"depth":1}';function fe(k){return Qa(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ce extends za{constructor(e){super(),Aa(this,e,fe,ye,Ha,{})}}export{Ce as component};
