import{s as Et,o as zt,n as Ts}from"../chunks/scheduler.9bc65507.js";import{S as Ht,i as Qt,g as h,s as r,u as y,A as St,h as f,f as e,c as i,j as S,v as g,y as J,k as N,o as E,a as t,w as M,d as b,t as j,x as w,m as At,n as qt}from"../chunks/index.78c82d43.js";import{T as ct}from"../chunks/Tip.87d55b76.js";import{Y as Lt}from"../chunks/Youtube.b19762b6.js";import{I as re}from"../chunks/IconCopyLink.bedaa44d.js";import{C as X}from"../chunks/CodeBlock.48618ec2.js";import{D as Pt}from"../chunks/DocNotebookDropdown.40f7599b.js";import{F as ie,M as ce}from"../chunks/Markdown.993b48ef.js";function Dt(x){let a,u,l='<a href="../model_doc/beit">BEiT</a>, <a href="../model_doc/bit">BiT</a>, <a href="../model_doc/convnext">ConvNeXT</a>, <a href="../model_doc/convnextv2">ConvNeXTV2</a>, <a href="../model_doc/cvt">CvT</a>, <a href="../model_doc/data2vec-vision">Data2VecVision</a>, <a href="../model_doc/deit">DeiT</a>, <a href="../model_doc/dinat">DiNAT</a>, <a href="../model_doc/dinov2">DINOv2</a>, <a href="../model_doc/efficientformer">EfficientFormer</a>, <a href="../model_doc/efficientnet">EfficientNet</a>, <a href="../model_doc/focalnet">FocalNet</a>, <a href="../model_doc/imagegpt">ImageGPT</a>, <a href="../model_doc/levit">LeViT</a>, <a href="../model_doc/mobilenet_v1">MobileNetV1</a>, <a href="../model_doc/mobilenet_v2">MobileNetV2</a>, <a href="../model_doc/mobilevit">MobileViT</a>, <a href="../model_doc/mobilevitv2">MobileViTV2</a>, <a href="../model_doc/nat">NAT</a>, <a href="../model_doc/perceiver">Perceiver</a>, <a href="../model_doc/poolformer">PoolFormer</a>, <a href="../model_doc/pvt">PVT</a>, <a href="../model_doc/regnet">RegNet</a>, <a href="../model_doc/resnet">ResNet</a>, <a href="../model_doc/segformer">SegFormer</a>, <a href="../model_doc/swiftformer">SwiftFormer</a>, <a href="../model_doc/swin">Swin Transformer</a>, <a href="../model_doc/swinv2">Swin Transformer V2</a>, <a href="../model_doc/van">VAN</a>, <a href="../model_doc/vit">ViT</a>, <a href="../model_doc/vit_hybrid">ViT Hybrid</a>, <a href="../model_doc/vit_msn">ViTMSN</a>';return{c(){a=At(`The task illustrated in this tutorial is supported by the following model architectures:

`),u=h("p"),u.innerHTML=l},l(m){a=qt(m,`The task illustrated in this tutorial is supported by the following model architectures:

`),u=f(m,"P",{"data-svelte-h":!0}),J(u)!=="svelte-6ce6f7"&&(u.innerHTML=l)},m(m,T){t(m,a,T),t(m,u,T)},p:Ts,d(m){m&&(e(a),e(u))}}}function Kt(x){let a,u='Apply some image transformations to the images to make the model more robust against overfitting. Here you’ll use torchvision’s <a href="https://pytorch.org/vision/stable/transforms.html" rel="nofollow"><code>transforms</code></a> module, but you can also use any image library you like.',l,m,T="Crop a random part of the image, resize it, and normalize it with the image mean and standard deviation:",U,R,I,C,Y="Then create a preprocessing function to apply the transforms and return the <code>pixel_values</code> - the inputs to the model - of the image:",Z,F,G,v,V='To apply the preprocessing function over the entire dataset, use 🤗 Datasets <a href="https://huggingface.co/docs/datasets/v2.14.5/en/package_reference/main_classes#datasets.Dataset.with_transform" rel="nofollow">with_transform</a> method. The transforms are applied on the fly when you load an element of the dataset:',o,_,H,W,z='Now create a batch of examples using <a href="/docs/transformers/v4.33.3/en/main_classes/data_collator#transformers.DefaultDataCollator">DefaultDataCollator</a>. Unlike other data collators in 🤗 Transformers, the <code>DefaultDataCollator</code> does not apply additional preprocessing such as padding.',p,$,Q;return R=new X({props:{code:"ZnJvbSUyMHRvcmNodmlzaW9uLnRyYW5zZm9ybXMlMjBpbXBvcnQlMjBSYW5kb21SZXNpemVkQ3JvcCUyQyUyMENvbXBvc2UlMkMlMjBOb3JtYWxpemUlMkMlMjBUb1RlbnNvciUwQSUwQW5vcm1hbGl6ZSUyMCUzRCUyME5vcm1hbGl6ZShtZWFuJTNEaW1hZ2VfcHJvY2Vzc29yLmltYWdlX21lYW4lMkMlMjBzdGQlM0RpbWFnZV9wcm9jZXNzb3IuaW1hZ2Vfc3RkKSUwQXNpemUlMjAlM0QlMjAoJTBBJTIwJTIwJTIwJTIwaW1hZ2VfcHJvY2Vzc29yLnNpemUlNUIlMjJzaG9ydGVzdF9lZGdlJTIyJTVEJTBBJTIwJTIwJTIwJTIwaWYlMjAlMjJzaG9ydGVzdF9lZGdlJTIyJTIwaW4lMjBpbWFnZV9wcm9jZXNzb3Iuc2l6ZSUwQSUyMCUyMCUyMCUyMGVsc2UlMjAoaW1hZ2VfcHJvY2Vzc29yLnNpemUlNUIlMjJoZWlnaHQlMjIlNUQlMkMlMjBpbWFnZV9wcm9jZXNzb3Iuc2l6ZSU1QiUyMndpZHRoJTIyJTVEKSUwQSklMEFfdHJhbnNmb3JtcyUyMCUzRCUyMENvbXBvc2UoJTVCUmFuZG9tUmVzaXplZENyb3Aoc2l6ZSklMkMlMjBUb1RlbnNvcigpJTJDJTIwbm9ybWFsaXplJTVEKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> torchvision.transforms <span class="hljs-keyword">import</span> RandomResizedCrop, Compose, Normalize, ToTensor

<span class="hljs-meta">&gt;&gt;&gt; </span>normalize = Normalize(mean=image_processor.image_mean, std=image_processor.image_std)
<span class="hljs-meta">&gt;&gt;&gt; </span>size = (
<span class="hljs-meta">... </span>    image_processor.size[<span class="hljs-string">&quot;shortest_edge&quot;</span>]
<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> <span class="hljs-string">&quot;shortest_edge&quot;</span> <span class="hljs-keyword">in</span> image_processor.size
<span class="hljs-meta">... </span>    <span class="hljs-keyword">else</span> (image_processor.size[<span class="hljs-string">&quot;height&quot;</span>], image_processor.size[<span class="hljs-string">&quot;width&quot;</span>])
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>_transforms = Compose([RandomResizedCrop(size), ToTensor(), normalize])`}}),F=new X({props:{code:"ZGVmJTIwdHJhbnNmb3JtcyhleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjBleGFtcGxlcyU1QiUyMnBpeGVsX3ZhbHVlcyUyMiU1RCUyMCUzRCUyMCU1Ql90cmFuc2Zvcm1zKGltZy5jb252ZXJ0KCUyMlJHQiUyMikpJTIwZm9yJTIwaW1nJTIwaW4lMjBleGFtcGxlcyU1QiUyMmltYWdlJTIyJTVEJTVEJTBBJTIwJTIwJTIwJTIwZGVsJTIwZXhhbXBsZXMlNUIlMjJpbWFnZSUyMiU1RCUwQSUyMCUyMCUyMCUyMHJldHVybiUyMGV4YW1wbGVz",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">transforms</span>(<span class="hljs-params">examples</span>):
<span class="hljs-meta">... </span>    examples[<span class="hljs-string">&quot;pixel_values&quot;</span>] = [_transforms(img.convert(<span class="hljs-string">&quot;RGB&quot;</span>)) <span class="hljs-keyword">for</span> img <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;image&quot;</span>]]
<span class="hljs-meta">... </span>    <span class="hljs-keyword">del</span> examples[<span class="hljs-string">&quot;image&quot;</span>]
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> examples`}}),_=new X({props:{code:"Zm9vZCUyMCUzRCUyMGZvb2Qud2l0aF90cmFuc2Zvcm0odHJhbnNmb3Jtcyk=",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>food = food.with_transform(transforms)'}}),$=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERlZmF1bHREYXRhQ29sbGF0b3IlMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGVmYXVsdERhdGFDb2xsYXRvcigp",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()`}}),{c(){a=h("p"),a.innerHTML=u,l=r(),m=h("p"),m.textContent=T,U=r(),y(R.$$.fragment),I=r(),C=h("p"),C.innerHTML=Y,Z=r(),y(F.$$.fragment),G=r(),v=h("p"),v.innerHTML=V,o=r(),y(_.$$.fragment),H=r(),W=h("p"),W.innerHTML=z,p=r(),y($.$$.fragment)},l(d){a=f(d,"P",{"data-svelte-h":!0}),J(a)!=="svelte-1h04qv0"&&(a.innerHTML=u),l=i(d),m=f(d,"P",{"data-svelte-h":!0}),J(m)!=="svelte-1ocztfo"&&(m.textContent=T),U=i(d),g(R.$$.fragment,d),I=i(d),C=f(d,"P",{"data-svelte-h":!0}),J(C)!=="svelte-q25jfj"&&(C.innerHTML=Y),Z=i(d),g(F.$$.fragment,d),G=i(d),v=f(d,"P",{"data-svelte-h":!0}),J(v)!=="svelte-ascyzf"&&(v.innerHTML=V),o=i(d),g(_.$$.fragment,d),H=i(d),W=f(d,"P",{"data-svelte-h":!0}),J(W)!=="svelte-1is77mk"&&(W.innerHTML=z),p=i(d),g($.$$.fragment,d)},m(d,B){t(d,a,B),t(d,l,B),t(d,m,B),t(d,U,B),M(R,d,B),t(d,I,B),t(d,C,B),t(d,Z,B),M(F,d,B),t(d,G,B),t(d,v,B),t(d,o,B),M(_,d,B),t(d,H,B),t(d,W,B),t(d,p,B),M($,d,B),Q=!0},p:Ts,i(d){Q||(b(R.$$.fragment,d),b(F.$$.fragment,d),b(_.$$.fragment,d),b($.$$.fragment,d),Q=!0)},o(d){j(R.$$.fragment,d),j(F.$$.fragment,d),j(_.$$.fragment,d),j($.$$.fragment,d),Q=!1},d(d){d&&(e(a),e(l),e(m),e(U),e(I),e(C),e(Z),e(G),e(v),e(o),e(H),e(W),e(p)),w(R,d),w(F,d),w(_,d),w($,d)}}}function Ot(x){let a,u;return a=new ce({props:{$$slots:{default:[Kt]},$$scope:{ctx:x}}}),{c(){y(a.$$.fragment)},l(l){g(a.$$.fragment,l)},m(l,m){M(a,l,m),u=!0},p(l,m){const T={};m&2&&(T.$$scope={dirty:m,ctx:l}),a.$set(T)},i(l){u||(b(a.$$.fragment,l),u=!0)},o(l){j(a.$$.fragment,l),u=!1},d(l){w(a,l)}}}function sa(x){let a,u=`To avoid overfitting and to make the model more robust, add some data augmentation to the training part of the dataset.
Here we use Keras preprocessing layers to define the transformations for the training data (includes data augmentation),
and transformations for the validation data (only center cropping, resizing and normalizing). You can use <code>tf.image</code>or
any other library you prefer.`,l,m,T,U,R="Next, create functions to apply appropriate transformations to a batch of images, instead of one image at a time.",I,C,Y,Z,F='Use 🤗 Datasets <a href="https://huggingface.co/docs/datasets/v2.14.5/en/package_reference/main_classes#datasets.Dataset.set_transform" rel="nofollow">set_transform</a> to apply the transformations on the fly:',G,v,V,o,_=`As a final preprocessing step, create a batch of examples using <code>DefaultDataCollator</code>. Unlike other data collators in 🤗 Transformers, the
<code>DefaultDataCollator</code> does not apply additional preprocessing, such as padding.`,H,W,z;return m=new X({props:{code:"ZnJvbSUyMHRlbnNvcmZsb3clMjBpbXBvcnQlMjBrZXJhcyUwQWZyb20lMjB0ZW5zb3JmbG93LmtlcmFzJTIwaW1wb3J0JTIwbGF5ZXJzJTBBJTBBc2l6ZSUyMCUzRCUyMChpbWFnZV9wcm9jZXNzb3Iuc2l6ZSU1QiUyMmhlaWdodCUyMiU1RCUyQyUyMGltYWdlX3Byb2Nlc3Nvci5zaXplJTVCJTIyd2lkdGglMjIlNUQpJTBBJTBBdHJhaW5fZGF0YV9hdWdtZW50YXRpb24lMjAlM0QlMjBrZXJhcy5TZXF1ZW50aWFsKCUwQSUyMCUyMCUyMCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxheWVycy5SYW5kb21Dcm9wKHNpemUlNUIwJTVEJTJDJTIwc2l6ZSU1QjElNUQpJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbGF5ZXJzLlJlc2NhbGluZyhzY2FsZSUzRDEuMCUyMCUyRiUyMDEyNy41JTJDJTIwb2Zmc2V0JTNELTEpJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbGF5ZXJzLlJhbmRvbUZsaXAoJTIyaG9yaXpvbnRhbCUyMiklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsYXllcnMuUmFuZG9tUm90YXRpb24oZmFjdG9yJTNEMC4wMiklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsYXllcnMuUmFuZG9tWm9vbShoZWlnaHRfZmFjdG9yJTNEMC4yJTJDJTIwd2lkdGhfZmFjdG9yJTNEMC4yKSUyQyUwQSUyMCUyMCUyMCUyMCU1RCUyQyUwQSUyMCUyMCUyMCUyMG5hbWUlM0QlMjJ0cmFpbl9kYXRhX2F1Z21lbnRhdGlvbiUyMiUyQyUwQSklMEElMEF2YWxfZGF0YV9hdWdtZW50YXRpb24lMjAlM0QlMjBrZXJhcy5TZXF1ZW50aWFsKCUwQSUyMCUyMCUyMCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxheWVycy5DZW50ZXJDcm9wKHNpemUlNUIwJTVEJTJDJTIwc2l6ZSU1QjElNUQpJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbGF5ZXJzLlJlc2NhbGluZyhzY2FsZSUzRDEuMCUyMCUyRiUyMDEyNy41JTJDJTIwb2Zmc2V0JTNELTEpJTJDJTBBJTIwJTIwJTIwJTIwJTVEJTJDJTBBJTIwJTIwJTIwJTIwbmFtZSUzRCUyMnZhbF9kYXRhX2F1Z21lbnRhdGlvbiUyMiUyQyUwQSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> tensorflow <span class="hljs-keyword">import</span> keras
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> tensorflow.keras <span class="hljs-keyword">import</span> layers

<span class="hljs-meta">&gt;&gt;&gt; </span>size = (image_processor.size[<span class="hljs-string">&quot;height&quot;</span>], image_processor.size[<span class="hljs-string">&quot;width&quot;</span>])

<span class="hljs-meta">&gt;&gt;&gt; </span>train_data_augmentation = keras.Sequential(
<span class="hljs-meta">... </span>    [
<span class="hljs-meta">... </span>        layers.RandomCrop(size[<span class="hljs-number">0</span>], size[<span class="hljs-number">1</span>]),
<span class="hljs-meta">... </span>        layers.Rescaling(scale=<span class="hljs-number">1.0</span> / <span class="hljs-number">127.5</span>, offset=-<span class="hljs-number">1</span>),
<span class="hljs-meta">... </span>        layers.RandomFlip(<span class="hljs-string">&quot;horizontal&quot;</span>),
<span class="hljs-meta">... </span>        layers.RandomRotation(factor=<span class="hljs-number">0.02</span>),
<span class="hljs-meta">... </span>        layers.RandomZoom(height_factor=<span class="hljs-number">0.2</span>, width_factor=<span class="hljs-number">0.2</span>),
<span class="hljs-meta">... </span>    ],
<span class="hljs-meta">... </span>    name=<span class="hljs-string">&quot;train_data_augmentation&quot;</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>val_data_augmentation = keras.Sequential(
<span class="hljs-meta">... </span>    [
<span class="hljs-meta">... </span>        layers.CenterCrop(size[<span class="hljs-number">0</span>], size[<span class="hljs-number">1</span>]),
<span class="hljs-meta">... </span>        layers.Rescaling(scale=<span class="hljs-number">1.0</span> / <span class="hljs-number">127.5</span>, offset=-<span class="hljs-number">1</span>),
<span class="hljs-meta">... </span>    ],
<span class="hljs-meta">... </span>    name=<span class="hljs-string">&quot;val_data_augmentation&quot;</span>,
<span class="hljs-meta">... </span>)`}}),C=new X({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBaW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwUElMJTIwaW1wb3J0JTIwSW1hZ2UlMEElMEElMEFkZWYlMjBjb252ZXJ0X3RvX3RmX3RlbnNvcihpbWFnZSUzQSUyMEltYWdlKSUzQSUwQSUyMCUyMCUyMCUyMG5wX2ltYWdlJTIwJTNEJTIwbnAuYXJyYXkoaW1hZ2UpJTBBJTIwJTIwJTIwJTIwdGZfaW1hZ2UlMjAlM0QlMjB0Zi5jb252ZXJ0X3RvX3RlbnNvcihucF9pbWFnZSklMEElMjAlMjAlMjAlMjAlMjMlMjAlNjBleHBhbmRfZGltcygpJTYwJTIwaXMlMjB1c2VkJTIwdG8lMjBhZGQlMjBhJTIwYmF0Y2glMjBkaW1lbnNpb24lMjBzaW5jZSUwQSUyMCUyMCUyMCUyMCUyMyUyMHRoZSUyMFRGJTIwYXVnbWVudGF0aW9uJTIwbGF5ZXJzJTIwb3BlcmF0ZXMlMjBvbiUyMGJhdGNoZWQlMjBpbnB1dHMuJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwdGYuZXhwYW5kX2RpbXModGZfaW1hZ2UlMkMlMjAwKSUwQSUwQSUwQWRlZiUyMHByZXByb2Nlc3NfdHJhaW4oZXhhbXBsZV9iYXRjaCklM0ElMEElMjAlMjAlMjAlMjAlMjIlMjIlMjJBcHBseSUyMHRyYWluX3RyYW5zZm9ybXMlMjBhY3Jvc3MlMjBhJTIwYmF0Y2guJTIyJTIyJTIyJTBBJTIwJTIwJTIwJTIwaW1hZ2VzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdHJhaW5fZGF0YV9hdWdtZW50YXRpb24oY29udmVydF90b190Zl90ZW5zb3IoaW1hZ2UuY29udmVydCglMjJSR0IlMjIpKSklMjBmb3IlMjBpbWFnZSUyMGluJTIwZXhhbXBsZV9iYXRjaCU1QiUyMmltYWdlJTIyJTVEJTBBJTIwJTIwJTIwJTIwJTVEJTBBJTIwJTIwJTIwJTIwZXhhbXBsZV9iYXRjaCU1QiUyMnBpeGVsX3ZhbHVlcyUyMiU1RCUyMCUzRCUyMCU1QnRmLnRyYW5zcG9zZSh0Zi5zcXVlZXplKGltYWdlKSklMjBmb3IlMjBpbWFnZSUyMGluJTIwaW1hZ2VzJTVEJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwZXhhbXBsZV9iYXRjaCUwQSUwQSUwQWRlZiUyMHByZXByb2Nlc3NfdmFsKGV4YW1wbGVfYmF0Y2gpJTNBJTBBJTIwJTIwJTIwJTIwJTIyJTIyJTIyQXBwbHklMjB2YWxfdHJhbnNmb3JtcyUyMGFjcm9zcyUyMGElMjBiYXRjaC4lMjIlMjIlMjIlMEElMjAlMjAlMjAlMjBpbWFnZXMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB2YWxfZGF0YV9hdWdtZW50YXRpb24oY29udmVydF90b190Zl90ZW5zb3IoaW1hZ2UuY29udmVydCglMjJSR0IlMjIpKSklMjBmb3IlMjBpbWFnZSUyMGluJTIwZXhhbXBsZV9iYXRjaCU1QiUyMmltYWdlJTIyJTVEJTBBJTIwJTIwJTIwJTIwJTVEJTBBJTIwJTIwJTIwJTIwZXhhbXBsZV9iYXRjaCU1QiUyMnBpeGVsX3ZhbHVlcyUyMiU1RCUyMCUzRCUyMCU1QnRmLnRyYW5zcG9zZSh0Zi5zcXVlZXplKGltYWdlKSklMjBmb3IlMjBpbWFnZSUyMGluJTIwaW1hZ2VzJTVEJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwZXhhbXBsZV9iYXRjaA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">convert_to_tf_tensor</span>(<span class="hljs-params">image: Image</span>):
<span class="hljs-meta">... </span>    np_image = np.array(image)
<span class="hljs-meta">... </span>    tf_image = tf.convert_to_tensor(np_image)
<span class="hljs-meta">... </span>    <span class="hljs-comment"># \`expand_dims()\` is used to add a batch dimension since</span>
<span class="hljs-meta">... </span>    <span class="hljs-comment"># the TF augmentation layers operates on batched inputs.</span>
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> tf.expand_dims(tf_image, <span class="hljs-number">0</span>)


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_train</span>(<span class="hljs-params">example_batch</span>):
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;&quot;&quot;Apply train_transforms across a batch.&quot;&quot;&quot;</span>
<span class="hljs-meta">... </span>    images = [
<span class="hljs-meta">... </span>        train_data_augmentation(convert_to_tf_tensor(image.convert(<span class="hljs-string">&quot;RGB&quot;</span>))) <span class="hljs-keyword">for</span> image <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;image&quot;</span>]
<span class="hljs-meta">... </span>    ]
<span class="hljs-meta">... </span>    example_batch[<span class="hljs-string">&quot;pixel_values&quot;</span>] = [tf.transpose(tf.squeeze(image)) <span class="hljs-keyword">for</span> image <span class="hljs-keyword">in</span> images]
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> example_batch


<span class="hljs-meta">... </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_val</span>(<span class="hljs-params">example_batch</span>):
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;&quot;&quot;Apply val_transforms across a batch.&quot;&quot;&quot;</span>
<span class="hljs-meta">... </span>    images = [
<span class="hljs-meta">... </span>        val_data_augmentation(convert_to_tf_tensor(image.convert(<span class="hljs-string">&quot;RGB&quot;</span>))) <span class="hljs-keyword">for</span> image <span class="hljs-keyword">in</span> example_batch[<span class="hljs-string">&quot;image&quot;</span>]
<span class="hljs-meta">... </span>    ]
<span class="hljs-meta">... </span>    example_batch[<span class="hljs-string">&quot;pixel_values&quot;</span>] = [tf.transpose(tf.squeeze(image)) <span class="hljs-keyword">for</span> image <span class="hljs-keyword">in</span> images]
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> example_batch`}}),v=new X({props:{code:"Zm9vZCU1QiUyMnRyYWluJTIyJTVELnNldF90cmFuc2Zvcm0ocHJlcHJvY2Vzc190cmFpbiklMEFmb29kJTVCJTIydGVzdCUyMiU1RC5zZXRfdHJhbnNmb3JtKHByZXByb2Nlc3NfdmFsKQ==",highlighted:`food[<span class="hljs-string">&quot;train&quot;</span>].set_transform(preprocess_train)
food[<span class="hljs-string">&quot;test&quot;</span>].set_transform(preprocess_val)`}}),W=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERlZmF1bHREYXRhQ29sbGF0b3IlMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGVmYXVsdERhdGFDb2xsYXRvcihyZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyKQ==",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>)`}}),{c(){a=h("p"),a.innerHTML=u,l=r(),y(m.$$.fragment),T=r(),U=h("p"),U.textContent=R,I=r(),y(C.$$.fragment),Y=r(),Z=h("p"),Z.innerHTML=F,G=r(),y(v.$$.fragment),V=r(),o=h("p"),o.innerHTML=_,H=r(),y(W.$$.fragment)},l(p){a=f(p,"P",{"data-svelte-h":!0}),J(a)!=="svelte-134vg0e"&&(a.innerHTML=u),l=i(p),g(m.$$.fragment,p),T=i(p),U=f(p,"P",{"data-svelte-h":!0}),J(U)!=="svelte-kdpfis"&&(U.textContent=R),I=i(p),g(C.$$.fragment,p),Y=i(p),Z=f(p,"P",{"data-svelte-h":!0}),J(Z)!=="svelte-nydvlb"&&(Z.innerHTML=F),G=i(p),g(v.$$.fragment,p),V=i(p),o=f(p,"P",{"data-svelte-h":!0}),J(o)!=="svelte-j9ih75"&&(o.innerHTML=_),H=i(p),g(W.$$.fragment,p)},m(p,$){t(p,a,$),t(p,l,$),M(m,p,$),t(p,T,$),t(p,U,$),t(p,I,$),M(C,p,$),t(p,Y,$),t(p,Z,$),t(p,G,$),M(v,p,$),t(p,V,$),t(p,o,$),t(p,H,$),M(W,p,$),z=!0},p:Ts,i(p){z||(b(m.$$.fragment,p),b(C.$$.fragment,p),b(v.$$.fragment,p),b(W.$$.fragment,p),z=!0)},o(p){j(m.$$.fragment,p),j(C.$$.fragment,p),j(v.$$.fragment,p),j(W.$$.fragment,p),z=!1},d(p){p&&(e(a),e(l),e(T),e(U),e(I),e(Y),e(Z),e(G),e(V),e(o),e(H)),w(m,p),w(C,p),w(v,p),w(W,p)}}}function ea(x){let a,u;return a=new ce({props:{$$slots:{default:[sa]},$$scope:{ctx:x}}}),{c(){y(a.$$.fragment)},l(l){g(a.$$.fragment,l)},m(l,m){M(a,l,m),u=!0},p(l,m){const T={};m&2&&(T.$$scope={dirty:m,ctx:l}),a.$set(T)},i(l){u||(b(a.$$.fragment,l),u=!0)},o(l){j(a.$$.fragment,l),u=!1},d(l){w(a,l)}}}function ta(x){let a,u='If you aren’t familiar with finetuning a model with the <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer">Trainer</a>, take a look at the basic tutorial <a href="../training#train-with-pytorch-trainer">here</a>!';return{c(){a=h("p"),a.innerHTML=u},l(l){a=f(l,"P",{"data-svelte-h":!0}),J(a)!=="svelte-1kww4sq"&&(a.innerHTML=u)},m(l,m){t(l,a,m)},p:Ts,d(l){l&&e(a)}}}function aa(x){let a,u,l,m='You’re ready to start training your model now! Load ViT with <a href="/docs/transformers/v4.33.3/en/model_doc/auto#transformers.AutoModelForImageClassification">AutoModelForImageClassification</a>. Specify the number of labels along with the number of expected labels, and the label mappings:',T,U,R,I,C="At this point, only three steps remain:",Y,Z,F='<li>Define your training hyperparameters in <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a>. It is important you don’t remove unused columns because that’ll drop the <code>image</code> column. Without the <code>image</code> column, you can’t create <code>pixel_values</code>. Set <code>remove_unused_columns=False</code> to prevent this behavior! The only other required parameter is <code>output_dir</code> which specifies where to save your model. You’ll push this model to the Hub by setting <code>push_to_hub=True</code> (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer">Trainer</a> will evaluate the accuracy and save the training checkpoint.</li> <li>Pass the training arguments to <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer">Trainer</a> along with the model, dataset, tokenizer, data collator, and <code>compute_metrics</code> function.</li> <li>Call <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer.train">train()</a> to finetune your model.</li>',G,v,V,o,_='Once training is completed, share your model to the Hub with the <a href="/docs/transformers/v4.33.3/en/main_classes/trainer#transformers.Trainer.push_to_hub">push_to_hub()</a> method so everyone can use your model:',H,W,z;return a=new ct({props:{$$slots:{default:[ta]},$$scope:{ctx:x}}}),U=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckltYWdlQ2xhc3NpZmljYXRpb24lMkMlMjBUcmFpbmluZ0FyZ3VtZW50cyUyQyUyMFRyYWluZXIlMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckltYWdlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMGNoZWNrcG9pbnQlMkMlMEElMjAlMjAlMjAlMjBudW1fbGFiZWxzJTNEbGVuKGxhYmVscyklMkMlMEElMjAlMjAlMjAlMjBpZDJsYWJlbCUzRGlkMmxhYmVsJTJDJTBBJTIwJTIwJTIwJTIwbGFiZWwyaWQlM0RsYWJlbDJpZCUyQyUwQSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForImageClassification, TrainingArguments, Trainer

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForImageClassification.from_pretrained(
<span class="hljs-meta">... </span>    checkpoint,
<span class="hljs-meta">... </span>    num_labels=<span class="hljs-built_in">len</span>(labels),
<span class="hljs-meta">... </span>    id2label=id2label,
<span class="hljs-meta">... </span>    label2id=label2id,
<span class="hljs-meta">... </span>)`}}),v=new X({props:{code:"dHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0QlMjJteV9hd2Vzb21lX2Zvb2RfbW9kZWwlMjIlMkMlMEElMjAlMjAlMjAlMjByZW1vdmVfdW51c2VkX2NvbHVtbnMlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMGV2YWx1YXRpb25fc3RyYXRlZ3klM0QlMjJlcG9jaCUyMiUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfc3RyYXRlZ3klM0QlMjJlcG9jaCUyMiUyQyUwQSUyMCUyMCUyMCUyMGxlYXJuaW5nX3JhdGUlM0Q1ZS01JTJDJTBBJTIwJTIwJTIwJTIwcGVyX2RldmljZV90cmFpbl9iYXRjaF9zaXplJTNEMTYlMkMlMEElMjAlMjAlMjAlMjBncmFkaWVudF9hY2N1bXVsYXRpb25fc3RlcHMlM0Q0JTJDJTBBJTIwJTIwJTIwJTIwcGVyX2RldmljZV9ldmFsX2JhdGNoX3NpemUlM0QxNiUyQyUwQSUyMCUyMCUyMCUyMG51bV90cmFpbl9lcG9jaHMlM0QzJTJDJTBBJTIwJTIwJTIwJTIwd2FybXVwX3JhdGlvJTNEMC4xJTJDJTBBJTIwJTIwJTIwJTIwbG9nZ2luZ19zdGVwcyUzRDEwJTJDJTBBJTIwJTIwJTIwJTIwbG9hZF9iZXN0X21vZGVsX2F0X2VuZCUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBtZXRyaWNfZm9yX2Jlc3RfbW9kZWwlM0QlMjJhY2N1cmFjeSUyMiUyQyUwQSUyMCUyMCUyMCUyMHB1c2hfdG9faHViJTNEVHJ1ZSUyQyUwQSklMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRHRyYWluaW5nX2FyZ3MlMkMlMEElMjAlMjAlMjAlMjBkYXRhX2NvbGxhdG9yJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0Rmb29kJTVCJTIydHJhaW4lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBldmFsX2RhdGFzZXQlM0Rmb29kJTVCJTIydGVzdCUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRGltYWdlX3Byb2Nlc3NvciUyQyUwQSUyMCUyMCUyMCUyMGNvbXB1dGVfbWV0cmljcyUzRGNvbXB1dGVfbWV0cmljcyUyQyUwQSklMEElMEF0cmFpbmVyLnRyYWluKCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;my_awesome_food_model&quot;</span>,
<span class="hljs-meta">... </span>    remove_unused_columns=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>    evaluation_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
<span class="hljs-meta">... </span>    save_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
<span class="hljs-meta">... </span>    learning_rate=<span class="hljs-number">5e-5</span>,
<span class="hljs-meta">... </span>    per_device_train_batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    gradient_accumulation_steps=<span class="hljs-number">4</span>,
<span class="hljs-meta">... </span>    per_device_eval_batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    num_train_epochs=<span class="hljs-number">3</span>,
<span class="hljs-meta">... </span>    warmup_ratio=<span class="hljs-number">0.1</span>,
<span class="hljs-meta">... </span>    logging_steps=<span class="hljs-number">10</span>,
<span class="hljs-meta">... </span>    load_best_model_at_end=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    metric_for_best_model=<span class="hljs-string">&quot;accuracy&quot;</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>    data_collator=data_collator,
<span class="hljs-meta">... </span>    train_dataset=food[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    eval_dataset=food[<span class="hljs-string">&quot;test&quot;</span>],
<span class="hljs-meta">... </span>    tokenizer=image_processor,
<span class="hljs-meta">... </span>    compute_metrics=compute_metrics,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()`}}),W=new X({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()'}}),{c(){y(a.$$.fragment),u=r(),l=h("p"),l.innerHTML=m,T=r(),y(U.$$.fragment),R=r(),I=h("p"),I.textContent=C,Y=r(),Z=h("ol"),Z.innerHTML=F,G=r(),y(v.$$.fragment),V=r(),o=h("p"),o.innerHTML=_,H=r(),y(W.$$.fragment)},l(p){g(a.$$.fragment,p),u=i(p),l=f(p,"P",{"data-svelte-h":!0}),J(l)!=="svelte-ryqo50"&&(l.innerHTML=m),T=i(p),g(U.$$.fragment,p),R=i(p),I=f(p,"P",{"data-svelte-h":!0}),J(I)!=="svelte-l42k0i"&&(I.textContent=C),Y=i(p),Z=f(p,"OL",{"data-svelte-h":!0}),J(Z)!=="svelte-65yakp"&&(Z.innerHTML=F),G=i(p),g(v.$$.fragment,p),V=i(p),o=f(p,"P",{"data-svelte-h":!0}),J(o)!=="svelte-158pnaw"&&(o.innerHTML=_),H=i(p),g(W.$$.fragment,p)},m(p,$){M(a,p,$),t(p,u,$),t(p,l,$),t(p,T,$),M(U,p,$),t(p,R,$),t(p,I,$),t(p,Y,$),t(p,Z,$),t(p,G,$),M(v,p,$),t(p,V,$),t(p,o,$),t(p,H,$),M(W,p,$),z=!0},p(p,$){const Q={};$&2&&(Q.$$scope={dirty:$,ctx:p}),a.$set(Q)},i(p){z||(b(a.$$.fragment,p),b(U.$$.fragment,p),b(v.$$.fragment,p),b(W.$$.fragment,p),z=!0)},o(p){j(a.$$.fragment,p),j(U.$$.fragment,p),j(v.$$.fragment,p),j(W.$$.fragment,p),z=!1},d(p){p&&(e(u),e(l),e(T),e(R),e(I),e(Y),e(Z),e(G),e(V),e(o),e(H)),w(a,p),w(U,p),w(v,p),w(W,p)}}}function la(x){let a,u;return a=new ce({props:{$$slots:{default:[aa]},$$scope:{ctx:x}}}),{c(){y(a.$$.fragment)},l(l){g(a.$$.fragment,l)},m(l,m){M(a,l,m),u=!0},p(l,m){const T={};m&2&&(T.$$scope={dirty:m,ctx:l}),a.$set(T)},i(l){u||(b(a.$$.fragment,l),u=!0)},o(l){j(a.$$.fragment,l),u=!1},d(l){w(a,l)}}}function na(x){let a,u='If you are unfamiliar with fine-tuning a model with Keras, check out the <a href="./training#train-a-tensorflow-model-with-keras">basic tutorial</a> first!';return{c(){a=h("p"),a.innerHTML=u},l(l){a=f(l,"P",{"data-svelte-h":!0}),J(a)!=="svelte-1egt5s9"&&(a.innerHTML=u)},m(l,m){t(l,a,m)},p:Ts,d(l){l&&e(a)}}}function pa(x){let a,u,l,m="To fine-tune a model in TensorFlow, follow these steps:",T,U,R="<li>Define the training hyperparameters, and set up an optimizer and a learning rate schedule.</li> <li>Instantiate a pre-trained model.</li> <li>Convert a 🤗 Dataset to a <code>tf.data.Dataset</code>.</li> <li>Compile your model.</li> <li>Add callbacks and use the <code>fit()</code> method to run the training.</li> <li>Upload your model to 🤗 Hub to share with the community.</li>",I,C,Y="Start by defining the hyperparameters, optimizer and learning rate schedule:",Z,F,G,v,V='Then, load ViT with <a href="/docs/transformers/v4.33.3/en/model_doc/auto#transformers.TFAutoModelForImageClassification">TFAutoModelForImageClassification</a> along with the label mappings:',o,_,H,W,z='Convert your datasets to the <code>tf.data.Dataset</code> format using the <a href="https://huggingface.co/docs/datasets/v2.14.5/en/package_reference/main_classes#datasets.Dataset.to_tf_dataset" rel="nofollow">to_tf_dataset</a> and your <code>data_collator</code>:',p,$,Q,d,B="Configure the model for training with <code>compile()</code>:",L,P,D,ls,$s=`To compute the accuracy from the predictions and push your model to the 🤗 Hub, use <a href="../main_classes/keras_callbacks">Keras callbacks</a>.
Pass your <code>compute_metrics</code> function to <a href="../main_classes/keras_callbacks#transformers.KerasMetricCallback">KerasMetricCallback</a>,
and use the <a href="../main_classes/keras_callbacks#transformers.PushToHubCallback">PushToHubCallback</a> to upload the model:`,K,O,ss,ns,Us=`Finally, you are ready to train your model! Call <code>fit()</code> with your training and validation datasets, the number of epochs,
and your callbacks to fine-tune the model:`,es,ts,q,A,cs="Congratulations! You have fine-tuned your model and shared it on the 🤗 Hub. You can now use it for inference!",as;return a=new ct({props:{$$slots:{default:[na]},$$scope:{ctx:x}}}),F=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEElMEFiYXRjaF9zaXplJTIwJTNEJTIwMTYlMEFudW1fZXBvY2hzJTIwJTNEJTIwNSUwQW51bV90cmFpbl9zdGVwcyUyMCUzRCUyMGxlbihmb29kJTVCJTIydHJhaW4lMjIlNUQpJTIwKiUyMG51bV9lcG9jaHMlMEFsZWFybmluZ19yYXRlJTIwJTNEJTIwM2UtNSUwQXdlaWdodF9kZWNheV9yYXRlJTIwJTNEJTIwMC4wMSUwQSUwQW9wdGltaXplciUyQyUyMGxyX3NjaGVkdWxlJTIwJTNEJTIwY3JlYXRlX29wdGltaXplciglMEElMjAlMjAlMjAlMjBpbml0X2xyJTNEbGVhcm5pbmdfcmF0ZSUyQyUwQSUyMCUyMCUyMCUyMG51bV90cmFpbl9zdGVwcyUzRG51bV90cmFpbl9zdGVwcyUyQyUwQSUyMCUyMCUyMCUyMHdlaWdodF9kZWNheV9yYXRlJTNEd2VpZ2h0X2RlY2F5X3JhdGUlMkMlMEElMjAlMjAlMjAlMjBudW1fd2FybXVwX3N0ZXBzJTNEMCUyQyUwQSk=",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">16</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_epochs = <span class="hljs-number">5</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_train_steps = <span class="hljs-built_in">len</span>(food[<span class="hljs-string">&quot;train&quot;</span>]) * num_epochs
<span class="hljs-meta">&gt;&gt;&gt; </span>learning_rate = <span class="hljs-number">3e-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>)`}}),_=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9ySW1hZ2VDbGFzc2lmaWNhdGlvbiUwQSUwQW1vZGVsJTIwJTNEJTIwVEZBdXRvTW9kZWxGb3JJbWFnZUNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBjaGVja3BvaW50JTJDJTBBJTIwJTIwJTIwJTIwaWQybGFiZWwlM0RpZDJsYWJlbCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsMmlkJTNEbGFiZWwyaWQlMkMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForImageClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForImageClassification.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>)`}}),$=new X({props:{code:"JTIzJTIwY29udmVydGluZyUyMG91ciUyMHRyYWluJTIwZGF0YXNldCUyMHRvJTIwdGYuZGF0YS5EYXRhc2V0JTBBdGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMGZvb2QlNUIlMjJ0cmFpbiUyMiU1RC50b190Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMGNvbHVtbnMlM0QlMjJwaXhlbF92YWx1ZXMlMjIlMkMlMjBsYWJlbF9jb2xzJTNEJTIybGFiZWwlMjIlMkMlMjBzaHVmZmxlJTNEVHJ1ZSUyQyUyMGJhdGNoX3NpemUlM0RiYXRjaF9zaXplJTJDJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMEEpJTBBJTBBJTIzJTIwY29udmVydGluZyUyMG91ciUyMHRlc3QlMjBkYXRhc2V0JTIwdG8lMjB0Zi5kYXRhLkRhdGFzZXQlMEF0Zl9ldmFsX2RhdGFzZXQlMjAlM0QlMjBmb29kJTVCJTIydGVzdCUyMiU1RC50b190Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMGNvbHVtbnMlM0QlMjJwaXhlbF92YWx1ZXMlMjIlMkMlMjBsYWJlbF9jb2xzJTNEJTIybGFiZWwlMjIlMkMlMjBzaHVmZmxlJTNEVHJ1ZSUyQyUyMGJhdGNoX3NpemUlM0RiYXRjaF9zaXplJTJDJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># converting our train dataset to tf.data.Dataset</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>tf_train_dataset = food[<span class="hljs-string">&quot;train&quot;</span>].to_tf_dataset(
<span class="hljs-meta">... </span>    columns=<span class="hljs-string">&quot;pixel_values&quot;</span>, label_cols=<span class="hljs-string">&quot;label&quot;</span>, shuffle=<span class="hljs-literal">True</span>, batch_size=batch_size, collate_fn=data_collator
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># converting our test dataset to tf.data.Dataset</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>tf_eval_dataset = food[<span class="hljs-string">&quot;test&quot;</span>].to_tf_dataset(
<span class="hljs-meta">... </span>    columns=<span class="hljs-string">&quot;pixel_values&quot;</span>, label_cols=<span class="hljs-string">&quot;label&quot;</span>, shuffle=<span class="hljs-literal">True</span>, batch_size=batch_size, collate_fn=data_collator
<span class="hljs-meta">... </span>)`}}),P=new X({props:{code:"ZnJvbSUyMHRlbnNvcmZsb3cua2VyYXMubG9zc2VzJTIwaW1wb3J0JTIwU3BhcnNlQ2F0ZWdvcmljYWxDcm9zc2VudHJvcHklMEElMEFsb3NzJTIwJTNEJTIwdGYua2VyYXMubG9zc2VzLlNwYXJzZUNhdGVnb3JpY2FsQ3Jvc3NlbnRyb3B5KGZyb21fbG9naXRzJTNEVHJ1ZSklMEFtb2RlbC5jb21waWxlKG9wdGltaXplciUzRG9wdGltaXplciUyQyUyMGxvc3MlM0Rsb3NzKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> tensorflow.keras.losses <span class="hljs-keyword">import</span> SparseCategoricalCrossentropy

<span class="hljs-meta">&gt;&gt;&gt; </span>loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=<span class="hljs-literal">True</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.<span class="hljs-built_in">compile</span>(optimizer=optimizer, loss=loss)`}}),O=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5rZXJhc19jYWxsYmFja3MlMjBpbXBvcnQlMjBLZXJhc01ldHJpY0NhbGxiYWNrJTJDJTIwUHVzaFRvSHViQ2FsbGJhY2slMEElMEFtZXRyaWNfY2FsbGJhY2slMjAlM0QlMjBLZXJhc01ldHJpY0NhbGxiYWNrKG1ldHJpY19mbiUzRGNvbXB1dGVfbWV0cmljcyUyQyUyMGV2YWxfZGF0YXNldCUzRHRmX2V2YWxfZGF0YXNldCklMEFwdXNoX3RvX2h1Yl9jYWxsYmFjayUyMCUzRCUyMFB1c2hUb0h1YkNhbGxiYWNrKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0QlMjJmb29kX2NsYXNzaWZpZXIlMjIlMkMlMEElMjAlMjAlMjAlMjB0b2tlbml6ZXIlM0RpbWFnZV9wcm9jZXNzb3IlMkMlMEElMjAlMjAlMjAlMjBzYXZlX3N0cmF0ZWd5JTNEJTIybm8lMjIlMkMlMEEpJTBBY2FsbGJhY2tzJTIwJTNEJTIwJTVCbWV0cmljX2NhbGxiYWNrJTJDJTIwcHVzaF90b19odWJfY2FsbGJhY2slNUQ=",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(metric_fn=compute_metrics, eval_dataset=tf_eval_dataset)
<span class="hljs-meta">&gt;&gt;&gt; </span>push_to_hub_callback = PushToHubCallback(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;food_classifier&quot;</span>,
<span class="hljs-meta">... </span>    tokenizer=image_processor,
<span class="hljs-meta">... </span>    save_strategy=<span class="hljs-string">&quot;no&quot;</span>,
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>callbacks = [metric_callback, push_to_hub_callback]`}}),ts=new X({props:{code:"bW9kZWwuZml0KHRmX3RyYWluX2RhdGFzZXQlMkMlMjB2YWxpZGF0aW9uX2RhdGElM0R0Zl9ldmFsX2RhdGFzZXQlMkMlMjBlcG9jaHMlM0RudW1fZXBvY2hzJTJDJTIwY2FsbGJhY2tzJTNEY2FsbGJhY2tzKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>model.fit(tf_train_dataset, validation_data=tf_eval_dataset, epochs=num_epochs, callbacks=callbacks)
Epoch <span class="hljs-number">1</span>/<span class="hljs-number">5</span>
<span class="hljs-number">250</span>/<span class="hljs-number">250</span> [==============================] - 313s 1s/step - loss: <span class="hljs-number">2.5623</span> - val_loss: <span class="hljs-number">1.4161</span> - accuracy: <span class="hljs-number">0.9290</span>
Epoch <span class="hljs-number">2</span>/<span class="hljs-number">5</span>
<span class="hljs-number">250</span>/<span class="hljs-number">250</span> [==============================] - 265s 1s/step - loss: <span class="hljs-number">0.9181</span> - val_loss: <span class="hljs-number">0.6808</span> - accuracy: <span class="hljs-number">0.9690</span>
Epoch <span class="hljs-number">3</span>/<span class="hljs-number">5</span>
<span class="hljs-number">250</span>/<span class="hljs-number">250</span> [==============================] - 252s 1s/step - loss: <span class="hljs-number">0.3910</span> - val_loss: <span class="hljs-number">0.4303</span> - accuracy: <span class="hljs-number">0.9820</span>
Epoch <span class="hljs-number">4</span>/<span class="hljs-number">5</span>
<span class="hljs-number">250</span>/<span class="hljs-number">250</span> [==============================] - 251s 1s/step - loss: <span class="hljs-number">0.2028</span> - val_loss: <span class="hljs-number">0.3191</span> - accuracy: <span class="hljs-number">0.9900</span>
Epoch <span class="hljs-number">5</span>/<span class="hljs-number">5</span>
<span class="hljs-number">250</span>/<span class="hljs-number">250</span> [==============================] - 238s 949ms/step - loss: <span class="hljs-number">0.1232</span> - val_loss: <span class="hljs-number">0.3259</span> - accuracy: <span class="hljs-number">0.9890</span>`}}),{c(){y(a.$$.fragment),u=r(),l=h("p"),l.textContent=m,T=r(),U=h("ol"),U.innerHTML=R,I=r(),C=h("p"),C.textContent=Y,Z=r(),y(F.$$.fragment),G=r(),v=h("p"),v.innerHTML=V,o=r(),y(_.$$.fragment),H=r(),W=h("p"),W.innerHTML=z,p=r(),y($.$$.fragment),Q=r(),d=h("p"),d.innerHTML=B,L=r(),y(P.$$.fragment),D=r(),ls=h("p"),ls.innerHTML=$s,K=r(),y(O.$$.fragment),ss=r(),ns=h("p"),ns.innerHTML=Us,es=r(),y(ts.$$.fragment),q=r(),A=h("p"),A.textContent=cs},l(c){g(a.$$.fragment,c),u=i(c),l=f(c,"P",{"data-svelte-h":!0}),J(l)!=="svelte-s07fxj"&&(l.textContent=m),T=i(c),U=f(c,"OL",{"data-svelte-h":!0}),J(U)!=="svelte-1psiqa4"&&(U.innerHTML=R),I=i(c),C=f(c,"P",{"data-svelte-h":!0}),J(C)!=="svelte-ccl3wn"&&(C.textContent=Y),Z=i(c),g(F.$$.fragment,c),G=i(c),v=f(c,"P",{"data-svelte-h":!0}),J(v)!=="svelte-1wq7du1"&&(v.innerHTML=V),o=i(c),g(_.$$.fragment,c),H=i(c),W=f(c,"P",{"data-svelte-h":!0}),J(W)!=="svelte-yzs0or"&&(W.innerHTML=z),p=i(c),g($.$$.fragment,c),Q=i(c),d=f(c,"P",{"data-svelte-h":!0}),J(d)!=="svelte-fhefbq"&&(d.innerHTML=B),L=i(c),g(P.$$.fragment,c),D=i(c),ls=f(c,"P",{"data-svelte-h":!0}),J(ls)!=="svelte-887qtl"&&(ls.innerHTML=$s),K=i(c),g(O.$$.fragment,c),ss=i(c),ns=f(c,"P",{"data-svelte-h":!0}),J(ns)!=="svelte-1occr1z"&&(ns.innerHTML=Us),es=i(c),g(ts.$$.fragment,c),q=i(c),A=f(c,"P",{"data-svelte-h":!0}),J(A)!=="svelte-1r99pbn"&&(A.textContent=cs)},m(c,k){M(a,c,k),t(c,u,k),t(c,l,k),t(c,T,k),t(c,U,k),t(c,I,k),t(c,C,k),t(c,Z,k),M(F,c,k),t(c,G,k),t(c,v,k),t(c,o,k),M(_,c,k),t(c,H,k),t(c,W,k),t(c,p,k),M($,c,k),t(c,Q,k),t(c,d,k),t(c,L,k),M(P,c,k),t(c,D,k),t(c,ls,k),t(c,K,k),M(O,c,k),t(c,ss,k),t(c,ns,k),t(c,es,k),M(ts,c,k),t(c,q,k),t(c,A,k),as=!0},p(c,k){const me={};k&2&&(me.$$scope={dirty:k,ctx:c}),a.$set(me)},i(c){as||(b(a.$$.fragment,c),b(F.$$.fragment,c),b(_.$$.fragment,c),b($.$$.fragment,c),b(P.$$.fragment,c),b(O.$$.fragment,c),b(ts.$$.fragment,c),as=!0)},o(c){j(a.$$.fragment,c),j(F.$$.fragment,c),j(_.$$.fragment,c),j($.$$.fragment,c),j(P.$$.fragment,c),j(O.$$.fragment,c),j(ts.$$.fragment,c),as=!1},d(c){c&&(e(u),e(l),e(T),e(U),e(I),e(C),e(Z),e(G),e(v),e(o),e(H),e(W),e(p),e(Q),e(d),e(L),e(D),e(ls),e(K),e(ss),e(ns),e(es),e(q),e(A)),w(a,c),w(F,c),w(_,c),w($,c),w(P,c),w(O,c),w(ts,c)}}}function oa(x){let a,u;return a=new ce({props:{$$slots:{default:[pa]},$$scope:{ctx:x}}}),{c(){y(a.$$.fragment)},l(l){g(a.$$.fragment,l)},m(l,m){M(a,l,m),u=!0},p(l,m){const T={};m&2&&(T.$$scope={dirty:m,ctx:l}),a.$set(T)},i(l){u||(b(a.$$.fragment,l),u=!0)},o(l){j(a.$$.fragment,l),u=!1},d(l){w(a,l)}}}function ra(x){let a,u='For a more in-depth example of how to finetune a model for image classification, take a look at the corresponding <a href="https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/image_classification.ipynb" rel="nofollow">PyTorch notebook</a>.';return{c(){a=h("p"),a.innerHTML=u},l(l){a=f(l,"P",{"data-svelte-h":!0}),J(a)!=="svelte-1gyicmz"&&(a.innerHTML=u)},m(l,m){t(l,a,m)},p:Ts,d(l){l&&e(a)}}}function ia(x){let a,u="Load an image processor to preprocess the image and return the <code>input</code> as PyTorch tensors:",l,m,T,U,R="Pass your inputs to the model and return the logits:",I,C,Y,Z,F="Get the predicted label with the highest probability, and use the model’s <code>id2label</code> mapping to convert it to a label:",G,v,V;return m=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUwQWltcG9ydCUyMHRvcmNoJTBBJTBBaW1hZ2VfcHJvY2Vzc29yJTIwJTNEJTIwQXV0b0ltYWdlUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCglMjJteV9hd2Vzb21lX2Zvb2RfbW9kZWwlMjIpJTBBaW5wdXRzJTIwJTNEJTIwaW1hZ2VfcHJvY2Vzc29yKGltYWdlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMik=",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><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;my_awesome_food_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = image_processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)`}}),C=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckltYWdlQ2xhc3NpZmljYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckltYWdlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMm15X2F3ZXNvbWVfZm9vZF9tb2RlbCUyMiklMEF3aXRoJTIwdG9yY2gubm9fZ3JhZCgpJTNBJTBBJTIwJTIwJTIwJTIwbG9naXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMpLmxvZ2l0cw==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForImageClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForImageClassification.from_pretrained(<span class="hljs-string">&quot;my_awesome_food_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    logits = model(**inputs).logits`}}),v=new X({props:{code:"cHJlZGljdGVkX2xhYmVsJTIwJTNEJTIwbG9naXRzLmFyZ21heCgtMSkuaXRlbSgpJTBBbW9kZWwuY29uZmlnLmlkMmxhYmVsJTVCcHJlZGljdGVkX2xhYmVsJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_label = logits.argmax(-<span class="hljs-number">1</span>).item()
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.id2label[predicted_label]
<span class="hljs-string">&#x27;beignets&#x27;</span>`}}),{c(){a=h("p"),a.innerHTML=u,l=r(),y(m.$$.fragment),T=r(),U=h("p"),U.textContent=R,I=r(),y(C.$$.fragment),Y=r(),Z=h("p"),Z.innerHTML=F,G=r(),y(v.$$.fragment)},l(o){a=f(o,"P",{"data-svelte-h":!0}),J(a)!=="svelte-65kh0h"&&(a.innerHTML=u),l=i(o),g(m.$$.fragment,o),T=i(o),U=f(o,"P",{"data-svelte-h":!0}),J(U)!=="svelte-1at92g"&&(U.textContent=R),I=i(o),g(C.$$.fragment,o),Y=i(o),Z=f(o,"P",{"data-svelte-h":!0}),J(Z)!=="svelte-uvq5m0"&&(Z.innerHTML=F),G=i(o),g(v.$$.fragment,o)},m(o,_){t(o,a,_),t(o,l,_),M(m,o,_),t(o,T,_),t(o,U,_),t(o,I,_),M(C,o,_),t(o,Y,_),t(o,Z,_),t(o,G,_),M(v,o,_),V=!0},p:Ts,i(o){V||(b(m.$$.fragment,o),b(C.$$.fragment,o),b(v.$$.fragment,o),V=!0)},o(o){j(m.$$.fragment,o),j(C.$$.fragment,o),j(v.$$.fragment,o),V=!1},d(o){o&&(e(a),e(l),e(T),e(U),e(I),e(Y),e(Z),e(G)),w(m,o),w(C,o),w(v,o)}}}function ca(x){let a,u;return a=new ce({props:{$$slots:{default:[ia]},$$scope:{ctx:x}}}),{c(){y(a.$$.fragment)},l(l){g(a.$$.fragment,l)},m(l,m){M(a,l,m),u=!0},p(l,m){const T={};m&2&&(T.$$scope={dirty:m,ctx:l}),a.$set(T)},i(l){u||(b(a.$$.fragment,l),u=!0)},o(l){j(a.$$.fragment,l),u=!1},d(l){w(a,l)}}}function ma(x){let a,u="Load an image processor to preprocess the image and return the <code>input</code> as TensorFlow tensors:",l,m,T,U,R="Pass your inputs to the model and return the logits:",I,C,Y,Z,F="Get the predicted label with the highest probability, and use the model’s <code>id2label</code> mapping to convert it to a label:",G,v,V;return m=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUwQSUwQWltYWdlX3Byb2Nlc3NvciUyMCUzRCUyMEF1dG9JbWFnZVByb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoJTIyTWFyaWFLJTJGZm9vZF9jbGFzc2lmaWVyJTIyKSUwQWlucHV0cyUyMCUzRCUyMGltYWdlX3Byb2Nlc3NvcihpbWFnZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIydGYlMjIp",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/food_classifier&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = image_processor(image, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`}}),C=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9ySW1hZ2VDbGFzc2lmaWNhdGlvbiUwQSUwQW1vZGVsJTIwJTNEJTIwVEZBdXRvTW9kZWxGb3JJbWFnZUNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMjJNYXJpYUslMkZmb29kX2NsYXNzaWZpZXIlMjIpJTBBbG9naXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMpLmxvZ2l0cw==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForImageClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForImageClassification.from_pretrained(<span class="hljs-string">&quot;MariaK/food_classifier&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>logits = model(**inputs).logits`}}),v=new X({props:{code:"cHJlZGljdGVkX2NsYXNzX2lkJTIwJTNEJTIwaW50KHRmLm1hdGguYXJnbWF4KGxvZ2l0cyUyQyUyMGF4aXMlM0QtMSklNUIwJTVEKSUwQW1vZGVsLmNvbmZpZy5pZDJsYWJlbCU1QnByZWRpY3RlZF9jbGFzc19pZCU1RA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_class_id = <span class="hljs-built_in">int</span>(tf.math.argmax(logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.id2label[predicted_class_id]
<span class="hljs-string">&#x27;beignets&#x27;</span>`}}),{c(){a=h("p"),a.innerHTML=u,l=r(),y(m.$$.fragment),T=r(),U=h("p"),U.textContent=R,I=r(),y(C.$$.fragment),Y=r(),Z=h("p"),Z.innerHTML=F,G=r(),y(v.$$.fragment)},l(o){a=f(o,"P",{"data-svelte-h":!0}),J(a)!=="svelte-1l61n0d"&&(a.innerHTML=u),l=i(o),g(m.$$.fragment,o),T=i(o),U=f(o,"P",{"data-svelte-h":!0}),J(U)!=="svelte-1at92g"&&(U.textContent=R),I=i(o),g(C.$$.fragment,o),Y=i(o),Z=f(o,"P",{"data-svelte-h":!0}),J(Z)!=="svelte-uvq5m0"&&(Z.innerHTML=F),G=i(o),g(v.$$.fragment,o)},m(o,_){t(o,a,_),t(o,l,_),M(m,o,_),t(o,T,_),t(o,U,_),t(o,I,_),M(C,o,_),t(o,Y,_),t(o,Z,_),t(o,G,_),M(v,o,_),V=!0},p:Ts,i(o){V||(b(m.$$.fragment,o),b(C.$$.fragment,o),b(v.$$.fragment,o),V=!0)},o(o){j(m.$$.fragment,o),j(C.$$.fragment,o),j(v.$$.fragment,o),V=!1},d(o){o&&(e(a),e(l),e(T),e(U),e(I),e(Y),e(Z),e(G)),w(m,o),w(C,o),w(v,o)}}}function ha(x){let a,u;return a=new ce({props:{$$slots:{default:[ma]},$$scope:{ctx:x}}}),{c(){y(a.$$.fragment)},l(l){g(a.$$.fragment,l)},m(l,m){M(a,l,m),u=!0},p(l,m){const T={};m&2&&(T.$$scope={dirty:m,ctx:l}),a.$set(T)},i(l){u||(b(a.$$.fragment,l),u=!0)},o(l){j(a.$$.fragment,l),u=!1},d(l){w(a,l)}}}function fa(x){let a,u,l,m,T,U,R,I,C,Y,Z="Image classification",F,G,v,V,o,_,H=`Image classification assigns a label or class to an image. Unlike text or audio classification, the inputs are the
pixel values that comprise an image. There are many applications for image classification, such as detecting damage
after a natural disaster, monitoring crop health, or helping screen medical images for signs of disease.`,W,z,p="This guide illustrates how to:",$,Q,d='<li>Fine-tune <a href="model_doc/vit">ViT</a> on the <a href="https://huggingface.co/datasets/food101" rel="nofollow">Food-101</a> dataset to classify a food item in an image.</li> <li>Use your fine-tuned model for inference.</li>',B,L,P,D,ls="Before you begin, make sure you have all the necessary libraries installed:",$s,K,O,ss,ns="We encourage you to log in to your Hugging Face account to upload and share your model with the community. When prompted, enter your token to log in:",Us,es,ts,q,A,cs,as,c,k,me="Load Food-101 dataset",Je,_s,dt=`Start by loading a smaller subset of the Food-101 dataset from the 🤗 Datasets library. This will give you a chance to
experiment and make sure everything works before spending more time training on the full dataset.`,Te,vs,$e,Cs,yt='Split the dataset’s <code>train</code> split into a train and test set with the <a href="https://huggingface.co/docs/datasets/v2.14.5/en/package_reference/main_classes#datasets.Dataset.train_test_split" rel="nofollow">train_test_split</a> method:',Ue,Zs,_e,ks,gt="Then take a look at an example:",ve,Is,Ce,Gs,Mt="Each example in the dataset has two fields:",Ze,Ws,bt="<li><code>image</code>: a PIL image of the food item</li> <li><code>label</code>: the label class of the food item</li>",ke,Xs,jt=`To make it easier for the model to get the label name from the label id, create a dictionary that maps the label name
to an integer and vice versa:`,Ie,xs,Ge,Vs,wt="Now you can convert the label id to a label name:",We,Ys,Xe,ps,ms,he,Fs,mt,le,Jt="Preprocess",xe,Rs,Tt="The next step is to load a ViT image processor to process the image into a tensor:",Ve,Ns,Ye,hs,Fe,fs,Re,os,us,fe,Bs,ht,ne,$t="Evaluate",Ne,Es,Ut=`Including a metric during training is often helpful for evaluating your model’s performance. You can quickly load an
evaluation method with the 🤗 <a href="https://huggingface.co/docs/evaluate/index" rel="nofollow">Evaluate</a> library. For this task, load
the <a href="https://huggingface.co/spaces/evaluate-metric/accuracy" rel="nofollow">accuracy</a> metric (see the 🤗 Evaluate <a href="https://huggingface.co/docs/evaluate/a_quick_tour" rel="nofollow">quick tour</a> to learn more about how to load and compute a metric):`,Be,zs,Ee,Hs,_t='Then create a function that passes your predictions and labels to <a href="https://huggingface.co/docs/evaluate/v0.4.0/en/package_reference/main_classes#evaluate.EvaluationModule.compute" rel="nofollow">compute</a> to calculate the accuracy:',ze,Qs,He,Ss,vt="Your <code>compute_metrics</code> function is ready to go now, and you’ll return to it when you set up your training.",Qe,rs,ds,ue,As,ft,pe,Ct="Train",Se,ys,Ae,gs,qe,Ms,Le,is,bs,de,qs,ut,oe,Zt="Inference",Pe,Ls,kt="Great, now that you’ve fine-tuned a model, you can use it for inference!",De,Ps,It="Load an image you’d like to run inference on:",Ke,Ds,Oe,js,Gt='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png" alt="image of beignets"/>',st,Ks,Wt='The simplest way to try out your finetuned model for inference is to use it in a <a href="/docs/transformers/v4.33.3/en/main_classes/pipelines#transformers.pipeline">pipeline()</a>. Instantiate a <code>pipeline</code> for image classification with your model, and pass your image to it:',et,Os,tt,se,Xt="You can also manually replicate the results of the <code>pipeline</code> if you’d like:",at,ws,lt,Js,nt,ye,pt;return I=new re({}),G=new Pt({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/image_classification.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/image_classification.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/image_classification.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/image_classification.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/image_classification.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/image_classification.ipynb"}]}}),V=new Lt({props:{id:"tjAIM7BOYhw"}}),L=new ct({props:{$$slots:{default:[Dt]},$$scope:{ctx:x}}}),K=new X({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRyYW5zZm9ybWVycyUyMGRhdGFzZXRzJTIwZXZhbHVhdGU=",highlighted:"pip install transformers datasets evaluate"}}),es=new X({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

<span class="hljs-meta">&gt;&gt;&gt; </span>notebook_login()`}}),as=new re({}),vs=new X({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBZm9vZCUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJmb29kMTAxJTIyJTJDJTIwc3BsaXQlM0QlMjJ0cmFpbiU1QiUzQTUwMDAlNUQlMjIp",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>food = load_dataset(<span class="hljs-string">&quot;food101&quot;</span>, split=<span class="hljs-string">&quot;train[:5000]&quot;</span>)`}}),Zs=new X({props:{code:"Zm9vZCUyMCUzRCUyMGZvb2QudHJhaW5fdGVzdF9zcGxpdCh0ZXN0X3NpemUlM0QwLjIp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>food = food.train_test_split(test_size=<span class="hljs-number">0.2</span>)'}}),Is=new X({props:{code:"Zm9vZCU1QiUyMnRyYWluJTIyJTVEJTVCMCU1RA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>food[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]
{<span class="hljs-string">&#x27;image&#x27;</span>: &lt;PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=512x512 at <span class="hljs-number">0x7F52AFC8AC50</span>&gt;,
 <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-number">79</span>}`}}),xs=new X({props:{code:"bGFiZWxzJTIwJTNEJTIwZm9vZCU1QiUyMnRyYWluJTIyJTVELmZlYXR1cmVzJTVCJTIybGFiZWwlMjIlNUQubmFtZXMlMEFsYWJlbDJpZCUyQyUyMGlkMmxhYmVsJTIwJTNEJTIwZGljdCgpJTJDJTIwZGljdCgpJTBBZm9yJTIwaSUyQyUyMGxhYmVsJTIwaW4lMjBlbnVtZXJhdGUobGFiZWxzKSUzQSUwQSUyMCUyMCUyMCUyMGxhYmVsMmlkJTVCbGFiZWwlNUQlMjAlM0QlMjBzdHIoaSklMEElMjAlMjAlMjAlMjBpZDJsYWJlbCU1QnN0cihpKSU1RCUyMCUzRCUyMGxhYmVs",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>labels = food[<span class="hljs-string">&quot;train&quot;</span>].features[<span class="hljs-string">&quot;label&quot;</span>].names
<span class="hljs-meta">&gt;&gt;&gt; </span>label2id, id2label = <span class="hljs-built_in">dict</span>(), <span class="hljs-built_in">dict</span>()
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> i, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(labels):
<span class="hljs-meta">... </span>    label2id[label] = <span class="hljs-built_in">str</span>(i)
<span class="hljs-meta">... </span>    id2label[<span class="hljs-built_in">str</span>(i)] = label`}}),Ys=new X({props:{code:"aWQybGFiZWwlNUJzdHIoNzkpJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>id2label[<span class="hljs-built_in">str</span>(<span class="hljs-number">79</span>)]
<span class="hljs-string">&#x27;prime_rib&#x27;</span>`}}),Fs=new re({}),Ns=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJnb29nbGUlMkZ2aXQtYmFzZS1wYXRjaDE2LTIyNC1pbjIxayUyMiUwQWltYWdlX3Byb2Nlc3NvciUyMCUzRCUyMEF1dG9JbWFnZVByb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCk=",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;google/vit-base-patch16-224-in21k&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(checkpoint)`}}),hs=new ie({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[Ot]},$$scope:{ctx:x}}}),fs=new ie({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[ea]},$$scope:{ctx:x}}}),Bs=new re({}),zs=new X({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFhY2N1cmFjeSUyMCUzRCUyMGV2YWx1YXRlLmxvYWQoJTIyYWNjdXJhY3klMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> evaluate

<span class="hljs-meta">&gt;&gt;&gt; </span>accuracy = evaluate.load(<span class="hljs-string">&quot;accuracy&quot;</span>)`}}),Qs=new X({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTBBZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZCklM0ElMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUyQyUyMGxhYmVscyUyMCUzRCUyMGV2YWxfcHJlZCUwQSUyMCUyMCUyMCUyMHByZWRpY3Rpb25zJTIwJTNEJTIwbnAuYXJnbWF4KHByZWRpY3Rpb25zJTJDJTIwYXhpcyUzRDEpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwYWNjdXJhY3kuY29tcHV0ZShwcmVkaWN0aW9ucyUzRHByZWRpY3Rpb25zJTJDJTIwcmVmZXJlbmNlcyUzRGxhYmVscyk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_pred</span>):
<span class="hljs-meta">... </span>    predictions, labels = eval_pred
<span class="hljs-meta">... </span>    predictions = np.argmax(predictions, axis=<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> accuracy.compute(predictions=predictions, references=labels)`}}),As=new re({}),ys=new ie({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[la]},$$scope:{ctx:x}}}),gs=new ie({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[oa]},$$scope:{ctx:x}}}),Ms=new ct({props:{$$slots:{default:[ra]},$$scope:{ctx:x}}}),qs=new re({}),Ds=new X({props:{code:"ZHMlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIyZm9vZDEwMSUyMiUyQyUyMHNwbGl0JTNEJTIydmFsaWRhdGlvbiU1QiUzQTEwJTVEJTIyKSUwQWltYWdlJTIwJTNEJTIwZHMlNUIlMjJpbWFnZSUyMiU1RCU1QjAlNUQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>ds = load_dataset(<span class="hljs-string">&quot;food101&quot;</span>, split=<span class="hljs-string">&quot;validation[:10]&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>image = ds[<span class="hljs-string">&quot;image&quot;</span>][<span class="hljs-number">0</span>]`}}),Os=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBY2xhc3NpZmllciUyMCUzRCUyMHBpcGVsaW5lKCUyMmltYWdlLWNsYXNzaWZpY2F0aW9uJTIyJTJDJTIwbW9kZWwlM0QlMjJteV9hd2Vzb21lX2Zvb2RfbW9kZWwlMjIpJTBBY2xhc3NpZmllcihpbWFnZSk=",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>classifier = pipeline(<span class="hljs-string">&quot;image-classification&quot;</span>, model=<span class="hljs-string">&quot;my_awesome_food_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>classifier(image)
[{<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.31856709718704224</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;beignets&#x27;</span>},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.015232225880026817</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;bruschetta&#x27;</span>},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.01519392803311348</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;chicken_wings&#x27;</span>},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.013022331520915031</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;pork_chop&#x27;</span>},
 {<span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.012728818692266941</span>, <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;prime_rib&#x27;</span>}]`}}),ws=new ie({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[ca]},$$scope:{ctx:x}}}),Js=new ie({props:{pytorch:!1,tensorflow:!0,jax:!1,$$slots:{tensorflow:[ha]},$$scope:{ctx:x}}}),{c(){a=h("meta"),u=r(),l=h("p"),m=r(),T=h("h1"),U=h("a"),R=h("span"),y(I.$$.fragment),C=r(),Y=h("span"),Y.textContent=Z,F=r(),y(G.$$.fragment),v=r(),y(V.$$.fragment),o=r(),_=h("p"),_.textContent=H,W=r(),z=h("p"),z.textContent=p,$=r(),Q=h("ol"),Q.innerHTML=d,B=r(),y(L.$$.fragment),P=r(),D=h("p"),D.textContent=ls,$s=r(),y(K.$$.fragment),O=r(),ss=h("p"),ss.textContent=ns,Us=r(),y(es.$$.fragment),ts=r(),q=h("h2"),A=h("a"),cs=h("span"),y(as.$$.fragment),c=r(),k=h("span"),k.textContent=me,Je=r(),_s=h("p"),_s.textContent=dt,Te=r(),y(vs.$$.fragment),$e=r(),Cs=h("p"),Cs.innerHTML=yt,Ue=r(),y(Zs.$$.fragment),_e=r(),ks=h("p"),ks.textContent=gt,ve=r(),y(Is.$$.fragment),Ce=r(),Gs=h("p"),Gs.textContent=Mt,Ze=r(),Ws=h("ul"),Ws.innerHTML=bt,ke=r(),Xs=h("p"),Xs.textContent=jt,Ie=r(),y(xs.$$.fragment),Ge=r(),Vs=h("p"),Vs.textContent=wt,We=r(),y(Ys.$$.fragment),Xe=r(),ps=h("h2"),ms=h("a"),he=h("span"),y(Fs.$$.fragment),mt=r(),le=h("span"),le.textContent=Jt,xe=r(),Rs=h("p"),Rs.textContent=Tt,Ve=r(),y(Ns.$$.fragment),Ye=r(),y(hs.$$.fragment),Fe=r(),y(fs.$$.fragment),Re=r(),os=h("h2"),us=h("a"),fe=h("span"),y(Bs.$$.fragment),ht=r(),ne=h("span"),ne.textContent=$t,Ne=r(),Es=h("p"),Es.innerHTML=Ut,Be=r(),y(zs.$$.fragment),Ee=r(),Hs=h("p"),Hs.innerHTML=_t,ze=r(),y(Qs.$$.fragment),He=r(),Ss=h("p"),Ss.innerHTML=vt,Qe=r(),rs=h("h2"),ds=h("a"),ue=h("span"),y(As.$$.fragment),ft=r(),pe=h("span"),pe.textContent=Ct,Se=r(),y(ys.$$.fragment),Ae=r(),y(gs.$$.fragment),qe=r(),y(Ms.$$.fragment),Le=r(),is=h("h2"),bs=h("a"),de=h("span"),y(qs.$$.fragment),ut=r(),oe=h("span"),oe.textContent=Zt,Pe=r(),Ls=h("p"),Ls.textContent=kt,De=r(),Ps=h("p"),Ps.textContent=It,Ke=r(),y(Ds.$$.fragment),Oe=r(),js=h("div"),js.innerHTML=Gt,st=r(),Ks=h("p"),Ks.innerHTML=Wt,et=r(),y(Os.$$.fragment),tt=r(),se=h("p"),se.innerHTML=Xt,at=r(),y(ws.$$.fragment),lt=r(),y(Js.$$.fragment),nt=r(),ye=h("p"),this.h()},l(s){const n=St("svelte-1phssyn",document.head);a=f(n,"META",{name:!0,content:!0}),n.forEach(e),u=i(s),l=f(s,"P",{}),S(l).forEach(e),m=i(s),T=f(s,"H1",{class:!0});var ee=S(T);U=f(ee,"A",{id:!0,class:!0,href:!0});var ge=S(U);R=f(ge,"SPAN",{});var Me=S(R);g(I.$$.fragment,Me),Me.forEach(e),ge.forEach(e),C=i(ee),Y=f(ee,"SPAN",{"data-svelte-h":!0}),J(Y)!=="svelte-1cn7k7s"&&(Y.textContent=Z),ee.forEach(e),F=i(s),g(G.$$.fragment,s),v=i(s),g(V.$$.fragment,s),o=i(s),_=f(s,"P",{"data-svelte-h":!0}),J(_)!=="svelte-dpadt7"&&(_.textContent=H),W=i(s),z=f(s,"P",{"data-svelte-h":!0}),J(z)!=="svelte-ku8orh"&&(z.textContent=p),$=i(s),Q=f(s,"OL",{"data-svelte-h":!0}),J(Q)!=="svelte-1j1nbn7"&&(Q.innerHTML=d),B=i(s),g(L.$$.fragment,s),P=i(s),D=f(s,"P",{"data-svelte-h":!0}),J(D)!=="svelte-1c9nexd"&&(D.textContent=ls),$s=i(s),g(K.$$.fragment,s),O=i(s),ss=f(s,"P",{"data-svelte-h":!0}),J(ss)!=="svelte-yib87s"&&(ss.textContent=ns),Us=i(s),g(es.$$.fragment,s),ts=i(s),q=f(s,"H2",{class:!0});var te=S(q);A=f(te,"A",{id:!0,class:!0,href:!0});var be=S(A);cs=f(be,"SPAN",{});var je=S(cs);g(as.$$.fragment,je),je.forEach(e),be.forEach(e),c=i(te),k=f(te,"SPAN",{"data-svelte-h":!0}),J(k)!=="svelte-tl19vq"&&(k.textContent=me),te.forEach(e),Je=i(s),_s=f(s,"P",{"data-svelte-h":!0}),J(_s)!=="svelte-1cr1dw1"&&(_s.textContent=dt),Te=i(s),g(vs.$$.fragment,s),$e=i(s),Cs=f(s,"P",{"data-svelte-h":!0}),J(Cs)!=="svelte-1izknij"&&(Cs.innerHTML=yt),Ue=i(s),g(Zs.$$.fragment,s),_e=i(s),ks=f(s,"P",{"data-svelte-h":!0}),J(ks)!=="svelte-1m91ua0"&&(ks.textContent=gt),ve=i(s),g(Is.$$.fragment,s),Ce=i(s),Gs=f(s,"P",{"data-svelte-h":!0}),J(Gs)!=="svelte-w87shu"&&(Gs.textContent=Mt),Ze=i(s),Ws=f(s,"UL",{"data-svelte-h":!0}),J(Ws)!=="svelte-133so41"&&(Ws.innerHTML=bt),ke=i(s),Xs=f(s,"P",{"data-svelte-h":!0}),J(Xs)!=="svelte-1j34ajz"&&(Xs.textContent=jt),Ie=i(s),g(xs.$$.fragment,s),Ge=i(s),Vs=f(s,"P",{"data-svelte-h":!0}),J(Vs)!=="svelte-1e9n4a3"&&(Vs.textContent=wt),We=i(s),g(Ys.$$.fragment,s),Xe=i(s),ps=f(s,"H2",{class:!0});var ae=S(ps);ms=f(ae,"A",{id:!0,class:!0,href:!0});var we=S(ms);he=f(we,"SPAN",{});var xt=S(he);g(Fs.$$.fragment,xt),xt.forEach(e),we.forEach(e),mt=i(ae),le=f(ae,"SPAN",{"data-svelte-h":!0}),J(le)!=="svelte-1cg9qj"&&(le.textContent=Jt),ae.forEach(e),xe=i(s),Rs=f(s,"P",{"data-svelte-h":!0}),J(Rs)!=="svelte-25xdfm"&&(Rs.textContent=Tt),Ve=i(s),g(Ns.$$.fragment,s),Ye=i(s),g(hs.$$.fragment,s),Fe=i(s),g(fs.$$.fragment,s),Re=i(s),os=f(s,"H2",{class:!0});var ot=S(os);us=f(ot,"A",{id:!0,class:!0,href:!0});var Vt=S(us);fe=f(Vt,"SPAN",{});var Yt=S(fe);g(Bs.$$.fragment,Yt),Yt.forEach(e),Vt.forEach(e),ht=i(ot),ne=f(ot,"SPAN",{"data-svelte-h":!0}),J(ne)!=="svelte-sh8s6s"&&(ne.textContent=$t),ot.forEach(e),Ne=i(s),Es=f(s,"P",{"data-svelte-h":!0}),J(Es)!=="svelte-1qqtfp"&&(Es.innerHTML=Ut),Be=i(s),g(zs.$$.fragment,s),Ee=i(s),Hs=f(s,"P",{"data-svelte-h":!0}),J(Hs)!=="svelte-14oy2j6"&&(Hs.innerHTML=_t),ze=i(s),g(Qs.$$.fragment,s),He=i(s),Ss=f(s,"P",{"data-svelte-h":!0}),J(Ss)!=="svelte-44vib3"&&(Ss.innerHTML=vt),Qe=i(s),rs=f(s,"H2",{class:!0});var rt=S(rs);ds=f(rt,"A",{id:!0,class:!0,href:!0});var Ft=S(ds);ue=f(Ft,"SPAN",{});var Rt=S(ue);g(As.$$.fragment,Rt),Rt.forEach(e),Ft.forEach(e),ft=i(rt),pe=f(rt,"SPAN",{"data-svelte-h":!0}),J(pe)!=="svelte-5arm0l"&&(pe.textContent=Ct),rt.forEach(e),Se=i(s),g(ys.$$.fragment,s),Ae=i(s),g(gs.$$.fragment,s),qe=i(s),g(Ms.$$.fragment,s),Le=i(s),is=f(s,"H2",{class:!0});var it=S(is);bs=f(it,"A",{id:!0,class:!0,href:!0});var Nt=S(bs);de=f(Nt,"SPAN",{});var Bt=S(de);g(qs.$$.fragment,Bt),Bt.forEach(e),Nt.forEach(e),ut=i(it),oe=f(it,"SPAN",{"data-svelte-h":!0}),J(oe)!=="svelte-199uz7g"&&(oe.textContent=Zt),it.forEach(e),Pe=i(s),Ls=f(s,"P",{"data-svelte-h":!0}),J(Ls)!=="svelte-l3g61e"&&(Ls.textContent=kt),De=i(s),Ps=f(s,"P",{"data-svelte-h":!0}),J(Ps)!=="svelte-1jlr7r7"&&(Ps.textContent=It),Ke=i(s),g(Ds.$$.fragment,s),Oe=i(s),js=f(s,"DIV",{class:!0,"data-svelte-h":!0}),J(js)!=="svelte-pnh0xy"&&(js.innerHTML=Gt),st=i(s),Ks=f(s,"P",{"data-svelte-h":!0}),J(Ks)!=="svelte-1tz8nvz"&&(Ks.innerHTML=Wt),et=i(s),g(Os.$$.fragment,s),tt=i(s),se=f(s,"P",{"data-svelte-h":!0}),J(se)!=="svelte-1njl8vm"&&(se.innerHTML=Xt),at=i(s),g(ws.$$.fragment,s),lt=i(s),g(Js.$$.fragment,s),nt=i(s),ye=f(s,"P",{}),S(ye).forEach(e),this.h()},h(){N(a,"name","hf:doc:metadata"),N(a,"content",JSON.stringify(ua)),N(U,"id","image-classification"),N(U,"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"),N(U,"href","#image-classification"),N(T,"class","relative group"),N(A,"id","load-food101-dataset"),N(A,"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"),N(A,"href","#load-food101-dataset"),N(q,"class","relative group"),N(ms,"id","preprocess"),N(ms,"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"),N(ms,"href","#preprocess"),N(ps,"class","relative group"),N(us,"id","evaluate"),N(us,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),N(us,"href","#evaluate"),N(os,"class","relative group"),N(ds,"id","train"),N(ds,"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"),N(ds,"href","#train"),N(rs,"class","relative group"),N(bs,"id","inference"),N(bs,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),N(bs,"href","#inference"),N(is,"class","relative group"),N(js,"class","flex justify-center")},m(s,n){E(document.head,a),t(s,u,n),t(s,l,n),t(s,m,n),t(s,T,n),E(T,U),E(U,R),M(I,R,null),E(T,C),E(T,Y),t(s,F,n),M(G,s,n),t(s,v,n),M(V,s,n),t(s,o,n),t(s,_,n),t(s,W,n),t(s,z,n),t(s,$,n),t(s,Q,n),t(s,B,n),M(L,s,n),t(s,P,n),t(s,D,n),t(s,$s,n),M(K,s,n),t(s,O,n),t(s,ss,n),t(s,Us,n),M(es,s,n),t(s,ts,n),t(s,q,n),E(q,A),E(A,cs),M(as,cs,null),E(q,c),E(q,k),t(s,Je,n),t(s,_s,n),t(s,Te,n),M(vs,s,n),t(s,$e,n),t(s,Cs,n),t(s,Ue,n),M(Zs,s,n),t(s,_e,n),t(s,ks,n),t(s,ve,n),M(Is,s,n),t(s,Ce,n),t(s,Gs,n),t(s,Ze,n),t(s,Ws,n),t(s,ke,n),t(s,Xs,n),t(s,Ie,n),M(xs,s,n),t(s,Ge,n),t(s,Vs,n),t(s,We,n),M(Ys,s,n),t(s,Xe,n),t(s,ps,n),E(ps,ms),E(ms,he),M(Fs,he,null),E(ps,mt),E(ps,le),t(s,xe,n),t(s,Rs,n),t(s,Ve,n),M(Ns,s,n),t(s,Ye,n),M(hs,s,n),t(s,Fe,n),M(fs,s,n),t(s,Re,n),t(s,os,n),E(os,us),E(us,fe),M(Bs,fe,null),E(os,ht),E(os,ne),t(s,Ne,n),t(s,Es,n),t(s,Be,n),M(zs,s,n),t(s,Ee,n),t(s,Hs,n),t(s,ze,n),M(Qs,s,n),t(s,He,n),t(s,Ss,n),t(s,Qe,n),t(s,rs,n),E(rs,ds),E(ds,ue),M(As,ue,null),E(rs,ft),E(rs,pe),t(s,Se,n),M(ys,s,n),t(s,Ae,n),M(gs,s,n),t(s,qe,n),M(Ms,s,n),t(s,Le,n),t(s,is,n),E(is,bs),E(bs,de),M(qs,de,null),E(is,ut),E(is,oe),t(s,Pe,n),t(s,Ls,n),t(s,De,n),t(s,Ps,n),t(s,Ke,n),M(Ds,s,n),t(s,Oe,n),t(s,js,n),t(s,st,n),t(s,Ks,n),t(s,et,n),M(Os,s,n),t(s,tt,n),t(s,se,n),t(s,at,n),M(ws,s,n),t(s,lt,n),M(Js,s,n),t(s,nt,n),t(s,ye,n),pt=!0},p(s,[n]){const ee={};n&2&&(ee.$$scope={dirty:n,ctx:s}),L.$set(ee);const ge={};n&2&&(ge.$$scope={dirty:n,ctx:s}),hs.$set(ge);const Me={};n&2&&(Me.$$scope={dirty:n,ctx:s}),fs.$set(Me);const te={};n&2&&(te.$$scope={dirty:n,ctx:s}),ys.$set(te);const be={};n&2&&(be.$$scope={dirty:n,ctx:s}),gs.$set(be);const je={};n&2&&(je.$$scope={dirty:n,ctx:s}),Ms.$set(je);const ae={};n&2&&(ae.$$scope={dirty:n,ctx:s}),ws.$set(ae);const we={};n&2&&(we.$$scope={dirty:n,ctx:s}),Js.$set(we)},i(s){pt||(b(I.$$.fragment,s),b(G.$$.fragment,s),b(V.$$.fragment,s),b(L.$$.fragment,s),b(K.$$.fragment,s),b(es.$$.fragment,s),b(as.$$.fragment,s),b(vs.$$.fragment,s),b(Zs.$$.fragment,s),b(Is.$$.fragment,s),b(xs.$$.fragment,s),b(Ys.$$.fragment,s),b(Fs.$$.fragment,s),b(Ns.$$.fragment,s),b(hs.$$.fragment,s),b(fs.$$.fragment,s),b(Bs.$$.fragment,s),b(zs.$$.fragment,s),b(Qs.$$.fragment,s),b(As.$$.fragment,s),b(ys.$$.fragment,s),b(gs.$$.fragment,s),b(Ms.$$.fragment,s),b(qs.$$.fragment,s),b(Ds.$$.fragment,s),b(Os.$$.fragment,s),b(ws.$$.fragment,s),b(Js.$$.fragment,s),pt=!0)},o(s){j(I.$$.fragment,s),j(G.$$.fragment,s),j(V.$$.fragment,s),j(L.$$.fragment,s),j(K.$$.fragment,s),j(es.$$.fragment,s),j(as.$$.fragment,s),j(vs.$$.fragment,s),j(Zs.$$.fragment,s),j(Is.$$.fragment,s),j(xs.$$.fragment,s),j(Ys.$$.fragment,s),j(Fs.$$.fragment,s),j(Ns.$$.fragment,s),j(hs.$$.fragment,s),j(fs.$$.fragment,s),j(Bs.$$.fragment,s),j(zs.$$.fragment,s),j(Qs.$$.fragment,s),j(As.$$.fragment,s),j(ys.$$.fragment,s),j(gs.$$.fragment,s),j(Ms.$$.fragment,s),j(qs.$$.fragment,s),j(Ds.$$.fragment,s),j(Os.$$.fragment,s),j(ws.$$.fragment,s),j(Js.$$.fragment,s),pt=!1},d(s){s&&(e(u),e(l),e(m),e(T),e(F),e(v),e(o),e(_),e(W),e(z),e($),e(Q),e(B),e(P),e(D),e($s),e(O),e(ss),e(Us),e(ts),e(q),e(Je),e(_s),e(Te),e($e),e(Cs),e(Ue),e(_e),e(ks),e(ve),e(Ce),e(Gs),e(Ze),e(Ws),e(ke),e(Xs),e(Ie),e(Ge),e(Vs),e(We),e(Xe),e(ps),e(xe),e(Rs),e(Ve),e(Ye),e(Fe),e(Re),e(os),e(Ne),e(Es),e(Be),e(Ee),e(Hs),e(ze),e(He),e(Ss),e(Qe),e(rs),e(Se),e(Ae),e(qe),e(Le),e(is),e(Pe),e(Ls),e(De),e(Ps),e(Ke),e(Oe),e(js),e(st),e(Ks),e(et),e(tt),e(se),e(at),e(lt),e(nt),e(ye)),e(a),w(I),w(G,s),w(V,s),w(L,s),w(K,s),w(es,s),w(as),w(vs,s),w(Zs,s),w(Is,s),w(xs,s),w(Ys,s),w(Fs),w(Ns,s),w(hs,s),w(fs,s),w(Bs),w(zs,s),w(Qs,s),w(As),w(ys,s),w(gs,s),w(Ms,s),w(qs),w(Ds,s),w(Os,s),w(ws,s),w(Js,s)}}}const ua={local:"image-classification",sections:[{local:"load-food101-dataset",title:"Load Food-101 dataset"},{local:"preprocess",title:"Preprocess"},{local:"evaluate",title:"Evaluate"},{local:"train",title:"Train"},{local:"inference",title:"Inference"}],title:"Image classification"};function da(x){return zt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class $a extends Ht{constructor(a){super(),Qt(this,a,da,fa,Et,{})}}export{$a as component};
