import{S as Rl,i as Vl,s as Wl,e as o,k as u,w as E,t,M as Ql,c as i,d as a,m as g,a as p,x as P,h as l,b as $,N as Jl,G as s,g as m,y as T,q,o as I,B as D,v as Xl,L as ya}from"../../chunks/vendor-hf-doc-builder.js";import{T as el}from"../../chunks/Tip-hf-doc-builder.js";import{Y as Zl}from"../../chunks/Youtube-hf-doc-builder.js";import{I as va}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as oe}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as en}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";import{F as Ls,M as Os}from"../../chunks/Markdown-hf-doc-builder.js";function sn(Q){let r,f,n,d,w,y,S,L,O,F,M,z,A,U,x,ne,C,X,v,H,B,V;return{c(){r=t(`The task illustrated in this tutorial is supported by the following model architectures:

`),f=o("p"),n=o("a"),d=t("BEiT"),w=t(", "),y=o("a"),S=t("Data2VecVision"),L=t(", "),O=o("a"),F=t("DPT"),M=t(", "),z=o("a"),A=t("MobileNetV2"),U=t(", "),x=o("a"),ne=t("MobileViT"),C=t(", "),X=o("a"),v=t("SegFormer"),H=t(", "),B=o("a"),V=t("UPerNet"),this.h()},l(G){r=l(G,`The task illustrated in this tutorial is supported by the following model architectures:

`),f=i(G,"P",{});var N=p(f);n=i(N,"A",{href:!0});var ae=p(n);d=l(ae,"BEiT"),ae.forEach(a),w=l(N,", "),y=i(N,"A",{href:!0});var ue=p(y);S=l(ue,"Data2VecVision"),ue.forEach(a),L=l(N,", "),O=i(N,"A",{href:!0});var te=p(O);F=l(te,"DPT"),te.forEach(a),M=l(N,", "),z=i(N,"A",{href:!0});var he=p(z);A=l(he,"MobileNetV2"),he.forEach(a),U=l(N,", "),x=i(N,"A",{href:!0});var ie=p(x);ne=l(ie,"MobileViT"),ie.forEach(a),C=l(N,", "),X=i(N,"A",{href:!0});var fe=p(X);v=l(fe,"SegFormer"),fe.forEach(a),H=l(N,", "),B=i(N,"A",{href:!0});var Z=p(B);V=l(Z,"UPerNet"),Z.forEach(a),N.forEach(a),this.h()},h(){$(n,"href","../model_doc/beit"),$(y,"href","../model_doc/data2vec-vision"),$(O,"href","../model_doc/dpt"),$(z,"href","../model_doc/mobilenet_v2"),$(x,"href","../model_doc/mobilevit"),$(X,"href","../model_doc/segformer"),$(B,"href","../model_doc/upernet")},m(G,N){m(G,r,N),m(G,f,N),s(f,n),s(n,d),s(f,w),s(f,y),s(y,S),s(f,L),s(f,O),s(O,F),s(f,M),s(f,z),s(z,A),s(f,U),s(f,x),s(x,ne),s(f,C),s(f,X),s(X,v),s(f,H),s(f,B),s(B,V)},d(G){G&&a(r),G&&a(f)}}}function an(Q){let r,f,n,d,w,y,S,L,O,F,M,z,A,U,x,ne,C,X,v,H,B,V,G,N,ae,ue,te,he,ie,fe,Z,me,le,W,ce,_,K,re,_e,pe,ge,b,J;return M=new oe({props:{code:`from torchvision.transforms import ColorJitter

jitter = ColorJitter(brightness=0.25, contrast=0.25, saturation=0.25, hue=0.1)`,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>)`}}),Z=new oe({props:{code:`def train_transforms(example_batch):
    images = [jitter(x) for x in example_batch["image"]]
    labels = [x for x in example_batch["annotation"]]
    inputs = image_processor(images, labels)
    return inputs


def val_transforms(example_batch):
    images = [x for x in example_batch["image"]]
    labels = [x for x in example_batch["annotation"]]
    inputs = image_processor(images, labels)
    return inputs`,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`}}),b=new oe({props:{code:`train_ds.set_transform(train_transforms)
test_ds.set_transform(val_transforms)`,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(){r=o("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=o("a"),d=o("code"),w=t("ColorJitter"),y=t(" function from "),S=o("a"),L=t("torchvision"),O=t(" to randomly change the color properties of an image, but you can also use any image library you like."),F=u(),E(M.$$.fragment),z=u(),A=o("p"),U=t("Now create two preprocessing functions to prepare the images and annotations for the model. These functions convert the images into "),x=o("code"),ne=t("pixel_values"),C=t(" and annotations to "),X=o("code"),v=t("labels"),H=t(". For the training set, "),B=o("code"),V=t("jitter"),G=t(" is applied before providing the images to the image processor. For the test set, the image processor crops and normalizes the "),N=o("code"),ae=t("images"),ue=t(", and only crops the "),te=o("code"),he=t("labels"),ie=t(" because no data augmentation is applied during testing."),fe=u(),E(Z.$$.fragment),me=u(),le=o("p"),W=t("To apply the "),ce=o("code"),_=t("jitter"),K=t(" over the entire dataset, use the \u{1F917} Datasets "),re=o("a"),_e=t("set_transform"),pe=t(" function. The transform is applied on the fly which is faster and consumes less disk space:"),ge=u(),E(b.$$.fragment),this.h()},l(j){r=i(j,"P",{});var ee=p(r);f=l(ee,"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=i(ee,"A",{href:!0,rel:!0});var $e=p(n);d=i($e,"CODE",{});var be=p(d);w=l(be,"ColorJitter"),be.forEach(a),$e.forEach(a),y=l(ee," function from "),S=i(ee,"A",{href:!0,rel:!0});var De=p(S);L=l(De,"torchvision"),De.forEach(a),O=l(ee," to randomly change the color properties of an image, but you can also use any image library you like."),ee.forEach(a),F=g(j),P(M.$$.fragment,j),z=g(j),A=i(j,"P",{});var Y=p(A);U=l(Y,"Now create two preprocessing functions to prepare the images and annotations for the model. These functions convert the images into "),x=i(Y,"CODE",{});var Ce=p(x);ne=l(Ce,"pixel_values"),Ce.forEach(a),C=l(Y," and annotations to "),X=i(Y,"CODE",{});var ve=p(X);v=l(ve,"labels"),ve.forEach(a),H=l(Y,". For the training set, "),B=i(Y,"CODE",{});var qe=p(B);V=l(qe,"jitter"),qe.forEach(a),G=l(Y," is applied before providing the images to the image processor. For the test set, the image processor crops and normalizes the "),N=i(Y,"CODE",{});var Pe=p(N);ae=l(Pe,"images"),Pe.forEach(a),ue=l(Y,", and only crops the "),te=i(Y,"CODE",{});var ke=p(te);he=l(ke,"labels"),ke.forEach(a),ie=l(Y," because no data augmentation is applied during testing."),Y.forEach(a),fe=g(j),P(Z.$$.fragment,j),me=g(j),le=i(j,"P",{});var xe=p(le);W=l(xe,"To apply the "),ce=i(xe,"CODE",{});var Ie=p(ce);_=l(Ie,"jitter"),Ie.forEach(a),K=l(xe," over the entire dataset, use the \u{1F917} Datasets "),re=i(xe,"A",{href:!0,rel:!0});var ye=p(re);_e=l(ye,"set_transform"),ye.forEach(a),pe=l(xe," function. The transform is applied on the fly which is faster and consumes less disk space:"),xe.forEach(a),ge=g(j),P(b.$$.fragment,j),this.h()},h(){$(n,"href","https://pytorch.org/vision/stable/generated/torchvision.transforms.ColorJitter.html"),$(n,"rel","nofollow"),$(S,"href","https://pytorch.org/vision/stable/index.html"),$(S,"rel","nofollow"),$(re,"href","https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.set_transform"),$(re,"rel","nofollow")},m(j,ee){m(j,r,ee),s(r,f),s(r,n),s(n,d),s(d,w),s(r,y),s(r,S),s(S,L),s(r,O),m(j,F,ee),T(M,j,ee),m(j,z,ee),m(j,A,ee),s(A,U),s(A,x),s(x,ne),s(A,C),s(A,X),s(X,v),s(A,H),s(A,B),s(B,V),s(A,G),s(A,N),s(N,ae),s(A,ue),s(A,te),s(te,he),s(A,ie),m(j,fe,ee),T(Z,j,ee),m(j,me,ee),m(j,le,ee),s(le,W),s(le,ce),s(ce,_),s(le,K),s(le,re),s(re,_e),s(le,pe),m(j,ge,ee),T(b,j,ee),J=!0},p:ya,i(j){J||(q(M.$$.fragment,j),q(Z.$$.fragment,j),q(b.$$.fragment,j),J=!0)},o(j){I(M.$$.fragment,j),I(Z.$$.fragment,j),I(b.$$.fragment,j),J=!1},d(j){j&&a(r),j&&a(F),D(M,j),j&&a(z),j&&a(A),j&&a(fe),D(Z,j),j&&a(me),j&&a(le),j&&a(ge),D(b,j)}}}function tn(Q){let r,f;return r=new Os({props:{$$slots:{default:[an]},$$scope:{ctx:Q}}}),{c(){E(r.$$.fragment)},l(n){P(r.$$.fragment,n)},m(n,d){T(r,n,d),f=!0},p(n,d){const w={};d&2&&(w.$$scope={dirty:d,ctx:n}),r.$set(w)},i(n){f||(q(r.$$.fragment,n),f=!0)},o(n){I(r.$$.fragment,n),f=!1},d(n){D(r,n)}}}function ln(Q){let r,f,n,d,w,y,S,L,O,F,M,z,A,U,x,ne,C,X,v,H,B,V,G,N,ae,ue,te,he,ie,fe,Z,me,le,W,ce,_,K,re,_e,pe,ge;return x=new oe({props:{code:`import tensorflow as tf


def aug_transforms(image):
    image = tf.keras.utils.img_to_array(image)
    image = tf.image.random_brightness(image, 0.25)
    image = tf.image.random_contrast(image, 0.5, 2.0)
    image = tf.image.random_saturation(image, 0.75, 1.25)
    image = tf.image.random_hue(image, 0.1)
    image = tf.transpose(image, (2, 0, 1))
    return image


def transforms(image):
    image = tf.keras.utils.img_to_array(image)
    image = tf.transpose(image, (2, 0, 1))
    return image`,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`}}),me=new oe({props:{code:`def train_transforms(example_batch):
    images = [aug_transforms(x.convert("RGB")) for x in example_batch["image"]]
    labels = [x for x in example_batch["annotation"]]
    inputs = image_processor(images, labels)
    return inputs


def val_transforms(example_batch):
    images = [transforms(x.convert("RGB")) for x in example_batch["image"]]
    labels = [x for x in example_batch["annotation"]]
    inputs = image_processor(images, labels)
    return inputs`,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`}}),pe=new oe({props:{code:`train_ds.set_transform(train_transforms)
test_ds.set_transform(val_transforms)`,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(){r=o("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=o("a"),d=o("code"),w=t("tf.image"),y=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:`),S=u(),L=o("ul"),O=o("li"),F=t("training data transformations that include image augmentation"),M=u(),z=o("li"),A=t("validation data transformations that only transpose the images, since computer vision models in \u{1F917} Transformers expect channels-first layout"),U=u(),E(x.$$.fragment),ne=u(),C=o("p"),X=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 `),v=o("code"),H=t("image_processor"),B=t(" to convert the images into "),V=o("code"),G=t("pixel_values"),N=t(` and
annotations to `),ae=o("code"),ue=t("labels"),te=t(". "),he=o("code"),ie=t("ImageProcessor"),fe=t(" also takes care of resizing and normalizing the images."),Z=u(),E(me.$$.fragment),le=u(),W=o("p"),ce=t("To apply the preprocessing transformations over the entire dataset, use the \u{1F917} Datasets "),_=o("a"),K=t("set_transform"),re=t(` function.
The transform is applied on the fly which is faster and consumes less disk space:`),_e=u(),E(pe.$$.fragment),this.h()},l(b){r=i(b,"P",{});var J=p(r);f=l(J,`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=i(J,"A",{href:!0,rel:!0});var j=p(n);d=i(j,"CODE",{});var ee=p(d);w=l(ee,"tf.image"),ee.forEach(a),j.forEach(a),y=l(J,` to randomly change the color properties of an image, but you can also use any image
library you like.
Define two separate transformation functions:`),J.forEach(a),S=g(b),L=i(b,"UL",{});var $e=p(L);O=i($e,"LI",{});var be=p(O);F=l(be,"training data transformations that include image augmentation"),be.forEach(a),M=g($e),z=i($e,"LI",{});var De=p(z);A=l(De,"validation data transformations that only transpose the images, since computer vision models in \u{1F917} Transformers expect channels-first layout"),De.forEach(a),$e.forEach(a),U=g(b),P(x.$$.fragment,b),ne=g(b),C=i(b,"P",{});var Y=p(C);X=l(Y,`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 `),v=i(Y,"CODE",{});var Ce=p(v);H=l(Ce,"image_processor"),Ce.forEach(a),B=l(Y," to convert the images into "),V=i(Y,"CODE",{});var ve=p(V);G=l(ve,"pixel_values"),ve.forEach(a),N=l(Y,` and
annotations to `),ae=i(Y,"CODE",{});var qe=p(ae);ue=l(qe,"labels"),qe.forEach(a),te=l(Y,". "),he=i(Y,"CODE",{});var Pe=p(he);ie=l(Pe,"ImageProcessor"),Pe.forEach(a),fe=l(Y," also takes care of resizing and normalizing the images."),Y.forEach(a),Z=g(b),P(me.$$.fragment,b),le=g(b),W=i(b,"P",{});var ke=p(W);ce=l(ke,"To apply the preprocessing transformations over the entire dataset, use the \u{1F917} Datasets "),_=i(ke,"A",{href:!0,rel:!0});var xe=p(_);K=l(xe,"set_transform"),xe.forEach(a),re=l(ke,` function.
The transform is applied on the fly which is faster and consumes less disk space:`),ke.forEach(a),_e=g(b),P(pe.$$.fragment,b),this.h()},h(){$(n,"href","https://www.tensorflow.org/api_docs/python/tf/image"),$(n,"rel","nofollow"),$(_,"href","https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.set_transform"),$(_,"rel","nofollow")},m(b,J){m(b,r,J),s(r,f),s(r,n),s(n,d),s(d,w),s(r,y),m(b,S,J),m(b,L,J),s(L,O),s(O,F),s(L,M),s(L,z),s(z,A),m(b,U,J),T(x,b,J),m(b,ne,J),m(b,C,J),s(C,X),s(C,v),s(v,H),s(C,B),s(C,V),s(V,G),s(C,N),s(C,ae),s(ae,ue),s(C,te),s(C,he),s(he,ie),s(C,fe),m(b,Z,J),T(me,b,J),m(b,le,J),m(b,W,J),s(W,ce),s(W,_),s(_,K),s(W,re),m(b,_e,J),T(pe,b,J),ge=!0},p:ya,i(b){ge||(q(x.$$.fragment,b),q(me.$$.fragment,b),q(pe.$$.fragment,b),ge=!0)},o(b){I(x.$$.fragment,b),I(me.$$.fragment,b),I(pe.$$.fragment,b),ge=!1},d(b){b&&a(r),b&&a(S),b&&a(L),b&&a(U),D(x,b),b&&a(ne),b&&a(C),b&&a(Z),D(me,b),b&&a(le),b&&a(W),b&&a(_e),D(pe,b)}}}function nn(Q){let r,f;return r=new Os({props:{$$slots:{default:[ln]},$$scope:{ctx:Q}}}),{c(){E(r.$$.fragment)},l(n){P(r.$$.fragment,n)},m(n,d){T(r,n,d),f=!0},p(n,d){const w={};d&2&&(w.$$scope={dirty:d,ctx:n}),r.$set(w)},i(n){f||(q(r.$$.fragment,n),f=!0)},o(n){I(r.$$.fragment,n),f=!1},d(n){D(r,n)}}}function rn(Q){let r,f;return r=new oe({props:{code:`def compute_metrics(eval_pred):
    with torch.no_grad():
        logits, labels = eval_pred
        logits_tensor = torch.from_numpy(logits)
        logits_tensor = nn.functional.interpolate(
            logits_tensor,
            size=labels.shape[-2:],
            mode="bilinear",
            align_corners=False,
        ).argmax(dim=1)

        pred_labels = logits_tensor.detach().cpu().numpy()
        metrics = metric.compute(
            predictions=pred_labels,
            references=labels,
            num_labels=num_labels,
            ignore_index=255,
            reduce_labels=False,
        )
        for key, value in metrics.items():
            if type(value) is np.ndarray:
                metrics[key] = value.tolist()
        return metrics`,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>    <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(){E(r.$$.fragment)},l(n){P(r.$$.fragment,n)},m(n,d){T(r,n,d),f=!0},p:ya,i(n){f||(q(r.$$.fragment,n),f=!0)},o(n){I(r.$$.fragment,n),f=!1},d(n){D(r,n)}}}function on(Q){let r,f;return r=new Os({props:{$$slots:{default:[rn]},$$scope:{ctx:Q}}}),{c(){E(r.$$.fragment)},l(n){P(r.$$.fragment,n)},m(n,d){T(r,n,d),f=!0},p(n,d){const w={};d&2&&(w.$$scope={dirty:d,ctx:n}),r.$set(w)},i(n){f||(q(r.$$.fragment,n),f=!0)},o(n){I(r.$$.fragment,n),f=!1},d(n){D(r,n)}}}function pn(Q){let r,f;return r=new oe({props:{code:`def compute_metrics(eval_pred):
    logits, labels = eval_pred
    logits = tf.transpose(logits, perm=[0, 2, 3, 1])
    logits_resized = tf.image.resize(
        logits,
        size=tf.shape(labels)[1:],
        method="bilinear",
    )

    pred_labels = tf.argmax(logits_resized, axis=-1)
    metrics = metric.compute(
        predictions=pred_labels,
        references=labels,
        num_labels=num_labels,
        ignore_index=-1,
        reduce_labels=image_processor.do_reduce_labels,
    )

    per_category_accuracy = metrics.pop("per_category_accuracy").tolist()
    per_category_iou = metrics.pop("per_category_iou").tolist()

    metrics.update({f"accuracy_{id2label[i]}": v for i, v in enumerate(per_category_accuracy)})
    metrics.update({f"iou_{id2label[i]}": v for i, v in enumerate(per_category_iou)})
    return {"val_" + k: v for k, v in metrics.items()}`,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(){E(r.$$.fragment)},l(n){P(r.$$.fragment,n)},m(n,d){T(r,n,d),f=!0},p:ya,i(n){f||(q(r.$$.fragment,n),f=!0)},o(n){I(r.$$.fragment,n),f=!1},d(n){D(r,n)}}}function mn(Q){let r,f;return r=new Os({props:{$$slots:{default:[pn]},$$scope:{ctx:Q}}}),{c(){E(r.$$.fragment)},l(n){P(r.$$.fragment,n)},m(n,d){T(r,n,d),f=!0},p(n,d){const w={};d&2&&(w.$$scope={dirty:d,ctx:n}),r.$set(w)},i(n){f||(q(r.$$.fragment,n),f=!0)},o(n){I(r.$$.fragment,n),f=!1},d(n){D(r,n)}}}function cn(Q){let r,f,n,d,w,y,S,L;return{c(){r=o("p"),f=t("If you aren\u2019t familiar with finetuning a model with the "),n=o("a"),d=t("Trainer"),w=t(", take a look at the basic tutorial "),y=o("a"),S=t("here"),L=t("!"),this.h()},l(O){r=i(O,"P",{});var F=p(r);f=l(F,"If you aren\u2019t familiar with finetuning a model with the "),n=i(F,"A",{href:!0});var M=p(n);d=l(M,"Trainer"),M.forEach(a),w=l(F,", take a look at the basic tutorial "),y=i(F,"A",{href:!0});var z=p(y);S=l(z,"here"),z.forEach(a),L=l(F,"!"),F.forEach(a),this.h()},h(){$(n,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer"),$(y,"href","../training#finetune-with-trainer")},m(O,F){m(O,r,F),s(r,f),s(r,n),s(n,d),s(r,w),s(r,y),s(y,S),s(r,L)},d(O){O&&a(r)}}}function hn(Q){let r,f,n,d,w,y,S,L,O,F,M,z,A,U,x,ne,C,X,v,H,B,V,G,N,ae,ue,te,he,ie,fe,Z,me,le,W,ce,_,K,re,_e,pe,ge,b,J,j,ee,$e,be,De,Y,Ce,ve,qe,Pe,ke,xe,Ie,ye,je,we,Ne,Fe,as,Ye,Le,Oe,Me;return r=new el({props:{$$slots:{default:[cn]},$$scope:{ctx:Q}}}),O=new oe({props:{code:`from transformers import AutoModelForSemanticSegmentation, TrainingArguments, Trainer

model = AutoModelForSemanticSegmentation.from_pretrained(checkpoint, id2label=id2label, label2id=label2id)`,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)`}}),ye=new oe({props:{code:`training_args = TrainingArguments(
    output_dir="segformer-b0-scene-parse-150",
    learning_rate=6e-5,
    num_train_epochs=50,
    per_device_train_batch_size=2,
    per_device_eval_batch_size=2,
    save_total_limit=3,
    evaluation_strategy="steps",
    save_strategy="steps",
    save_steps=20,
    eval_steps=20,
    logging_steps=1,
    eval_accumulation_steps=5,
    remove_unused_columns=False,
    push_to_hub=True,
)

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=train_ds,
    eval_dataset=test_ds,
    compute_metrics=compute_metrics,
)

trainer.train()`,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()`}}),Oe=new oe({props:{code:"trainer.push_to_hub()",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()'}}),{c(){E(r.$$.fragment),f=u(),n=o("p"),d=t("You\u2019re ready to start training your model now! Load SegFormer with "),w=o("a"),y=t("AutoModelForSemanticSegmentation"),S=t(", and pass the model the mapping between label ids and label classes:"),L=u(),E(O.$$.fragment),F=u(),M=o("p"),z=t("At this point, only three steps remain:"),A=u(),U=o("ol"),x=o("li"),ne=t("Define your training hyperparameters in "),C=o("a"),X=t("TrainingArguments"),v=t(". It is important you don\u2019t remove unused columns because this\u2019ll drop the "),H=o("code"),B=t("image"),V=t(" column. Without the "),G=o("code"),N=t("image"),ae=t(" column, you can\u2019t create "),ue=o("code"),te=t("pixel_values"),he=t(". Set "),ie=o("code"),fe=t("remove_unused_columns=False"),Z=t(" to prevent this behavior! The only other required parameter is "),me=o("code"),le=t("output_dir"),W=t(" which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),ce=o("code"),_=t("push_to_hub=True"),K=t(" (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),re=o("a"),_e=t("Trainer"),pe=t(" will evaluate the IoU metric and save the training checkpoint."),ge=u(),b=o("li"),J=t("Pass the training arguments to "),j=o("a"),ee=t("Trainer"),$e=t(" along with the model, dataset, tokenizer, data collator, and "),be=o("code"),De=t("compute_metrics"),Y=t(" function."),Ce=u(),ve=o("li"),qe=t("Call "),Pe=o("a"),ke=t("train()"),xe=t(" to finetune your model."),Ie=u(),E(ye.$$.fragment),je=u(),we=o("p"),Ne=t("Once training is completed, share your model to the Hub with the "),Fe=o("a"),as=t("push_to_hub()"),Ye=t(" method so everyone can use your model:"),Le=u(),E(Oe.$$.fragment),this.h()},l(k){P(r.$$.fragment,k),f=g(k),n=i(k,"P",{});var se=p(n);d=l(se,"You\u2019re ready to start training your model now! Load SegFormer with "),w=i(se,"A",{href:!0});var Se=p(w);y=l(Se,"AutoModelForSemanticSegmentation"),Se.forEach(a),S=l(se,", and pass the model the mapping between label ids and label classes:"),se.forEach(a),L=g(k),P(O.$$.fragment,k),F=g(k),M=i(k,"P",{});var Ge=p(M);z=l(Ge,"At this point, only three steps remain:"),Ge.forEach(a),A=g(k),U=i(k,"OL",{});var He=p(U);x=i(He,"LI",{});var de=p(x);ne=l(de,"Define your training hyperparameters in "),C=i(de,"A",{href:!0});var ze=p(C);X=l(ze,"TrainingArguments"),ze.forEach(a),v=l(de,". It is important you don\u2019t remove unused columns because this\u2019ll drop the "),H=i(de,"CODE",{});var Qe=p(H);B=l(Qe,"image"),Qe.forEach(a),V=l(de," column. Without the "),G=i(de,"CODE",{});var Ee=p(G);N=l(Ee,"image"),Ee.forEach(a),ae=l(de," column, you can\u2019t create "),ue=i(de,"CODE",{});var Ke=p(ue);te=l(Ke,"pixel_values"),Ke.forEach(a),he=l(de,". Set "),ie=i(de,"CODE",{});var Be=p(ie);fe=l(Be,"remove_unused_columns=False"),Be.forEach(a),Z=l(de," to prevent this behavior! The only other required parameter is "),me=i(de,"CODE",{});var ns=p(me);le=l(ns,"output_dir"),ns.forEach(a),W=l(de," which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),ce=i(de,"CODE",{});var rs=p(ce);_=l(rs,"push_to_hub=True"),rs.forEach(a),K=l(de," (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),re=i(de,"A",{href:!0});var ts=p(re);_e=l(ts,"Trainer"),ts.forEach(a),pe=l(de," will evaluate the IoU metric and save the training checkpoint."),de.forEach(a),ge=g(He),b=i(He,"LI",{});var Te=p(b);J=l(Te,"Pass the training arguments to "),j=i(Te,"A",{href:!0});var Je=p(j);ee=l(Je,"Trainer"),Je.forEach(a),$e=l(Te," along with the model, dataset, tokenizer, data collator, and "),be=i(Te,"CODE",{});var Re=p(be);De=l(Re,"compute_metrics"),Re.forEach(a),Y=l(Te," function."),Te.forEach(a),Ce=g(He),ve=i(He,"LI",{});var Xe=p(ve);qe=l(Xe,"Call "),Pe=i(Xe,"A",{href:!0});var ls=p(Pe);ke=l(ls,"train()"),ls.forEach(a),xe=l(Xe," to finetune your model."),Xe.forEach(a),He.forEach(a),Ie=g(k),P(ye.$$.fragment,k),je=g(k),we=i(k,"P",{});var c=p(we);Ne=l(c,"Once training is completed, share your model to the Hub with the "),Fe=i(c,"A",{href:!0});var R=p(Fe);as=l(R,"push_to_hub()"),R.forEach(a),Ye=l(c," method so everyone can use your model:"),c.forEach(a),Le=g(k),P(Oe.$$.fragment,k),this.h()},h(){$(w,"href","/docs/transformers/main/en/model_doc/auto#transformers.AutoModelForSemanticSegmentation"),$(C,"href","/docs/transformers/main/en/main_classes/trainer#transformers.TrainingArguments"),$(re,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer"),$(j,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer"),$(Pe,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer.train"),$(Fe,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer.push_to_hub")},m(k,se){T(r,k,se),m(k,f,se),m(k,n,se),s(n,d),s(n,w),s(w,y),s(n,S),m(k,L,se),T(O,k,se),m(k,F,se),m(k,M,se),s(M,z),m(k,A,se),m(k,U,se),s(U,x),s(x,ne),s(x,C),s(C,X),s(x,v),s(x,H),s(H,B),s(x,V),s(x,G),s(G,N),s(x,ae),s(x,ue),s(ue,te),s(x,he),s(x,ie),s(ie,fe),s(x,Z),s(x,me),s(me,le),s(x,W),s(x,ce),s(ce,_),s(x,K),s(x,re),s(re,_e),s(x,pe),s(U,ge),s(U,b),s(b,J),s(b,j),s(j,ee),s(b,$e),s(b,be),s(be,De),s(b,Y),s(U,Ce),s(U,ve),s(ve,qe),s(ve,Pe),s(Pe,ke),s(ve,xe),m(k,Ie,se),T(ye,k,se),m(k,je,se),m(k,we,se),s(we,Ne),s(we,Fe),s(Fe,as),s(we,Ye),m(k,Le,se),T(Oe,k,se),Me=!0},p(k,se){const Se={};se&2&&(Se.$$scope={dirty:se,ctx:k}),r.$set(Se)},i(k){Me||(q(r.$$.fragment,k),q(O.$$.fragment,k),q(ye.$$.fragment,k),q(Oe.$$.fragment,k),Me=!0)},o(k){I(r.$$.fragment,k),I(O.$$.fragment,k),I(ye.$$.fragment,k),I(Oe.$$.fragment,k),Me=!1},d(k){D(r,k),k&&a(f),k&&a(n),k&&a(L),D(O,k),k&&a(F),k&&a(M),k&&a(A),k&&a(U),k&&a(Ie),D(ye,k),k&&a(je),k&&a(we),k&&a(Le),D(Oe,k)}}}function fn(Q){let r,f;return r=new Os({props:{$$slots:{default:[hn]},$$scope:{ctx:Q}}}),{c(){E(r.$$.fragment)},l(n){P(r.$$.fragment,n)},m(n,d){T(r,n,d),f=!0},p(n,d){const w={};d&2&&(w.$$scope={dirty:d,ctx:n}),r.$set(w)},i(n){f||(q(r.$$.fragment,n),f=!0)},o(n){I(r.$$.fragment,n),f=!1},d(n){D(r,n)}}}function un(Q){let r,f,n,d,w;return{c(){r=o("p"),f=t("If you are unfamiliar with fine-tuning a model with Keras, check out the "),n=o("a"),d=t("basic tutorial"),w=t(" first!"),this.h()},l(y){r=i(y,"P",{});var S=p(r);f=l(S,"If you are unfamiliar with fine-tuning a model with Keras, check out the "),n=i(S,"A",{href:!0});var L=p(n);d=l(L,"basic tutorial"),L.forEach(a),w=l(S," first!"),S.forEach(a),this.h()},h(){$(n,"href","./training#train-a-tensorflow-model-with-keras")},m(y,S){m(y,r,S),s(r,f),s(r,n),s(n,d),s(r,w)},d(y){y&&a(r)}}}function gn(Q){let r,f,n,d,w,y,S,L,O,F,M,z,A,U,x,ne,C,X,v,H,B,V,G,N,ae,ue,te,he,ie,fe,Z,me,le,W,ce,_,K,re,_e,pe,ge,b,J,j,ee,$e,be,De,Y,Ce,ve,qe,Pe,ke,xe,Ie,ye,je,we,Ne,Fe,as,Ye,Le,Oe,Me,k,se,Se,Ge,He,de,ze,Qe,Ee,Ke,Be,ns,rs,ts,Te,Je,Re,Xe,ls;return r=new el({props:{$$slots:{default:[un]},$$scope:{ctx:Q}}}),W=new oe({props:{code:`from transformers import create_optimizer

batch_size = 2
num_epochs = 50
num_train_steps = len(train_ds) * num_epochs
learning_rate = 6e-5
weight_decay_rate = 0.01

optimizer, lr_schedule = create_optimizer(
    init_lr=learning_rate,
    num_train_steps=num_train_steps,
    weight_decay_rate=weight_decay_rate,
    num_warmup_steps=0,
)`,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>)`}}),b=new oe({props:{code:`from transformers import TFAutoModelForSemanticSegmentation

model = TFAutoModelForSemanticSegmentation.from_pretrained(
    checkpoint,
    id2label=id2label,
    label2id=label2id,
)
model.compile(optimizer=optimizer)`,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)`}}),Ie=new oe({props:{code:`from transformers import DefaultDataCollator

data_collator = DefaultDataCollator(return_tensors="tf")

tf_train_dataset = train_ds.to_tf_dataset(
    columns=["pixel_values", "label"],
    shuffle=True,
    batch_size=batch_size,
    collate_fn=data_collator,
)

tf_eval_dataset = test_ds.to_tf_dataset(
    columns=["pixel_values", "label"],
    shuffle=True,
    batch_size=batch_size,
    collate_fn=data_collator,
)`,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>)`}}),ze=new oe({props:{code:`from transformers.keras_callbacks import KerasMetricCallback, PushToHubCallback

metric_callback = KerasMetricCallback(
    metric_fn=compute_metrics, eval_dataset=tf_eval_dataset, batch_size=batch_size, label_cols=["labels"]
)

push_to_hub_callback = PushToHubCallback(output_dir="scene_segmentation", tokenizer=image_processor)

callbacks = [metric_callback, push_to_hub_callback]`,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]`}}),Te=new oe({props:{code:`model.fit(
    tf_train_dataset,
    validation_data=tf_eval_dataset,
    callbacks=callbacks,
    epochs=num_epochs,
)`,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(){E(r.$$.fragment),f=u(),n=o("p"),d=t("To fine-tune a model in TensorFlow, follow these steps:"),w=u(),y=o("ol"),S=o("li"),L=t("Define the training hyperparameters, and set up an optimizer and a learning rate schedule."),O=u(),F=o("li"),M=t("Instantiate a pretrained model."),z=u(),A=o("li"),U=t("Convert a \u{1F917} Dataset to a "),x=o("code"),ne=t("tf.data.Dataset"),C=t("."),X=u(),v=o("li"),H=t("Compile your model."),B=u(),V=o("li"),G=t("Add callbacks to calculate metrics and upload your model to \u{1F917} Hub"),N=u(),ae=o("li"),ue=t("Use the "),te=o("code"),he=t("fit()"),ie=t(" method to run the training."),fe=u(),Z=o("p"),me=t("Start by defining the hyperparameters, optimizer and learning rate schedule:"),le=u(),E(W.$$.fragment),ce=u(),_=o("p"),K=t("Then, load SegFormer with "),re=o("a"),_e=t("TFAutoModelForSemanticSegmentation"),pe=t(` along with the label mappings, and compile it with the
optimizer:`),ge=u(),E(b.$$.fragment),J=u(),j=o("p"),ee=t("Convert your datasets to the "),$e=o("code"),be=t("tf.data.Dataset"),De=t(" format using the "),Y=o("a"),Ce=t("to_tf_dataset"),ve=t(" and the "),qe=o("a"),Pe=t("DefaultDataCollator"),ke=t(":"),xe=u(),E(Ie.$$.fragment),ye=u(),je=o("p"),we=t("To compute the accuracy from the predictions and push your model to the \u{1F917} Hub, use "),Ne=o("a"),Fe=t("Keras callbacks"),as=t(`.
Pass your `),Ye=o("code"),Le=t("compute_metrics"),Oe=t(" function to "),Me=o("a"),k=t("KerasMetricCallback"),se=t(`,
and use the `),Se=o("a"),Ge=t("PushToHubCallback"),He=t(" to upload the model:"),de=u(),E(ze.$$.fragment),Qe=u(),Ee=o("p"),Ke=t("Finally, you are ready to train your model! Call "),Be=o("code"),ns=t("fit()"),rs=t(` with your training and validation datasets, the number of epochs,
and your callbacks to fine-tune the model:`),ts=u(),E(Te.$$.fragment),Je=u(),Re=o("p"),Xe=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(c){P(r.$$.fragment,c),f=g(c),n=i(c,"P",{});var R=p(n);d=l(R,"To fine-tune a model in TensorFlow, follow these steps:"),R.forEach(a),w=g(c),y=i(c,"OL",{});var Ae=p(y);S=i(Ae,"LI",{});var ra=p(S);L=l(ra,"Define the training hyperparameters, and set up an optimizer and a learning rate schedule."),ra.forEach(a),O=g(Ae),F=i(Ae,"LI",{});var ds=p(F);M=l(ds,"Instantiate a pretrained model."),ds.forEach(a),z=g(Ae),A=i(Ae,"LI",{});var _s=p(A);U=l(_s,"Convert a \u{1F917} Dataset to a "),x=i(_s,"CODE",{});var oa=p(x);ne=l(oa,"tf.data.Dataset"),oa.forEach(a),C=l(_s,"."),_s.forEach(a),X=g(Ae),v=i(Ae,"LI",{});var $s=p(v);H=l($s,"Compile your model."),$s.forEach(a),B=g(Ae),V=i(Ae,"LI",{});var ia=p(V);G=l(ia,"Add callbacks to calculate metrics and upload your model to \u{1F917} Hub"),ia.forEach(a),N=g(Ae),ae=i(Ae,"LI",{});var bs=p(ae);ue=l(bs,"Use the "),te=i(bs,"CODE",{});var Ms=p(te);he=l(Ms,"fit()"),Ms.forEach(a),ie=l(bs," method to run the training."),bs.forEach(a),Ae.forEach(a),fe=g(c),Z=i(c,"P",{});var Ve=p(Z);me=l(Ve,"Start by defining the hyperparameters, optimizer and learning rate schedule:"),Ve.forEach(a),le=g(c),P(W.$$.fragment,c),ce=g(c),_=i(c,"P",{});var js=p(_);K=l(js,"Then, load SegFormer with "),re=i(js,"A",{href:!0});var vs=p(re);_e=l(vs,"TFAutoModelForSemanticSegmentation"),vs.forEach(a),pe=l(js,` along with the label mappings, and compile it with the
optimizer:`),js.forEach(a),ge=g(c),P(b.$$.fragment,c),J=g(c),j=i(c,"P",{});var Ze=p(j);ee=l(Ze,"Convert your datasets to the "),$e=i(Ze,"CODE",{});var pa=p($e);be=l(pa,"tf.data.Dataset"),pa.forEach(a),De=l(Ze," format using the "),Y=i(Ze,"A",{href:!0,rel:!0});var ys=p(Y);Ce=l(ys,"to_tf_dataset"),ys.forEach(a),ve=l(Ze," and the "),qe=i(Ze,"A",{href:!0});var ma=p(qe);Pe=l(ma,"DefaultDataCollator"),ma.forEach(a),ke=l(Ze,":"),Ze.forEach(a),xe=g(c),P(Ie.$$.fragment,c),ye=g(c),je=i(c,"P",{});var Ue=p(je);we=l(Ue,"To compute the accuracy from the predictions and push your model to the \u{1F917} Hub, use "),Ne=i(Ue,"A",{href:!0});var Ns=p(Ne);Fe=l(Ns,"Keras callbacks"),Ns.forEach(a),as=l(Ue,`.
Pass your `),Ye=i(Ue,"CODE",{});var os=p(Ye);Le=l(os,"compute_metrics"),os.forEach(a),Oe=l(Ue," function to "),Me=i(Ue,"A",{href:!0});var Hs=p(Me);k=l(Hs,"KerasMetricCallback"),Hs.forEach(a),se=l(Ue,`,
and use the `),Se=i(Ue,"A",{href:!0});var es=p(Se);Ge=l(es,"PushToHubCallback"),es.forEach(a),He=l(Ue," to upload the model:"),Ue.forEach(a),de=g(c),P(ze.$$.fragment,c),Qe=g(c),Ee=i(c,"P",{});var We=p(Ee);Ke=l(We,"Finally, you are ready to train your model! Call "),Be=i(We,"CODE",{});var ws=p(Be);ns=l(ws,"fit()"),ws.forEach(a),rs=l(We,` with your training and validation datasets, the number of epochs,
and your callbacks to fine-tune the model:`),We.forEach(a),ts=g(c),P(Te.$$.fragment,c),Je=g(c),Re=i(c,"P",{});var is=p(Re);Xe=l(is,"Congratulations! You have fine-tuned your model and shared it on the \u{1F917} Hub. You can now use it for inference!"),is.forEach(a),this.h()},h(){$(re,"href","/docs/transformers/main/en/model_doc/auto#transformers.TFAutoModelForSemanticSegmentation"),$(Y,"href","https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.to_tf_dataset"),$(Y,"rel","nofollow"),$(qe,"href","/docs/transformers/main/en/main_classes/data_collator#transformers.DefaultDataCollator"),$(Ne,"href","./main_classes/keras_callbacks"),$(Me,"href","/docs/transformers/main/en/main_classes/keras_callbacks#transformers.KerasMetricCallback"),$(Se,"href","/docs/transformers/main/en/main_classes/keras_callbacks#transformers.PushToHubCallback")},m(c,R){T(r,c,R),m(c,f,R),m(c,n,R),s(n,d),m(c,w,R),m(c,y,R),s(y,S),s(S,L),s(y,O),s(y,F),s(F,M),s(y,z),s(y,A),s(A,U),s(A,x),s(x,ne),s(A,C),s(y,X),s(y,v),s(v,H),s(y,B),s(y,V),s(V,G),s(y,N),s(y,ae),s(ae,ue),s(ae,te),s(te,he),s(ae,ie),m(c,fe,R),m(c,Z,R),s(Z,me),m(c,le,R),T(W,c,R),m(c,ce,R),m(c,_,R),s(_,K),s(_,re),s(re,_e),s(_,pe),m(c,ge,R),T(b,c,R),m(c,J,R),m(c,j,R),s(j,ee),s(j,$e),s($e,be),s(j,De),s(j,Y),s(Y,Ce),s(j,ve),s(j,qe),s(qe,Pe),s(j,ke),m(c,xe,R),T(Ie,c,R),m(c,ye,R),m(c,je,R),s(je,we),s(je,Ne),s(Ne,Fe),s(je,as),s(je,Ye),s(Ye,Le),s(je,Oe),s(je,Me),s(Me,k),s(je,se),s(je,Se),s(Se,Ge),s(je,He),m(c,de,R),T(ze,c,R),m(c,Qe,R),m(c,Ee,R),s(Ee,Ke),s(Ee,Be),s(Be,ns),s(Ee,rs),m(c,ts,R),T(Te,c,R),m(c,Je,R),m(c,Re,R),s(Re,Xe),ls=!0},p(c,R){const Ae={};R&2&&(Ae.$$scope={dirty:R,ctx:c}),r.$set(Ae)},i(c){ls||(q(r.$$.fragment,c),q(W.$$.fragment,c),q(b.$$.fragment,c),q(Ie.$$.fragment,c),q(ze.$$.fragment,c),q(Te.$$.fragment,c),ls=!0)},o(c){I(r.$$.fragment,c),I(W.$$.fragment,c),I(b.$$.fragment,c),I(Ie.$$.fragment,c),I(ze.$$.fragment,c),I(Te.$$.fragment,c),ls=!1},d(c){D(r,c),c&&a(f),c&&a(n),c&&a(w),c&&a(y),c&&a(fe),c&&a(Z),c&&a(le),D(W,c),c&&a(ce),c&&a(_),c&&a(ge),D(b,c),c&&a(J),c&&a(j),c&&a(xe),D(Ie,c),c&&a(ye),c&&a(je),c&&a(de),D(ze,c),c&&a(Qe),c&&a(Ee),c&&a(ts),D(Te,c),c&&a(Je),c&&a(Re)}}}function dn(Q){let r,f;return r=new Os({props:{$$slots:{default:[gn]},$$scope:{ctx:Q}}}),{c(){E(r.$$.fragment)},l(n){P(r.$$.fragment,n)},m(n,d){T(r,n,d),f=!0},p(n,d){const w={};d&2&&(w.$$scope={dirty:d,ctx:n}),r.$set(w)},i(n){f||(q(r.$$.fragment,n),f=!0)},o(n){I(r.$$.fragment,n),f=!1},d(n){D(r,n)}}}function _n(Q){let r,f,n,d,w,y,S,L,O,F,M,z,A,U,x,ne,C,X,v,H,B,V,G,N,ae,ue,te,he,ie,fe,Z,me,le,W,ce;return F=new oe({props:{code:`from transformers import pipeline

segmenter = pipeline("image-segmentation", model="my_awesome_seg_model")
segmenter(image)`,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;}]`}}),B=new oe({props:{code:`device = torch.device("cuda" if torch.cuda.is_available() else "cpu")  # use GPU if available, otherwise use a CPU
encoding = image_processor(image, return_tensors="pt")
pixel_values = encoding.pixel_values.to(device)`,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)`}}),ie=new oe({props:{code:`outputs = model(pixel_values=pixel_values)
logits = outputs.logits.cpu()`,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()`}}),W=new oe({props:{code:`upsampled_logits = nn.functional.interpolate(
    logits,
    size=image.size[::-1],
    mode="bilinear",
    align_corners=False,
)

pred_seg = upsampled_logits.argmax(dim=1)[0]`,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(){r=o("p"),f=t("The simplest way to try out your finetuned model for inference is to use it in a "),n=o("a"),d=t("pipeline()"),w=t(". Instantiate a "),y=o("code"),S=t("pipeline"),L=t(" for image segmentation with your model, and pass your image to it:"),O=u(),E(F.$$.fragment),M=u(),z=o("p"),A=t("You can also manually replicate the results of the "),U=o("code"),x=t("pipeline"),ne=t(" if you\u2019d like. Process the image with an image processor and place the "),C=o("code"),X=t("pixel_values"),v=t(" on a GPU:"),H=u(),E(B.$$.fragment),V=u(),G=o("p"),N=t("Pass your input to the model and return the "),ae=o("code"),ue=t("logits"),te=t(":"),he=u(),E(ie.$$.fragment),fe=u(),Z=o("p"),me=t("Next, rescale the logits to the original image size:"),le=u(),E(W.$$.fragment),this.h()},l(_){r=i(_,"P",{});var K=p(r);f=l(K,"The simplest way to try out your finetuned model for inference is to use it in a "),n=i(K,"A",{href:!0});var re=p(n);d=l(re,"pipeline()"),re.forEach(a),w=l(K,". Instantiate a "),y=i(K,"CODE",{});var _e=p(y);S=l(_e,"pipeline"),_e.forEach(a),L=l(K," for image segmentation with your model, and pass your image to it:"),K.forEach(a),O=g(_),P(F.$$.fragment,_),M=g(_),z=i(_,"P",{});var pe=p(z);A=l(pe,"You can also manually replicate the results of the "),U=i(pe,"CODE",{});var ge=p(U);x=l(ge,"pipeline"),ge.forEach(a),ne=l(pe," if you\u2019d like. Process the image with an image processor and place the "),C=i(pe,"CODE",{});var b=p(C);X=l(b,"pixel_values"),b.forEach(a),v=l(pe," on a GPU:"),pe.forEach(a),H=g(_),P(B.$$.fragment,_),V=g(_),G=i(_,"P",{});var J=p(G);N=l(J,"Pass your input to the model and return the "),ae=i(J,"CODE",{});var j=p(ae);ue=l(j,"logits"),j.forEach(a),te=l(J,":"),J.forEach(a),he=g(_),P(ie.$$.fragment,_),fe=g(_),Z=i(_,"P",{});var ee=p(Z);me=l(ee,"Next, rescale the logits to the original image size:"),ee.forEach(a),le=g(_),P(W.$$.fragment,_),this.h()},h(){$(n,"href","/docs/transformers/main/en/main_classes/pipelines#transformers.pipeline")},m(_,K){m(_,r,K),s(r,f),s(r,n),s(n,d),s(r,w),s(r,y),s(y,S),s(r,L),m(_,O,K),T(F,_,K),m(_,M,K),m(_,z,K),s(z,A),s(z,U),s(U,x),s(z,ne),s(z,C),s(C,X),s(z,v),m(_,H,K),T(B,_,K),m(_,V,K),m(_,G,K),s(G,N),s(G,ae),s(ae,ue),s(G,te),m(_,he,K),T(ie,_,K),m(_,fe,K),m(_,Z,K),s(Z,me),m(_,le,K),T(W,_,K),ce=!0},p:ya,i(_){ce||(q(F.$$.fragment,_),q(B.$$.fragment,_),q(ie.$$.fragment,_),q(W.$$.fragment,_),ce=!0)},o(_){I(F.$$.fragment,_),I(B.$$.fragment,_),I(ie.$$.fragment,_),I(W.$$.fragment,_),ce=!1},d(_){_&&a(r),_&&a(O),D(F,_),_&&a(M),_&&a(z),_&&a(H),D(B,_),_&&a(V),_&&a(G),_&&a(he),D(ie,_),_&&a(fe),_&&a(Z),_&&a(le),D(W,_)}}}function $n(Q){let r,f;return r=new Os({props:{$$slots:{default:[_n]},$$scope:{ctx:Q}}}),{c(){E(r.$$.fragment)},l(n){P(r.$$.fragment,n)},m(n,d){T(r,n,d),f=!0},p(n,d){const w={};d&2&&(w.$$scope={dirty:d,ctx:n}),r.$set(w)},i(n){f||(q(r.$$.fragment,n),f=!0)},o(n){I(r.$$.fragment,n),f=!1},d(n){D(r,n)}}}function bn(Q){let r,f,n,d,w,y,S,L,O,F,M,z,A,U,x,ne,C,X;return d=new oe({props:{code:`from transformers import AutoImageProcessor

image_processor = AutoImageProcessor.from_pretrained("MariaK/scene_segmentation")
inputs = image_processor(image, return_tensors="tf")`,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 oe({props:{code:`from transformers import TFAutoModelForSemanticSegmentation

model = TFAutoModelForSemanticSegmentation.from_pretrained("MariaK/scene_segmentation")
logits = model(**inputs).logits`,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`}}),C=new oe({props:{code:`logits = tf.transpose(logits, [0, 2, 3, 1])

upsampled_logits = tf.image.resize(
    logits,
    # We reverse the shape of \`image\` because \`image.size\` returns width and height.
    image.size[::-1],
)

pred_seg = tf.math.argmax(upsampled_logits, axis=-1)[0]`,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(){r=o("p"),f=t("Load an image processor to preprocess the image and return the input as TensorFlow tensors:"),n=u(),E(d.$$.fragment),w=u(),y=o("p"),S=t("Pass your input to the model and return the "),L=o("code"),O=t("logits"),F=t(":"),M=u(),E(z.$$.fragment),A=u(),U=o("p"),x=t("Next, rescale the logits to the original image size and apply argmax on the class dimension:"),ne=u(),E(C.$$.fragment)},l(v){r=i(v,"P",{});var H=p(r);f=l(H,"Load an image processor to preprocess the image and return the input as TensorFlow tensors:"),H.forEach(a),n=g(v),P(d.$$.fragment,v),w=g(v),y=i(v,"P",{});var B=p(y);S=l(B,"Pass your input to the model and return the "),L=i(B,"CODE",{});var V=p(L);O=l(V,"logits"),V.forEach(a),F=l(B,":"),B.forEach(a),M=g(v),P(z.$$.fragment,v),A=g(v),U=i(v,"P",{});var G=p(U);x=l(G,"Next, rescale the logits to the original image size and apply argmax on the class dimension:"),G.forEach(a),ne=g(v),P(C.$$.fragment,v)},m(v,H){m(v,r,H),s(r,f),m(v,n,H),T(d,v,H),m(v,w,H),m(v,y,H),s(y,S),s(y,L),s(L,O),s(y,F),m(v,M,H),T(z,v,H),m(v,A,H),m(v,U,H),s(U,x),m(v,ne,H),T(C,v,H),X=!0},p:ya,i(v){X||(q(d.$$.fragment,v),q(z.$$.fragment,v),q(C.$$.fragment,v),X=!0)},o(v){I(d.$$.fragment,v),I(z.$$.fragment,v),I(C.$$.fragment,v),X=!1},d(v){v&&a(r),v&&a(n),D(d,v),v&&a(w),v&&a(y),v&&a(M),D(z,v),v&&a(A),v&&a(U),v&&a(ne),D(C,v)}}}function jn(Q){let r,f;return r=new Os({props:{$$slots:{default:[bn]},$$scope:{ctx:Q}}}),{c(){E(r.$$.fragment)},l(n){P(r.$$.fragment,n)},m(n,d){T(r,n,d),f=!0},p(n,d){const w={};d&2&&(w.$$scope={dirty:d,ctx:n}),r.$set(w)},i(n){f||(q(r.$$.fragment,n),f=!0)},o(n){I(r.$$.fragment,n),f=!1},d(n){D(r,n)}}}function vn(Q){let r,f,n,d,w,y,S,L,O,F,M,z,A,U,x,ne,C,X,v,H,B,V,G,N,ae,ue,te,he,ie,fe,Z,me,le,W,ce,_,K,re,_e,pe,ge,b,J,j,ee,$e,be,De,Y,Ce,ve,qe,Pe,ke,xe,Ie,ye,je,we,Ne,Fe,as,Ye,Le,Oe,Me,k,se,Se,Ge,He,de,ze,Qe,Ee,Ke,Be,ns,rs,ts,Te,Je,Re,Xe,ls,c,R,Ae,ra,ds,_s,oa,$s,ia,bs,Ms,Ve,js,vs,Ze,pa,ys,ma,Ue,Ns,os,Hs,es,We,ws,is,_t,wa,$t,Na,ps,bt,ka,jt,vt,xa,yt,wt,Ha,Bs,Ba,ks,Ua,xs,Ya,hs,Es,Ea,Us,kt,Pa,xt,Ga,ss,Et,Ys,Pt,Tt,Gs,qt,It,Ks,Dt,At,Ka,Js,Ja,ms,zt,Rs,Ct,St,Vs,Ft,Lt,Ra,Ps,Va,Ts,Wa,qs,Ot,Ta,Mt,Nt,Qa,fs,Is,qa,Ws,Ht,Ia,Bt,Xa,Ds,Za,As,et,us,zs,Da,Qs,Ut,Aa,Yt,st,ca,Gt,at,ha,Kt,tt,Xs,lt,Zs,fa,sl,nt,Cs,rt,Ss,ot,cs,Jt,ea,Rt,Vt,za,Wt,Qt,it,sa,pt,aa,ua,al,mt;return y=new va({}),M=new en({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"}]}}),A=new Zl({props:{id:"dKE8SIt9C-w"}}),W=new el({props:{$$slots:{default:[sn]},$$scope:{ctx:Q}}}),_e=new oe({props:{code:"pip install -q datasets transformers evaluate",highlighted:"pip install -q datasets transformers evaluate"}}),j=new oe({props:{code:`from huggingface_hub import notebook_login

notebook_login()`,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()`}}),Y=new va({}),ye=new oe({props:{code:`from datasets import load_dataset

ds = load_dataset("scene_parse_150", split="train[:50]")`,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>)`}}),se=new oe({props:{code:`ds = ds.train_test_split(test_size=0.2)
train_ds = ds["train"]
test_ds = ds["test"]`,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>]`}}),ze=new oe({props:{code:"train_ds[0]",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>}`}}),os=new oe({props:{code:`import json
from huggingface_hub import cached_download, hf_hub_url

repo_id = "huggingface/label-files"
filename = "ade20k-hf-doc-builder.json"
id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r"))
id2label = {int(k): v for k, v in id2label.items()}
label2id = {v: k for k, v in id2label.items()}
num_labels = len(id2label)`,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)`}}),is=new va({}),Bs=new oe({props:{code:`from transformers import AutoImageProcessor

checkpoint = "nvidia/mit-b0"
image_processor = AutoImageProcessor.from_pretrained(checkpoint, reduce_labels=True)`,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>)`}}),ks=new Ls({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[tn]},$$scope:{ctx:Q}}}),xs=new Ls({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[nn]},$$scope:{ctx:Q}}}),Us=new va({}),Js=new oe({props:{code:`import evaluate

metric = evaluate.load("mean_iou")`,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>)`}}),Ps=new Ls({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[on]},$$scope:{ctx:Q}}}),Ts=new Ls({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[mn]},$$scope:{ctx:Q}}}),Ws=new va({}),Ds=new Ls({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[fn]},$$scope:{ctx:Q}}}),As=new Ls({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[dn]},$$scope:{ctx:Q}}}),Qs=new va({}),Xs=new oe({props:{code:`image = ds[0]["image"]
image`,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`}}),Cs=new Ls({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[$n]},$$scope:{ctx:Q}}}),Ss=new Ls({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[jn]},$$scope:{ctx:Q}}}),sa=new oe({props:{code:`import matplotlib.pyplot as plt
import numpy as np

color_seg = np.zeros((pred_seg.shape[0], pred_seg.shape[1], 3), dtype=np.uint8)
palette = np.array(ade_palette())
for label, color in enumerate(palette):
    color_seg[pred_seg == label, :] = color
color_seg = color_seg[..., ::-1]  # convert to BGR

img = np.array(image) * 0.5 + color_seg * 0.5  # plot the image with the segmentation map
img = img.astype(np.uint8)

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