import{s as ze,o as Re,n as Ae}from"../chunks/scheduler.bdbef820.js";import{S as Ze,i as Ge,g as p,s as l,r as c,A as Pe,h as r,f as s,c as n,j as Be,u as f,x as m,k as Le,y as Ee,a,v as h,d as u,t as d,w as M}from"../chunks/index.c0aea24a.js";import{T as De}from"../chunks/Tip.31005f7d.js";import{C as Q}from"../chunks/CodeBlock.6ccca92e.js";import{H as ge,E as Ne}from"../chunks/EditOnGithub.725ee0c1.js";function Qe(q){let i,y='The following example uses <a href="https://pytorch.org/vision/stable/index.html" rel="nofollow">torchvision</a>, but feel free to use other data augmentation libraries like <a href="https://albumentations.ai/docs/" rel="nofollow">Albumentations</a>, <a href="https://kornia.readthedocs.io/en/latest/" rel="nofollow">Kornia</a>, and <a href="https://imgaug.readthedocs.io/en/latest/" rel="nofollow">imgaug</a>.';return{c(){i=p("p"),i.innerHTML=y},l(o){i=r(o,"P",{"data-svelte-h":!0}),m(i)!=="svelte-7kbokn"&&(i.innerHTML=y)},m(o,D){a(o,i,D)},p:Ae,d(o){o&&s(i)}}}function qe(q){let i,y,o,D,j,F,w,ye="This guide shows specific methods for processing image datasets. Learn how to:",X,T,je='<li>Use <a href="/docs/datasets/v2.21.0/en/package_reference/main_classes#datasets.Dataset.map">map()</a> with image dataset.</li> <li>Apply data augmentations to a dataset with <a href="/docs/datasets/v2.21.0/en/package_reference/main_classes#datasets.Dataset.set_transform">set_transform()</a>.</li>',W,$,we='For a guide on how to process any type of dataset, take a look at the <a class="underline decoration-sky-400 decoration-2 font-semibold" href="./process">general process guide</a>.',V,b,Y,_,Te='The <a href="/docs/datasets/v2.21.0/en/package_reference/main_classes#datasets.Dataset.map">map()</a> function can apply transforms over an entire dataset.',K,v,$e='For example, create a basic <a href="https://pytorch.org/vision/stable/generated/torchvision.transforms.Resize.html" rel="nofollow"><code>Resize</code></a> function:',S,J,O,U,be='Now use the <a href="/docs/datasets/v2.21.0/en/package_reference/main_classes#datasets.Dataset.map">map()</a> function to resize the entire dataset, and set <code>batched=True</code> to speed up the process by accepting batches of examples. The transform returns <code>pixel_values</code> as a cacheable <code>PIL.Image</code> object:',ee,x,te,k,_e='The cache file saves time because you don’t have to execute the same transform twice. The <a href="/docs/datasets/v2.21.0/en/package_reference/main_classes#datasets.Dataset.map">map()</a> function is best for operations you only run once per training - like resizing an image - instead of using it for operations executed for each epoch, like data augmentations.',se,C,ve='<a href="/docs/datasets/v2.21.0/en/package_reference/main_classes#datasets.Dataset.map">map()</a> takes up some memory, but you can reduce its memory requirements with the following parameters:',ae,H,Je='<li><a href="./package_reference/main_classes#datasets.DatasetDict.map.batch_size"><code>batch_size</code></a> determines the number of examples that are processed in one call to the transform function.</li> <li><a href="./package_reference/main_classes#datasets.DatasetDict.map.writer_batch_size"><code>writer_batch_size</code></a> determines the number of processed examples that are kept in memory before they are stored away.</li>',le,I,Ue='Both parameter values default to 1000, which can be expensive if you are storing images. Lower these values to use less memory when you use <a href="/docs/datasets/v2.21.0/en/package_reference/main_classes#datasets.Dataset.map">map()</a>.',ne,B,pe,L,xe='🤗 Datasets applies data augmentations from any library or package to your dataset. Transforms can be applied on-the-fly on batches of data with <a href="/docs/datasets/v2.21.0/en/package_reference/main_classes#datasets.Dataset.set_transform">set_transform()</a>, which consumes less disk space.',re,g,ie,z,ke="For example, if you’d like to change the color properties of an image randomly:",me,R,oe,A,Ce="Create a function to apply the <code>ColorJitter</code> transform:",ce,Z,fe,G,He='Apply the transform with the <a href="/docs/datasets/v2.21.0/en/package_reference/main_classes#datasets.Dataset.set_transform">set_transform()</a> function:',he,P,ue,E,de,N,Me;return j=new ge({props:{title:"Process image data",local:"process-image-data",headingTag:"h1"}}),b=new ge({props:{title:"Map",local:"map",headingTag:"h2"}}),J=new Q({props:{code:"ZGVmJTIwdHJhbnNmb3JtcyhleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjBleGFtcGxlcyU1QiUyMnBpeGVsX3ZhbHVlcyUyMiU1RCUyMCUzRCUyMCU1QmltYWdlLmNvbnZlcnQoJTIyUkdCJTIyKS5yZXNpemUoKDEwMCUyQzEwMCkpJTIwZm9yJTIwaW1hZ2UlMjBpbiUyMGV4YW1wbGVzJTVCJTIyaW1hZ2UlMjIlNUQlNUQlMEElMjAlMjAlMjAlMjByZXR1cm4lMjBleGFtcGxlcw==",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>] = [image.convert(<span class="hljs-string">&quot;RGB&quot;</span>).resize((<span class="hljs-number">100</span>,<span class="hljs-number">100</span>)) <span class="hljs-keyword">for</span> image <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;image&quot;</span>]]
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> examples`,wrap:!1}}),x=new Q({props:{code:"ZGF0YXNldCUyMCUzRCUyMGRhdGFzZXQubWFwKHRyYW5zZm9ybXMlMkMlMjByZW1vdmVfY29sdW1ucyUzRCU1QiUyMmltYWdlJTIyJTVEJTJDJTIwYmF0Y2hlZCUzRFRydWUpJTBBZGF0YXNldCU1QjAlNUQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = dataset.<span class="hljs-built_in">map</span>(transforms, remove_columns=[<span class="hljs-string">&quot;image&quot;</span>], batched=<span class="hljs-literal">True</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset[<span class="hljs-number">0</span>]
{<span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-number">6</span>,
 <span class="hljs-string">&#x27;pixel_values&#x27;</span>: &lt;PIL.PngImagePlugin.PngImageFile image mode=RGB size=100x100 at <span class="hljs-number">0x7F058237BB10</span>&gt;}`,wrap:!1}}),B=new ge({props:{title:"Apply transforms",local:"apply-transforms",headingTag:"h2"}}),g=new De({props:{$$slots:{default:[Qe]},$$scope:{ctx:q}}}),R=new Q({props:{code:"ZnJvbSUyMHRvcmNodmlzaW9uLnRyYW5zZm9ybXMlMjBpbXBvcnQlMjBDb21wb3NlJTJDJTIwQ29sb3JKaXR0ZXIlMkMlMjBUb1RlbnNvciUwQSUwQWppdHRlciUyMCUzRCUyMENvbXBvc2UoJTBBJTIwJTIwJTIwJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwQ29sb3JKaXR0ZXIoYnJpZ2h0bmVzcyUzRDAuMjUlMkMlMjBjb250cmFzdCUzRDAuMjUlMkMlMjBzYXR1cmF0aW9uJTNEMC4yNSUyQyUyMGh1ZSUzRDAuNyklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBUb1RlbnNvcigpJTJDJTBBJTIwJTIwJTIwJTIwJTVEJTBBKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> torchvision.transforms <span class="hljs-keyword">import</span> Compose, ColorJitter, ToTensor

<span class="hljs-meta">&gt;&gt;&gt; </span>jitter = Compose(
<span class="hljs-meta">... </span>    [
<span class="hljs-meta">... </span>         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.7</span>),
<span class="hljs-meta">... </span>         ToTensor(),
<span class="hljs-meta">... </span>    ]
<span class="hljs-meta">... </span>)`,wrap:!1}}),Z=new Q({props:{code:"ZGVmJTIwdHJhbnNmb3JtcyhleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjBleGFtcGxlcyU1QiUyMnBpeGVsX3ZhbHVlcyUyMiU1RCUyMCUzRCUyMCU1QmppdHRlcihpbWFnZS5jb252ZXJ0KCUyMlJHQiUyMikpJTIwZm9yJTIwaW1hZ2UlMjBpbiUyMGV4YW1wbGVzJTVCJTIyaW1hZ2UlMjIlNUQlNUQlMEElMjAlMjAlMjAlMjByZXR1cm4lMjBleGFtcGxlcw==",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>] = [jitter(image.convert(<span class="hljs-string">&quot;RGB&quot;</span>)) <span class="hljs-keyword">for</span> image <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;image&quot;</span>]]
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> examples`,wrap:!1}}),P=new Q({props:{code:"ZGF0YXNldC5zZXRfdHJhbnNmb3JtKHRyYW5zZm9ybXMp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>dataset.set_transform(transforms)',wrap:!1}}),E=new Ne({props:{source:"https://github.com/huggingface/datasets/blob/main/docs/source/image_process.mdx"}}),{c(){i=p("meta"),y=l(),o=p("p"),D=l(),c(j.$$.fragment),F=l(),w=p("p"),w.textContent=ye,X=l(),T=p("ul"),T.innerHTML=je,W=l(),$=p("p"),$.innerHTML=we,V=l(),c(b.$$.fragment),Y=l(),_=p("p"),_.innerHTML=Te,K=l(),v=p("p"),v.innerHTML=$e,S=l(),c(J.$$.fragment),O=l(),U=p("p"),U.innerHTML=be,ee=l(),c(x.$$.fragment),te=l(),k=p("p"),k.innerHTML=_e,se=l(),C=p("p"),C.innerHTML=ve,ae=l(),H=p("ul"),H.innerHTML=Je,le=l(),I=p("p"),I.innerHTML=Ue,ne=l(),c(B.$$.fragment),pe=l(),L=p("p"),L.innerHTML=xe,re=l(),c(g.$$.fragment),ie=l(),z=p("p"),z.textContent=ke,me=l(),c(R.$$.fragment),oe=l(),A=p("p"),A.innerHTML=Ce,ce=l(),c(Z.$$.fragment),fe=l(),G=p("p"),G.innerHTML=He,he=l(),c(P.$$.fragment),ue=l(),c(E.$$.fragment),de=l(),N=p("p"),this.h()},l(e){const t=Pe("svelte-u9bgzb",document.head);i=r(t,"META",{name:!0,content:!0}),t.forEach(s),y=n(e),o=r(e,"P",{}),Be(o).forEach(s),D=n(e),f(j.$$.fragment,e),F=n(e),w=r(e,"P",{"data-svelte-h":!0}),m(w)!=="svelte-7uwdmt"&&(w.textContent=ye),X=n(e),T=r(e,"UL",{"data-svelte-h":!0}),m(T)!=="svelte-13zbh1f"&&(T.innerHTML=je),W=n(e),$=r(e,"P",{"data-svelte-h":!0}),m($)!=="svelte-3s2bzp"&&($.innerHTML=we),V=n(e),f(b.$$.fragment,e),Y=n(e),_=r(e,"P",{"data-svelte-h":!0}),m(_)!=="svelte-3t5vcg"&&(_.innerHTML=Te),K=n(e),v=r(e,"P",{"data-svelte-h":!0}),m(v)!=="svelte-3s9pec"&&(v.innerHTML=$e),S=n(e),f(J.$$.fragment,e),O=n(e),U=r(e,"P",{"data-svelte-h":!0}),m(U)!=="svelte-12fvnls"&&(U.innerHTML=be),ee=n(e),f(x.$$.fragment,e),te=n(e),k=r(e,"P",{"data-svelte-h":!0}),m(k)!=="svelte-1nk2pql"&&(k.innerHTML=_e),se=n(e),C=r(e,"P",{"data-svelte-h":!0}),m(C)!=="svelte-1k95g4x"&&(C.innerHTML=ve),ae=n(e),H=r(e,"UL",{"data-svelte-h":!0}),m(H)!=="svelte-1uuk8jl"&&(H.innerHTML=Je),le=n(e),I=r(e,"P",{"data-svelte-h":!0}),m(I)!=="svelte-unu7qm"&&(I.innerHTML=Ue),ne=n(e),f(B.$$.fragment,e),pe=n(e),L=r(e,"P",{"data-svelte-h":!0}),m(L)!=="svelte-hkqhcp"&&(L.innerHTML=xe),re=n(e),f(g.$$.fragment,e),ie=n(e),z=r(e,"P",{"data-svelte-h":!0}),m(z)!=="svelte-1dscypy"&&(z.textContent=ke),me=n(e),f(R.$$.fragment,e),oe=n(e),A=r(e,"P",{"data-svelte-h":!0}),m(A)!=="svelte-1qyarbp"&&(A.innerHTML=Ce),ce=n(e),f(Z.$$.fragment,e),fe=n(e),G=r(e,"P",{"data-svelte-h":!0}),m(G)!=="svelte-2dj44q"&&(G.innerHTML=He),he=n(e),f(P.$$.fragment,e),ue=n(e),f(E.$$.fragment,e),de=n(e),N=r(e,"P",{}),Be(N).forEach(s),this.h()},h(){Le(i,"name","hf:doc:metadata"),Le(i,"content",Fe)},m(e,t){Ee(document.head,i),a(e,y,t),a(e,o,t),a(e,D,t),h(j,e,t),a(e,F,t),a(e,w,t),a(e,X,t),a(e,T,t),a(e,W,t),a(e,$,t),a(e,V,t),h(b,e,t),a(e,Y,t),a(e,_,t),a(e,K,t),a(e,v,t),a(e,S,t),h(J,e,t),a(e,O,t),a(e,U,t),a(e,ee,t),h(x,e,t),a(e,te,t),a(e,k,t),a(e,se,t),a(e,C,t),a(e,ae,t),a(e,H,t),a(e,le,t),a(e,I,t),a(e,ne,t),h(B,e,t),a(e,pe,t),a(e,L,t),a(e,re,t),h(g,e,t),a(e,ie,t),a(e,z,t),a(e,me,t),h(R,e,t),a(e,oe,t),a(e,A,t),a(e,ce,t),h(Z,e,t),a(e,fe,t),a(e,G,t),a(e,he,t),h(P,e,t),a(e,ue,t),h(E,e,t),a(e,de,t),a(e,N,t),Me=!0},p(e,[t]){const Ie={};t&2&&(Ie.$$scope={dirty:t,ctx:e}),g.$set(Ie)},i(e){Me||(u(j.$$.fragment,e),u(b.$$.fragment,e),u(J.$$.fragment,e),u(x.$$.fragment,e),u(B.$$.fragment,e),u(g.$$.fragment,e),u(R.$$.fragment,e),u(Z.$$.fragment,e),u(P.$$.fragment,e),u(E.$$.fragment,e),Me=!0)},o(e){d(j.$$.fragment,e),d(b.$$.fragment,e),d(J.$$.fragment,e),d(x.$$.fragment,e),d(B.$$.fragment,e),d(g.$$.fragment,e),d(R.$$.fragment,e),d(Z.$$.fragment,e),d(P.$$.fragment,e),d(E.$$.fragment,e),Me=!1},d(e){e&&(s(y),s(o),s(D),s(F),s(w),s(X),s(T),s(W),s($),s(V),s(Y),s(_),s(K),s(v),s(S),s(O),s(U),s(ee),s(te),s(k),s(se),s(C),s(ae),s(H),s(le),s(I),s(ne),s(pe),s(L),s(re),s(ie),s(z),s(me),s(oe),s(A),s(ce),s(fe),s(G),s(he),s(ue),s(de),s(N)),s(i),M(j,e),M(b,e),M(J,e),M(x,e),M(B,e),M(g,e),M(R,e),M(Z,e),M(P,e),M(E,e)}}}const Fe='{"title":"Process image data","local":"process-image-data","sections":[{"title":"Map","local":"map","sections":[],"depth":2},{"title":"Apply transforms","local":"apply-transforms","sections":[],"depth":2}],"depth":1}';function Xe(q){return Re(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Oe extends Ze{constructor(i){super(),Ge(this,i,Xe,qe,ze,{})}}export{Oe as component};
