import{s as _e,n as Le,o as Ge}from"../chunks/scheduler.7bc62968.js";import{S as Ne,i as ke,g as o,s as i,r as V,A as $e,h as l,f as a,c as s,j as Te,u as ee,x as r,k as Ae,y as He,a as n,v as te,d as ae,t as ne,w as ie}from"../chunks/index.2f8492b0.js";import{H as se}from"../chunks/Heading.14fb2476.js";function Me(oe){let c,H,k,M,h,P,d,le='This section introduces CycleGAN, short for <em>Cycle-Consistent Generative Adversarial Network</em>, which is a framework designed for image-to-image translation tasks where paired examples are not available. Introduced by Zhu et al. in a <a href="https://arxiv.org/abs/1703.10593" rel="nofollow">2017</a> paper, it represents a significant advancement in the field of computer vision and machine learning.',I,m,re="In many image-to-image translation tasks, the goal is to learn a mapping between an input image and an output image. Traditional approaches often rely on large datasets of paired examples (e.g., photos and corresponding sketches). However, obtaining such paired datasets can be extremely challenging or even infeasible in many scenarios. This is where CycleGAN comes into play, as it is designed to work with unpaired datasets.",z,p,q,f,ce='<img src="https://huggingface.co/datasets/hf-vision/course-assets/resolve/main/unpaired_images.png" alt="paired and unpaired_images"/>',S,g,he="In many image translation scenarios, we encounter datasets lacking direct, one-to-one correspondence between image pairs. This scenario is where unpaired image-to-image translation comes into play. Here, instead of having matching pairs of images, you work with two distinct sets or “piles” of images, each representing a different style or domain, such as X and Y. For instance, one pile might consist of realistic photographs, while the other could contain artworks by Monet, Cezanne, or other artists. Alternatively, the piles could represent different seasons, with one showcasing winter landscapes and the other summer scenes. Another example could be a collection of horse images in one pile and zebra images in the other, without any direct pairing between the two. The objective in unpaired image-to-image translation is for the model to learn and extract the general stylistic elements from each pile and apply these learned styles to transform images from one domain to another. This transformation often works both ways, allowing images from domain X to be translated into the style of domain Y, and vice versa. This approach is particularly valuable when exact image pairs are unavailable or difficult to obtain.",j,u,E,v,de="<strong>Dual GAN Structure</strong>:",F,y,me="CycleGAN employs two GANs (Generative Adversarial Networks), one for translating from the first set to the second (e.g., zebra to horse) and another for the reverse process (horse to zebra). This dual structure ensures realism (via the adversarial process) and content preservation (via cycle consistency).",U,w,pe=`<li>PatchGAN Discriminators: The discriminators used in CycleGAN are based on <a href="https://arxiv.org/pdf/1611.07004.pdf" rel="nofollow">PatchGAN</a> architecture, which assesses patches of an image rather than the whole, contributing to more detailed and localized realism.</li> <li>Generator Architecture: The generators in CycleGAN draw from <a href="https://arxiv.org/abs/1505.04597" rel="nofollow">U-Net</a> and [DCGAN](<a href="https://arxiv.org/abs/1511.06434" rel="nofollow">https://arxiv.org/abs/1511.06434</a> architectures, involving downsampling (encoding), upsampling (decoding), and convolutional layers with batch normalization and ReLU.
These generators are enhanced with additional convolutional layers and skip connections, known as residual connections, which aid in learning identity functions and supporting deeper transformations.</li>`,D,b,fe="<strong>Cycle Consistency Loss</strong>:",W,C,ge="Ensures that the style of an image can be changed (e.g., sad face to hugging face) and then reverted back to its original form (hugging face back to sad face) with minimal loss of detail or content.",R,x,ue="Implementation Involves two stages of transformation.",X,T,ve=`<strong>First Stage</strong>: A sad face is transformed into a hugging face. <strong>Second Stage</strong>: This hugging face is then converted back into a sad face. The model aims for the final image (reverted sad face) to closely resemble the original sad face. This is achieved by minimizing the pixel difference between these two images, which is added to the model’s loss function. The cycle consistency is applied in both directions: sad face to hugging face to sad face, and hugging face to sad face to hugging face. The loss for each cycle is calculated by summing the pixel differences and is then incorporated into the overall generator loss.
Integration with Adversarial Loss: Cycle consistency loss is combined with adversarial loss, commonly used in GANs, to form a comprehensive loss function. This combined loss function is optimized simultaneously for both generators in CycleGAN.`,Y,A,ye="<strong>Least-Square Loss</strong>:",B,_,we="It’s a method that minimizes the sum of squared residuals. What that means is that it tries to find the best-fit line that has the smallest sum of squared distances between that line and all the points. In GANs, the <strong>line</strong> represents the label (real or fake), and the points represent the discriminator’s predictions. The discriminator’s loss function in Least Squares adversarial loss is formulated by calculating the squared distance between its predictions and the actual labels (real or fake) across multiple images. For the generator, the loss function is designed to make its fake outputs appear as real as possible, measured by how far these outputs deviate from the label of <strong>real</strong>. Having Least-Square Loss addresses vanishing gradients and mode collapse issues common in BCE loss.",Z,L,be="<strong>Indentity Loss</strong>:",J,G,Ce=`Introduced in CycleGAN, identity loss is an optional loss term aimed at enhancing color preservation in generated images. It works by ensuring that an image input into a generator (e.g., a horse image into a zebra-to-horse generator) should ideally output the same image, as it is already in the target style. The loss is calculated as the pixel distance between the real input and the output of the generator. A zero pixel distance (no change in the image) results in zero identity loss, which is the desired outcome.
For CycleGANs generators, this loss is added alongside adversarial and cycle consistency losses. It’s adjusted using a lambda term (weighting factor).`,K,N,xe=`<img src="https://huggingface.co/datasets/hf-vision/course-assets/resolve/main/cycleGAN1.jpg" alt="CycleGAN"/>
This figure shows the combined GAN architecture functionality for both <strong>GANs</strong>. These GANs are linked by cycle consistency, forming a cycle.
For real images, the classification matrix contains ones. For fake images, it contains zeros. In summary, CycleGAN intricately combines two GANs with various loss functions, including adversarial, cycle consistency, and optional identity loss,
to effectively transfer styles between two domains while preserving the essential characteristics of the input images.`,O,$,Q;return h=new se({props:{title:"CycleGAN Introduction",local:"cyclegan-introduction",headingTag:"h1"}}),p=new se({props:{title:"What Is Unpaired Image-to-Image Translation",local:"what-is-unpaired-image-to-image-translation",headingTag:"h2"}}),u=new se({props:{title:"Main Components of CycleGAN",local:"main-components-of-cyclegan",headingTag:"h2"}}),{c(){c=o("meta"),H=i(),k=o("p"),M=i(),V(h.$$.fragment),P=i(),d=o("p"),d.innerHTML=le,I=i(),m=o("p"),m.textContent=re,z=i(),V(p.$$.fragment),q=i(),f=o("p"),f.innerHTML=ce,S=i(),g=o("p"),g.textContent=he,j=i(),V(u.$$.fragment),E=i(),v=o("p"),v.innerHTML=de,F=i(),y=o("p"),y.textContent=me,U=i(),w=o("ul"),w.innerHTML=pe,D=i(),b=o("p"),b.innerHTML=fe,W=i(),C=o("p"),C.textContent=ge,R=i(),x=o("p"),x.textContent=ue,X=i(),T=o("p"),T.innerHTML=ve,Y=i(),A=o("p"),A.innerHTML=ye,B=i(),_=o("p"),_.innerHTML=we,Z=i(),L=o("p"),L.innerHTML=be,J=i(),G=o("p"),G.textContent=Ce,K=i(),N=o("p"),N.innerHTML=xe,O=i(),$=o("p"),this.h()},l(e){const t=$e("svelte-u9bgzb",document.head);c=l(t,"META",{name:!0,content:!0}),t.forEach(a),H=s(e),k=l(e,"P",{}),Te(k).forEach(a),M=s(e),ee(h.$$.fragment,e),P=s(e),d=l(e,"P",{"data-svelte-h":!0}),r(d)!=="svelte-1vunqvr"&&(d.innerHTML=le),I=s(e),m=l(e,"P",{"data-svelte-h":!0}),r(m)!=="svelte-1wd5x5o"&&(m.textContent=re),z=s(e),ee(p.$$.fragment,e),q=s(e),f=l(e,"P",{"data-svelte-h":!0}),r(f)!=="svelte-1ok4k6q"&&(f.innerHTML=ce),S=s(e),g=l(e,"P",{"data-svelte-h":!0}),r(g)!=="svelte-aq342c"&&(g.textContent=he),j=s(e),ee(u.$$.fragment,e),E=s(e),v=l(e,"P",{"data-svelte-h":!0}),r(v)!=="svelte-1d6m7lo"&&(v.innerHTML=de),F=s(e),y=l(e,"P",{"data-svelte-h":!0}),r(y)!=="svelte-g7ojp9"&&(y.textContent=me),U=s(e),w=l(e,"UL",{"data-svelte-h":!0}),r(w)!=="svelte-119u2tg"&&(w.innerHTML=pe),D=s(e),b=l(e,"P",{"data-svelte-h":!0}),r(b)!=="svelte-gg19do"&&(b.innerHTML=fe),W=s(e),C=l(e,"P",{"data-svelte-h":!0}),r(C)!=="svelte-emhl4j"&&(C.textContent=ge),R=s(e),x=l(e,"P",{"data-svelte-h":!0}),r(x)!=="svelte-pabc23"&&(x.textContent=ue),X=s(e),T=l(e,"P",{"data-svelte-h":!0}),r(T)!=="svelte-c2z849"&&(T.innerHTML=ve),Y=s(e),A=l(e,"P",{"data-svelte-h":!0}),r(A)!=="svelte-1651i7l"&&(A.innerHTML=ye),B=s(e),_=l(e,"P",{"data-svelte-h":!0}),r(_)!=="svelte-edylf9"&&(_.innerHTML=we),Z=s(e),L=l(e,"P",{"data-svelte-h":!0}),r(L)!=="svelte-oz5lfc"&&(L.innerHTML=be),J=s(e),G=l(e,"P",{"data-svelte-h":!0}),r(G)!=="svelte-1ig7g33"&&(G.textContent=Ce),K=s(e),N=l(e,"P",{"data-svelte-h":!0}),r(N)!=="svelte-1bir4m6"&&(N.innerHTML=xe),O=s(e),$=l(e,"P",{}),Te($).forEach(a),this.h()},h(){Ae(c,"name","hf:doc:metadata"),Ae(c,"content",Pe)},m(e,t){He(document.head,c),n(e,H,t),n(e,k,t),n(e,M,t),te(h,e,t),n(e,P,t),n(e,d,t),n(e,I,t),n(e,m,t),n(e,z,t),te(p,e,t),n(e,q,t),n(e,f,t),n(e,S,t),n(e,g,t),n(e,j,t),te(u,e,t),n(e,E,t),n(e,v,t),n(e,F,t),n(e,y,t),n(e,U,t),n(e,w,t),n(e,D,t),n(e,b,t),n(e,W,t),n(e,C,t),n(e,R,t),n(e,x,t),n(e,X,t),n(e,T,t),n(e,Y,t),n(e,A,t),n(e,B,t),n(e,_,t),n(e,Z,t),n(e,L,t),n(e,J,t),n(e,G,t),n(e,K,t),n(e,N,t),n(e,O,t),n(e,$,t),Q=!0},p:Le,i(e){Q||(ae(h.$$.fragment,e),ae(p.$$.fragment,e),ae(u.$$.fragment,e),Q=!0)},o(e){ne(h.$$.fragment,e),ne(p.$$.fragment,e),ne(u.$$.fragment,e),Q=!1},d(e){e&&(a(H),a(k),a(M),a(P),a(d),a(I),a(m),a(z),a(q),a(f),a(S),a(g),a(j),a(E),a(v),a(F),a(y),a(U),a(w),a(D),a(b),a(W),a(C),a(R),a(x),a(X),a(T),a(Y),a(A),a(B),a(_),a(Z),a(L),a(J),a(G),a(K),a(N),a(O),a($)),a(c),ie(h,e),ie(p,e),ie(u,e)}}}const Pe='{"title":"CycleGAN Introduction","local":"cyclegan-introduction","sections":[{"title":"What Is Unpaired Image-to-Image Translation","local":"what-is-unpaired-image-to-image-translation","sections":[],"depth":2},{"title":"Main Components of CycleGAN","local":"main-components-of-cyclegan","sections":[],"depth":2}],"depth":1}';function Ie(oe){return Ge(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class je extends Ne{constructor(c){super(),ke(this,c,Ie,Me,_e,{})}}export{je as component};
