import{s as Le,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 ze,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(F){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 Fe(F){let i,y,o,D,j,X,w,ye="This guide shows specific methods for processing image datasets. Learn how to:",W,b,je='<li>Use <a href="/docs/datasets/pr_6981/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/pr_6981/en/package_reference/main_classes#datasets.Dataset.set_transform">set_transform()</a>.</li>',q,T,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,$,Y,_,be='The <a href="/docs/datasets/pr_6981/en/package_reference/main_classes#datasets.Dataset.map">map()</a> function can apply transforms over an entire dataset.',K,J,Te='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,v,O,U,$e='Now use the <a href="/docs/datasets/pr_6981/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/pr_6981/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,Je='<a href="/docs/datasets/pr_6981/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,ve='<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/pr_6981/en/package_reference/main_classes#datasets.Dataset.map">map()</a>.',ne,B,pe,z,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/pr_6981/en/package_reference/main_classes#datasets.Dataset.set_transform">set_transform()</a>, which consumes less disk space.',re,g,ie,L,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/pr_6981/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"}}),$=new ge({props:{title:"Map",local:"map",headingTag:"h2"}}),v=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:F}}}),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),X=l(),w=p("p"),w.textContent=ye,W=l(),b=p("ul"),b.innerHTML=je,q=l(),T=p("p"),T.innerHTML=we,V=l(),c($.$$.fragment),Y=l(),_=p("p"),_.innerHTML=be,K=l(),J=p("p"),J.innerHTML=Te,S=l(),c(v.$$.fragment),O=l(),U=p("p"),U.innerHTML=$e,ee=l(),c(x.$$.fragment),te=l(),k=p("p"),k.innerHTML=_e,se=l(),C=p("p"),C.innerHTML=Je,ae=l(),H=p("ul"),H.innerHTML=ve,le=l(),I=p("p"),I.innerHTML=Ue,ne=l(),c(B.$$.fragment),pe=l(),z=p("p"),z.innerHTML=xe,re=l(),c(g.$$.fragment),ie=l(),L=p("p"),L.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),X=n(e),w=r(e,"P",{"data-svelte-h":!0}),m(w)!=="svelte-7uwdmt"&&(w.textContent=ye),W=n(e),b=r(e,"UL",{"data-svelte-h":!0}),m(b)!=="svelte-1u7tbpb"&&(b.innerHTML=je),q=n(e),T=r(e,"P",{"data-svelte-h":!0}),m(T)!=="svelte-3s2bzp"&&(T.innerHTML=we),V=n(e),f($.$$.fragment,e),Y=n(e),_=r(e,"P",{"data-svelte-h":!0}),m(_)!=="svelte-1lrz6h0"&&(_.innerHTML=be),K=n(e),J=r(e,"P",{"data-svelte-h":!0}),m(J)!=="svelte-3s9pec"&&(J.innerHTML=Te),S=n(e),f(v.$$.fragment,e),O=n(e),U=r(e,"P",{"data-svelte-h":!0}),m(U)!=="svelte-1xqrrpk"&&(U.innerHTML=$e),ee=n(e),f(x.$$.fragment,e),te=n(e),k=r(e,"P",{"data-svelte-h":!0}),m(k)!=="svelte-1w979kt"&&(k.innerHTML=_e),se=n(e),C=r(e,"P",{"data-svelte-h":!0}),m(C)!=="svelte-mj4s91"&&(C.innerHTML=Je),ae=n(e),H=r(e,"UL",{"data-svelte-h":!0}),m(H)!=="svelte-1uuk8jl"&&(H.innerHTML=ve),le=n(e),I=r(e,"P",{"data-svelte-h":!0}),m(I)!=="svelte-bk6upa"&&(I.innerHTML=Ue),ne=n(e),f(B.$$.fragment,e),pe=n(e),z=r(e,"P",{"data-svelte-h":!0}),m(z)!=="svelte-yjg5yp"&&(z.innerHTML=xe),re=n(e),f(g.$$.fragment,e),ie=n(e),L=r(e,"P",{"data-svelte-h":!0}),m(L)!=="svelte-1dscypy"&&(L.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-tezmwi"&&(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(){ze(i,"name","hf:doc:metadata"),ze(i,"content",Xe)},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,X,t),a(e,w,t),a(e,W,t),a(e,b,t),a(e,q,t),a(e,T,t),a(e,V,t),h($,e,t),a(e,Y,t),a(e,_,t),a(e,K,t),a(e,J,t),a(e,S,t),h(v,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,z,t),a(e,re,t),h(g,e,t),a(e,ie,t),a(e,L,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($.$$.fragment,e),u(v.$$.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($.$$.fragment,e),d(v.$$.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(X),s(w),s(W),s(b),s(q),s(T),s(V),s(Y),s(_),s(K),s(J),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(z),s(re),s(ie),s(L),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($,e),M(v,e),M(x,e),M(B,e),M(g,e),M(R,e),M(Z,e),M(P,e),M(E,e)}}}const Xe='{"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 We(F){return Re(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Oe extends Ze{constructor(i){super(),Ge(this,i,We,Fe,Le,{})}}export{Oe as component};
