import{S as sp,i as ap,s as lp,e as a,k as p,w as h,t as o,M as np,c as l,d as s,m as c,a as n,x as f,h as i,b as m,G as t,g as d,y as g,q as b,o as w,B as y,v as op,L as tp}from"../../../chunks/vendor-hf-doc-builder.js";import{D as bt}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as I}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as ee}from"../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as ep}from"../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function ip(wt){let J,E,T,M,U;return M=new I({props:{code:"aW1wb3J0JTIwcmVxdWVzdHMlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQWZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBERElNU2NoZWR1bGVyJTJDJTIwU3RhYmxlRGlmZnVzaW9uUGl4MlBpeFplcm9QaXBlbGluZSUwQSUwQSUwQWRlZiUyMGRvd25sb2FkKGVtYmVkZGluZ191cmwlMkMlMjBsb2NhbF9maWxlcGF0aCklM0ElMEElMjAlMjAlMjAlMjByJTIwJTNEJTIwcmVxdWVzdHMuZ2V0KGVtYmVkZGluZ191cmwpJTBBJTIwJTIwJTIwJTIwd2l0aCUyMG9wZW4obG9jYWxfZmlsZXBhdGglMkMlMjAlMjJ3YiUyMiklMjBhcyUyMGYlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmLndyaXRlKHIuY29udGVudCklMEElMEElMEFtb2RlbF9ja3B0JTIwJTNEJTIwJTIyQ29tcFZpcyUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNCUyMiUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGl4MlBpeFplcm9QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2twdCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFwaXBlbGluZS5zY2hlZHVsZXIlMjAlM0QlMjBERElNU2NoZWR1bGVyLmZyb21fY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MjB0YXJnZXRfZW1iZWRzJTNEdGFyZ2V0X2VtYmVkcyUyQyUwQSUyMCUyMCUyMCUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMGNyb3NzX2F0dGVudGlvbl9ndWlkYW5jZV9hbW91bnQlM0QwLjE1JTJDJTBBKS5pbWFnZXMlMEElMEFpbWFnZXMlNUIwJTVELnNhdmUoJTIyZWRpdGVkX2ltYWdlX2RvZy5wbmclMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, StableDiffusionPix2PixZeroPipeline


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">download</span>(<span class="hljs-params">embedding_url, local_filepath</span>):
<span class="hljs-meta">... </span>    r = requests.get(embedding_url)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(local_filepath, <span class="hljs-string">&quot;wb&quot;</span>) <span class="hljs-keyword">as</span> f:
<span class="hljs-meta">... </span>        f.write(r.content)


<span class="hljs-meta">&gt;&gt;&gt; </span>model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(model_ckpt, torch_dtype=torch.float16)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;a high resolution painting of a cat in the style of van gough&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>source_emb_url = <span class="hljs-string">&quot;https://hf.co/datasets/sayakpaul/sample-datasets/resolve/main/cat.pt&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>target_emb_url = <span class="hljs-string">&quot;https://hf.co/datasets/sayakpaul/sample-datasets/resolve/main/dog.pt&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> url <span class="hljs-keyword">in</span> [source_emb_url, target_emb_url]:
<span class="hljs-meta">... </span>    download(url, url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])

<span class="hljs-meta">&gt;&gt;&gt; </span>src_embeds = torch.load(source_emb_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>target_embeds = torch.load(target_emb_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>images = pipeline(
<span class="hljs-meta">... </span>    prompt,
<span class="hljs-meta">... </span>    source_embeds=src_embeds,
<span class="hljs-meta">... </span>    target_embeds=target_embeds,
<span class="hljs-meta">... </span>    num_inference_steps=<span class="hljs-number">50</span>,
<span class="hljs-meta">... </span>    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
<span class="hljs-meta">... </span>).images

<span class="hljs-meta">&gt;&gt;&gt; </span>images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;edited_image_dog.png&quot;</span>)`}}),{c(){J=a("p"),E=o("Examples:"),T=p(),h(M.$$.fragment)},l(u){J=l(u,"P",{});var j=n(J);E=i(j,"Examples:"),j.forEach(s),T=c(u),f(M.$$.fragment,u)},m(u,j){d(u,J,j),t(J,E),d(u,T,j),g(M,u,j),U=!0},p:tp,i(u){U||(b(M.$$.fragment,u),U=!0)},o(u){w(M.$$.fragment,u),U=!1},d(u){u&&s(J),u&&s(T),y(M,u)}}}function rp(wt){let J,E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JTYwY3Jvc3NfYXR0ZW50aW9uX2d1aWRhbmNlX2Ftb3VudCU2MCUyMHRvJTIwMC4wMSUyMG9yJTIwbGVzcyUyMHRvJTIwYXZvaWQlMjBpbnB1dCUyMGxhdGVudCUyMGdyYWRpZW50JTIwZXhwbG9zaW9uJTBBJTBBaW1hZ2UlMjAlM0QlMjBwaXBlbGluZSglMEElMjAlMjAlMjAlMjBjYXB0aW9uJTJDJTBBJTIwJTIwJTIwJTIwc291cmNlX2VtYmVkcyUzRHNvdXJjZV9lbWJlZHMlMkMlMEElMjAlMjAlMjAlMjB0YXJnZXRfZW1iZWRzJTNEdGFyZ2V0X2VtYmVkcyUyQyUwQSUyMCUyMCUyMCUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMGNyb3NzX2F0dGVudGlvbl9ndWlkYW5jZV9hbW91bnQlM0QwLjE1JTJDJTBBJTIwJTIwJTIwJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTBBJTIwJTIwJTIwJTIwbGF0ZW50cyUzRGludl9sYXRlbnRzJTJDJTBBJTIwJTIwJTIwJTIwbmVnYXRpdmVfcHJvbXB0JTNEY2FwdGlvbiUyQyUwQSkuaW1hZ2VzJTVCMCU1RCUwQWltYWdlLnNhdmUoJTIyZWRpdGVkX2ltYWdlLnBuZyUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BlipForConditionalGeneration, BlipProcessor
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, DDIMInverseScheduler, StableDiffusionPix2PixZeroPipeline

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<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>captioner_id = <span class="hljs-string">&quot;Salesforce/blip-image-captioning-base&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>processor = BlipProcessor.from_pretrained(captioner_id)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = BlipForConditionalGeneration.from_pretrained(
<span class="hljs-meta">... </span>    captioner_id, torch_dtype=torch.float16, low_cpu_mem_usage=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>sd_model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
<span class="hljs-meta">... </span>    sd_model_ckpt,
<span class="hljs-meta">... </span>    caption_generator=model,
<span class="hljs-meta">... </span>    caption_processor=processor,
<span class="hljs-meta">... </span>    torch_dtype=torch.float16,
<span class="hljs-meta">... </span>    safety_checker=<span class="hljs-literal">None</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.enable_model_cpu_offload()

<span class="hljs-meta">&gt;&gt;&gt; </span>img_url = <span class="hljs-string">&quot;https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/test_images/cats/cat_6.png&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>raw_image = Image.<span class="hljs-built_in">open</span>(requests.get(img_url, stream=<span class="hljs-literal">True</span>).raw).convert(<span class="hljs-string">&quot;RGB&quot;</span>).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># generate caption</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>caption = pipeline.generate_caption(raw_image)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># &quot;a photography of a cat with flowers and dai dai daie - daie - daie kasaii&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inv_latents = pipeline.invert(caption, image=raw_image).latents
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># we need to generate source and target embeds</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>source_prompts = [<span class="hljs-string">&quot;a cat sitting on the street&quot;</span>, <span class="hljs-string">&quot;a cat playing in the field&quot;</span>, <span class="hljs-string">&quot;a face of a cat&quot;</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>target_prompts = [<span class="hljs-string">&quot;a dog sitting on the street&quot;</span>, <span class="hljs-string">&quot;a dog playing in the field&quot;</span>, <span class="hljs-string">&quot;a face of a dog&quot;</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>source_embeds = pipeline.get_embeds(source_prompts)
<span class="hljs-meta">&gt;&gt;&gt; </span>target_embeds = pipeline.get_embeds(target_prompts)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># the latents can then be used to edit a real image</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># when using Stable Diffusion 2 or other models that use v-prediction</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># set \`cross_attention_guidance_amount\` to 0.01 or less to avoid input latent gradient explosion</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipeline(
<span class="hljs-meta">... </span>    caption,
<span class="hljs-meta">... </span>    source_embeds=source_embeds,
<span class="hljs-meta">... </span>    target_embeds=target_embeds,
<span class="hljs-meta">... </span>    num_inference_steps=<span class="hljs-number">50</span>,
<span class="hljs-meta">... </span>    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
<span class="hljs-meta">... </span>    generator=generator,
<span class="hljs-meta">... </span>    latents=inv_latents,
<span class="hljs-meta">... </span>    negative_prompt=caption,
<span class="hljs-meta">... </span>).images[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>image.save(<span class="hljs-string">&quot;edited_image.png&quot;</span>)`}}),{c(){J=a("p"),E=o("Examples:"),T=p(),h(M.$$.fragment)},l(u){J=l(u,"P",{});var j=n(J);E=i(j,"Examples:"),j.forEach(s),T=c(u),f(M.$$.fragment,u)},m(u,j){d(u,J,j),t(J,E),d(u,T,j),g(M,u,j),U=!0},p:tp,i(u){U||(b(M.$$.fragment,u),U=!0)},o(u){w(M.$$.fragment,u),U=!1},d(u){u&&s(J),u&&s(T),y(M,u)}}}function pp(wt){let J,E,T,M,U,u,j,Ht,il,qs,S,te,At,Je,rl,qt,pl,Ls,_e,Te,cl,dl,Os,yt,ml,Ks,Mt,Lt,ul,ea,Jt,hl,ta,B,_t,ve,fl,gl,bl,Tt,je,wl,yl,Ml,vt,Ze,Jl,_l,Tl,jt,Ue,vl,jl,sa,Y,se,Ot,Ie,Zl,Kt,Ul,aa,Z,es,Il,xl,x,Gl,ts,El,Bl,ss,Wl,kl,as,Xl,Rl,ls,Pl,Vl,Nl,$,Cl,ns,Sl,Yl,os,$l,Fl,zl,Zt,Dl,xe,F,Ql,is,Hl,Al,rs,ql,Ll,Ol,ps,Kl,en,Ge,tn,Ee,sn,an,ln,X,nn,cs,on,rn,ds,pn,cn,Ut,dn,mn,la,z,ae,ms,Be,un,us,hn,na,le,hs,D,fs,fn,gn,gs,bn,wn,It,yn,Mn,bs,Q,ws,We,Jn,_n,ys,Ms,Tn,vn,xt,ke,jn,oa,H,ne,Js,Xe,Zn,_s,Un,ia,A,oe,Ts,Re,In,vs,xn,ra,Pe,pa,q,ie,js,Ve,Gn,Zs,En,ca,re,Bn,Us,Wn,kn,da,Gt,Xn,ma,Ne,ua,Et,Rn,ha,Ce,fa,Bt,Pn,ga,Se,ba,Wt,Vn,wa,Ye,ya,L,pe,Is,$e,Nn,xs,C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jAlMjAlMjBkb3dubG9hZCh1cmwlMkMlMjB1cmwuc3BsaXQoJTIyJTJGJTIyKSU1Qi0xJTVEKSUwQSUwQXNyY19lbWJlZHMlMjAlM0QlMjB0b3JjaC5sb2FkKHNyY19lbWJzX3VybC5zcGxpdCglMjIlMkYlMjIpJTVCLTElNUQpJTBBdGFyZ2V0X2VtYmVkcyUyMCUzRCUyMHRvcmNoLmxvYWQodGFyZ2V0X2VtYnNfdXJsLnNwbGl0KCUyMiUyRiUyMiklNUItMSU1RCklMEElMEFpbWFnZXMlMjAlM0QlMjBwaXBlbGluZSglMEElMjAlMjAlMjAlMjBwcm9tcHQlMkMlMEElMjAlMjAlMjAlMjBzb3VyY2VfZW1iZWRzJTNEc3JjX2VtYmVkcyUyQyUwQSUyMCUyMCUyMCUyMHRhcmdldF9lbWJlZHMlM0R0YXJnZXRfZW1iZWRzJTJDJTBBJTIwJTIwJTIwJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDUwJTJDJTBBJTIwJTIwJTIwJTIwY3Jvc3NfYXR0ZW50aW9uX2d1aWRhbmNlX2Ftb3VudCUzRDAuMTUlMkMlMEEpLmltYWdlcyUwQWltYWdlcyU1QjAlNUQuc2F2ZSglMjJlZGl0ZWRfaW1hZ2VfZG9nLnBuZyUyMik=",highlighted:`<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, StableDiffusionPix2PixZeroPipeline


<span class="hljs-keyword">def</span> <span class="hljs-title function_">download</span>(<span class="hljs-params">embedding_url, local_filepath</span>):
    r = requests.get(embedding_url)
    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(local_filepath, <span class="hljs-string">&quot;wb&quot;</span>) <span class="hljs-keyword">as</span> f:
        f.write(r.content)


model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    model_ckpt, conditions_input_image=<span class="hljs-literal">False</span>, torch_dtype=torch.float16
)
pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)

prompt = <span class="hljs-string">&quot;a high resolution painting of a cat in the style of van gogh&quot;</span>
src_embs_url = <span class="hljs-string">&quot;https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/embeddings_sd_1.4/cat.pt&quot;</span>
target_embs_url = <span class="hljs-string">&quot;https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/embeddings_sd_1.4/dog.pt&quot;</span>

<span class="hljs-keyword">for</span> url <span class="hljs-keyword">in</span> [src_embs_url, target_embs_url]:
    download(url, url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])

src_embeds = torch.load(src_embs_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])
target_embeds = torch.load(target_embs_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])

images = pipeline(
    prompt,
    source_embeds=src_embeds,
    target_embeds=target_embeds,
    num_inference_steps=<span class="hljs-number">50</span>,
    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
).images
images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;edited_image_dog.png&quot;</span>)`}}),Ve=new ee({}),Ne=new I({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQmxpcEZvckNvbmRpdGlvbmFsR2VuZXJhdGlvbiUyQyUyMEJsaXBQcm9jZXNzb3IlMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVNjaGVkdWxlciUyQyUyMERESU1JbnZlcnNlU2NoZWR1bGVyJTJDJTIwU3RhYmxlRGlmZnVzaW9uUGl4MlBpeFplcm9QaXBlbGluZSUwQSUwQWNhcHRpb25lcl9pZCUyMCUzRCUyMCUyMlNhbGVz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bG9hZCgp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BlipForConditionalGeneration, BlipProcessor
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, DDIMInverseScheduler, StableDiffusionPix2PixZeroPipeline

captioner_id = <span class="hljs-string">&quot;Salesforce/blip-image-captioning-base&quot;</span>
processor = BlipProcessor.from_pretrained(captioner_id)
model = BlipForConditionalGeneration.from_pretrained(captioner_id, torch_dtype=torch.float16, low_cpu_mem_usage=<span class="hljs-literal">True</span>)

sd_model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    sd_model_ckpt,
    caption_generator=model,
    caption_processor=processor,
    torch_dtype=torch.float16,
    safety_checker=<span class="hljs-literal">None</span>,
)
pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config)
pipeline.enable_model_cpu_offload()`}}),Ce=new I({props:{code:"aW1wb3J0JTIwcmVxdWVzdHMlMEFmcm9tJTIwUElMJTIwaW1wb3J0JTIwSW1hZ2UlMEElMEFpbWdfdXJsJTIwJTNEJTIwJTIyaHR0cHMlM0ElMkYlMkZnaXRodWIuY29tJTJGcGl4MnBpeHplcm8lMkZwaXgycGl4LXplcm8lMkZyYXclMkZtYWluJTJGYXNzZXRzJTJGdGVzdF9pbWFnZXMlMkZjYXRzJTJGY2F0XzYucG5nJTIyJTBBcmF3X2ltYWdlJTIwJTNEJTIwSW1hZ2Uub3BlbihyZXF1ZXN0cy5nZXQoaW1nX3VybCUyQyUyMHN0cmVhbSUzRFRydWUpLnJhdykuY29udmVydCglMjJSR0IlMjIpLnJlc2l6ZSgoNTEyJTJDJTIwNTEyKSklMEFjYXB0aW9uJTIwJTNEJTIwcGlwZWxpbmUuZ2VuZXJhdGVfY2FwdGlvbihyYXdfaW1hZ2Up",highlighted:`<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

img_url = <span class="hljs-string">&quot;https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/test_images/cats/cat_6.png&quot;</span>
raw_image = Image.<span class="hljs-built_in">open</span>(requests.get(img_url, stream=<span class="hljs-literal">True</span>).raw).convert(<span class="hljs-string">&quot;RGB&quot;</span>).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
caption = pipeline.generate_caption(raw_image)`}}),Se=new I({props:{code:"Z2VuZXJhdG9yJTIwJTNEJTIwdG9yY2gubWFudWFsX3NlZWQoMCklMEFpbnZfbGF0ZW50cyUyMCUzRCUyMHBpcGVsaW5lLmludmVydChjYXB0aW9uJTJDJTIwaW1hZ2UlM0RyYXdfaW1hZ2UlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IpLmxhdGVudHM=",highlighted:`generator = torch.manual_seed(<span class="hljs-number">0</span>)
inv_latents = pipeline.invert(caption, image=raw_image, generator=generator).latents`}}),Ye=new I({props:{code:"JTIzJTIwU2VlJTIwdGhlJTIwJTIyR2VuZXJhdGluZyUyMHNvdXJjZSUyMGFuZCUyMHRhcmdldCUyMGVtYmVkZGluZ3MlMjIlMjBzZWN0aW9uJTIwYmVsb3clMjB0byUwQSUyMyUyMGF1dG9tYXRlJTIwdGhlJTIwZ2VuZXJhdGlvbiUyMG9mJTIwdGhlc2UlMjBjYXB0aW9ucyUyMHdpdGglMjBhJTIwcHJlLXRyYWluZWQlMjBtb2RlbCUyMGxpa2UlMjBGbGFuLVQ1JTIwYXMlMjBleHBsYWluZWQlMjBiZWxvdy4lMEFzb3VyY2VfcHJvbXB0cyUyMCUzRCUyMCU1QiUyMmElMjBjYXQlMjBzaXR0aW5nJTIwb24lMjB0aGUlMjBzdHJlZXQlMjIlMkMlMjAlMjJhJTIwY2F0JTIwcGxheWluZyUyMGluJTIwdGhlJTIwZmllbGQlM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ighted:`<span class="hljs-comment"># See the &quot;Generating source and target embeddings&quot; section below to</span>
<span class="hljs-comment"># automate the generation of these captions with a pre-trained model like Flan-T5 as explained below.</span>
source_prompts = [<span class="hljs-string">&quot;a cat sitting on the street&quot;</span>, <span class="hljs-string">&quot;a cat playing in the field&quot;</span>, <span class="hljs-string">&quot;a face of a cat&quot;</span>]
target_prompts = [<span class="hljs-string">&quot;a dog sitting on the street&quot;</span>, <span class="hljs-string">&quot;a dog playing in the field&quot;</span>, <span class="hljs-string">&quot;a face of a dog&quot;</span>]

source_embeds = pipeline.get_embeds(source_prompts, batch_size=<span class="hljs-number">2</span>)
target_embeds = pipeline.get_embeds(target_prompts, batch_size=<span class="hljs-number">2</span>)


image = pipeline(
    caption,
    source_embeds=source_embeds,
    target_embeds=target_embeds,
    num_inference_steps=<span class="hljs-number">50</span>,
    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
    generator=generator,
    latents=inv_latents,
    negative_prompt=caption,
).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;edited_image.png&quot;</span>)`}}),$e=new ee({}),He=new I({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMFQ1Rm9yQ29uZGl0aW9uYWxHZW5lcmF0aW9uJTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQoJTIyZ29vZ2xlJTJGZmxhbi10NS14bCUyMiklMEFtb2RlbCUyMCUzRCUyMFQ1Rm9yQ29uZGl0aW9uYWxHZW5lcmF0aW9uLmZyb21fcHJldHJhaW5lZCglMjJnb29nbGUlMkZmbGFuLXQ1LXhsJTIyJTJDJTIwZGV2aWNlX21hcCUzRCUyMmF1dG8lMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, T5ForConditionalGeneration

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;google/flan-t5-xl&quot;</span>)
model = T5ForConditionalGeneration.from_pretrained(<span class="hljs-string">&quot;google/flan-t5-xl&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>, torch_dtype=torch.float16)`}}),qe=new I({props:{code:"c291cmNlX2NvbmNlcHQlMjAlM0QlMjAlMjJjYXQlMjIlMEF0YXJnZXRfY29uY2VwdCUyMCUzRCUyMCUyMmRvZyUyMiUwQSUwQXNvdXJjZV90ZXh0JTIwJTNEJTIwZiUyMlByb3ZpZGUlMjBhJTIwY2FwdGlvbiUyMGZvciUyMGltYWdlcyUyMGNvbnRhaW5pbmclMjBhJTIwJTdCc291cmNlX2NvbmNlcHQlN0QuJTIwJTIyJTBBJTIyVGhlJTIwY2FwdGlvbnMlMjBzaG91bGQlMjBiZSUyMGluJTIwRW5nbGlzaCUyMGFuZCUyMHNob3VsZCUyMGJlJTIwbm8lMjBsb25nZXIlMjB0aGFuJTIwMTUwJTIwY2hhcmFjdGVycy4lMjIlMEElMEF0YXJnZXRfdGV4dCUyMCUzRCUyMGYlMjJQcm92aWRlJTIwYSUyMGNhcHRpb24lMjBmb3IlMjBpbWFnZXMlMjBjb250YWluaW5nJTIwYSUyMCU3QnRhcmdldF9jb25jZXB0JTdELiUyMCUyMiUwQSUyMlRoZSUyMGNhcHRpb25zJTIwc2hvdWxkJTIwYmUlMjBpbiUyMEVuZ2xpc2glMjBhbmQlMjBzaG91bGQlMjBiZSUyMG5vJTIwbG9uZ2VyJTIwdGhhbiUyMDE1MCUyMGNoYXJhY3RlcnMuJTIy",highlighted:`source_concept = <span class="hljs-string">&quot;cat&quot;</span>
target_concept = <span class="hljs-string">&quot;dog&quot;</span>

source_text = <span class="hljs-string">f&quot;Provide a caption for images containing a <span class="hljs-subst">{source_concept}</span>. &quot;</span>
<span class="hljs-string">&quot;The captions should be in English and should be no longer than 150 characters.&quot;</span>

target_text = <span class="hljs-string">f&quot;Provide a caption for images containing a <span class="hljs-subst">{target_concept}</span>. &quot;</span>
<span class="hljs-string">&quot;The captions should be in English and should be no longer than 150 characters.&quot;</span>`}}),Oe=new I({props:{code:"ZGVmJTIwZ2VuZXJhdGVfY2FwdGlvbnMoaW5wdXRfcHJvbXB0KSUzQSUwQSUyMCUyMCUyMCUyMGlucHV0X2lkcyUyMCUzRCUyMHRva2VuaXplcihpbnB1dF9wcm9tcHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS5pbnB1dF9pZHMudG8oJTIyY3VkYSUyMiklMEElMEElMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW5wdXRfaWRzJTJDJTIwdGVtcGVyYXR1cmUlM0QwLjglMkMlMjBudW1fcmV0dXJuX3NlcXVlbmNlcyUzRDE2JTJDJTIwZG9fc2FtcGxlJTNEVHJ1ZSUyQyUyMG1heF9uZXdfdG9rZW5zJTNEMTI4JTJDJTIwdG9wX2slM0QxMCUwQSUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjB0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKG91dHB1dHMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSk=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_captions</span>(<span class="hljs-params">input_prompt</span>):
    input_ids = tokenizer(input_prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).input_ids.to(<span class="hljs-string">&quot;cuda&quot;</span>)

    outputs = model.generate(
        input_ids, temperature=<span class="hljs-number">0.8</span>, num_return_sequences=<span class="hljs-number">16</span>, do_sample=<span class="hljs-literal">True</span>, max_new_tokens=<span class="hljs-number">128</span>, top_k=<span class="hljs-number">10</span>
    )
    <span class="hljs-keyword">return</span> tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>)`}}),Ke=new I({props:{code:"c291cmNlX2NhcHRpb25zJTIwJTNEJTIwZ2VuZXJhdGVfY2FwdGlvbnMoc291cmNlX3RleHQpJTBBdGFyZ2V0X2NhcHRpb25zJTIwJTNEJTIwZ2VuZXJhdGVfY2FwdGlvbnModGFyZ2V0X2NvbmNlcHQp",highlighted:`source_captions = generate_captions(source_text)
target_captions = generate_captions(target_concept)`}}),st=new I({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpeDJQaXhaZXJvUGlwZWxpbmUlMjAlMEElMEFwaXBlbGluZSUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvblBpeDJQaXhaZXJvUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMEEpJTBBcGlwZWxpbmUlMjAlM0QlMjBwaXBlbGluZS50byglMjJjdWRhJTIyKSUwQXRva2VuaXplciUyMCUzRCUyMHBpcGVsaW5lLnRva2VuaXplciUwQXRleHRfZW5jb2RlciUyMCUzRCUyMHBpcGVsaW5lLnRleHRfZW5jb2Rlcg==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPix2PixZeroPipeline 

pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>, torch_dtype=torch.float16
)
pipeline = pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)
tokenizer = pipeline.tokenizer
text_encoder = pipeline.text_encoder`}}),lt=new I({props:{code:"aW1wb3J0JTIwdG9yY2glMjAlMEElMEFkZWYlMjBlbWJlZF9jYXB0aW9uc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pbnB1dHMuaW5wdXRfaWRzJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcHJvbXB0X2VtYmVkcyUyMCUzRCUyMHRleHRfZW5jb2Rlcih0ZXh0X2lucHV0X2lkcy50byhkZXZpY2UpJTJDJTIwYXR0ZW50aW9uX21hc2slM0ROb25lKSU1QjAlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBlbWJlZGRpbmdzLmFwcGVuZChwcm9tcHRfZW1iZWRzKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMHRvcmNoLmNvbmNhdGVuYXRlKGVtYmVkZGluZ3MlMkMlMjBkaW0lM0QwKS5tZWFuKGRpbSUzRDApLnVuc3F1ZWV6ZSgwKSUwQSUwQXNvdXJjZV9lbWJlZGRpbmdzJTIwJTNEJTIwZW1iZWRfY2FwdGlvbnMoc291cmNlX2NhcHRpb25zJTJDJTIwdG9rZW5pemVyJTJDJTIwdGV4dF9lbmNvZGVyKSUwQXRhcmdldF9lbWJlZGRpbmdzJTIwJTNEJTIwZW1iZWRfY2FwdGlvbnModGFyZ2V0X2NhcHRpb25zJTJDJTIwdG9rZW5pemVyJTJDJTIwdGV4dF9lbmNvZGVyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch 

<span class="hljs-keyword">def</span> <span class="hljs-title function_">embed_captions</span>(<span class="hljs-params">sentences, tokenizer, text_encoder, device=<span class="hljs-string">&quot;cuda&quot;</span></span>):
    <span class="hljs-keyword">with</span> torch.no_grad():
        embeddings = []
        <span class="hljs-keyword">for</span> sent <span class="hljs-keyword">in</span> sentences:
            text_inputs = tokenizer(
                sent,
                padding=<span class="hljs-string">&quot;max_length&quot;</span>,
                max_length=tokenizer.model_max_length,
                truncation=<span class="hljs-literal">True</span>,
                return_tensors=<span class="hljs-string">&quot;pt&quot;</span>,
            )
            text_input_ids = text_inputs.input_ids
            prompt_embeds = text_encoder(text_input_ids.to(device), attention_mask=<span class="hljs-literal">None</span>)[<span class="hljs-number">0</span>]
            embeddings.append(prompt_embeds)
    <span class="hljs-keyword">return</span> torch.concatenate(embeddings, dim=<span class="hljs-number">0</span>).mean(dim=<span class="hljs-number">0</span>).unsqueeze(<span class="hljs-number">0</span>)

source_embeddings = embed_captions(source_captions, tokenizer, text_encoder)
target_embeddings = embed_captions(target_captions, tokenizer, text_encoder)`}}),ot=new I({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERESU1TY2hlZHVsZXIlMEElMEFwaXBlbGluZS5zY2hlZHVsZXIlMjAlM0QlMjBERElNU2NoZWR1bGVyLmZyb21fY29uZmlnKHBpcGVsaW5lLnNjaGVkdWxlci5jb25maWcpJTBBJTBBaW1hZ2VzJTIwJTNEJTIwcGlwZWxpbmUoJTBBJTIwJTIwJTIwJTIwcHJvbXB0JTJDJTBBJTIwJTIwJTIwJTIwc291cmNlX2VtYmVkcyUzRHNvdXJjZV9lbWJlZGRpbmdzJTJDJTBBJTIwJTIwJTIwJTIwdGFyZ2V0X2VtYmVkcyUzRHRhcmdldF9lbWJlZGRpbmdzJTJDJTBBJTIwJTIwJTIwJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDUwJTJDJTBBJTIwJTIwJTIwJTIwY3Jvc3NfYXR0ZW50aW9uX2d1aWRhbmNlX2Ftb3VudCUzRDAuMTUlMkMlMEEpLmltYWdlcyUwQWltYWdlcyU1QjAlNUQuc2F2ZSglMjJlZGl0ZWRfaW1hZ2VfZG9nLnBuZyUyMik=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler

pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)

images = pipeline(
    prompt,
    source_embeds=source_embeddings,
    target_embeds=target_embeddings,
    num_inference_steps=<span class="hljs-number">50</span>,
    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
).images
images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;edited_image_dog.png&quot;</span>)`}}),it=new ee({}),rt=new bt({props:{name:"class diffusers.StableDiffusionPix2PixZeroPipeline",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": CLIPTextModel"},{name:"tokenizer",val:": CLIPTokenizer"},{name:"unet",val:": UNet2DConditionModel"},{name:"scheduler",val:": typing.Union[diffusers.schedulers.scheduling_ddpm.DDPMScheduler, diffusers.schedulers.scheduling_ddim.DDIMScheduler, diffusers.schedulers.scheduling_euler_ancestral_discrete.EulerAncestralDiscreteScheduler, diffusers.schedulers.scheduling_lms_discrete.LMSDiscreteScheduler]"},{name:"feature_extractor",val:": CLIPImageProcessor"},{name:"safety_checker",val:": StableDiffusionSafetyChecker"},{name:"inverse_scheduler",val:": DDIMInverseScheduler"},{name:"caption_generator",val:": BlipForConditionalGeneration"},{name:"caption_processor",val:": BlipProcessor"},{name:"requires_safety_checker",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/v0.18.2/en/api/models/autoencoderkl#diffusers.AutoencoderKL">AutoencoderKL</a>) &#x2014;
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.`,name:"vae"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.text_encoder",description:`<strong>text_encoder</strong> (<code>CLIPTextModel</code>) &#x2014;
Frozen text-encoder. Stable Diffusion uses the text portion of
<a href="https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIP</a>, specifically
the <a href="https://huggingface.co/openai/clip-vit-large-patch14" rel="nofollow">clip-vit-large-patch14</a> variant.`,name:"text_encoder"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.tokenizer",description:`<strong>tokenizer</strong> (<code>CLIPTokenizer</code>) &#x2014;
Tokenizer of class
<a href="https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>.`,name:"tokenizer"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/v0.18.2/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/v0.18.2/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to denoise the encoded image latents. Can be one of
<a href="/docs/diffusers/v0.18.2/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/v0.18.2/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, <a href="/docs/diffusers/v0.18.2/en/api/schedulers/euler_ancestral#diffusers.EulerAncestralDiscreteScheduler">EulerAncestralDiscreteScheduler</a>, or <a href="/docs/diffusers/v0.18.2/en/api/schedulers/ddpm#diffusers.DDPMScheduler">DDPMScheduler</a>.`,name:"scheduler"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.safety_checker",description:`<strong>safety_checker</strong> (<code>StableDiffusionSafetyChecker</code>) &#x2014;
Classification module that estimates whether generated images could be considered offensive or harmful.
Please, refer to the <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5" rel="nofollow">model card</a> for details.`,name:"safety_checker"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.feature_extractor",description:`<strong>feature_extractor</strong> (<code>CLIPImageProcessor</code>) &#x2014;
Model that extracts features from generated images to be used as inputs for the <code>safety_checker</code>.`,name:"feature_extractor"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.requires_safety_checker",description:`<strong>requires_safety_checker</strong> (bool) &#x2014;
Whether the pipeline requires a safety checker. We recommend setting it to True if you&#x2019;re using the
pipeline publicly.`,name:"requires_safety_checker"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.2/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L285"}}),ct=new bt({props:{name:"__call__",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[typing.List[str], str, NoneType] = None"},{name:"source_embeds",val:": Tensor = None"},{name:"target_embeds",val:": Tensor = None"},{name:"height",val:": typing.Optional[int] = None"},{name:"width",val:": typing.Optional[int] = None"},{name:"num_inference_steps",val:": int = 50"},{name:"guidance_scale",val:": float = 7.5"},{name:"negative_prompt",val:": typing.Union[typing.List[str], str, NoneType] = None"},{name:"num_images_per_prompt",val:": typing.Optional[int] = 1"},{name:"eta",val:": float = 0.0"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"negative_prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"cross_attention_guidance_amount",val:": float = 0.1"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"callback",val:": typing.Union[typing.Callable[[int, int, torch.FloatTensor], NoneType], NoneType] = None"},{name:"callback_steps",val:": typing.Optional[int] = 1"},{name:"cross_attention_kwargs",val:": typing.Union[typing.Dict[str, typing.Any], NoneType] = None"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the image generation. If not defined, one has to pass <code>prompt_embeds</code>.
instead.`,name:"prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.source_embeds",description:`<strong>source_embeds</strong> (<code>torch.Tensor</code>) &#x2014;
Source concept embeddings. Generation of the embeddings as per the <a href="https://arxiv.org/abs/2302.03027" rel="nofollow">original
paper</a>. Used in discovering the edit direction.`,name:"source_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.target_embeds",description:`<strong>target_embeds</strong> (<code>torch.Tensor</code>) &#x2014;
Target concept embeddings. Generation of the embeddings as per the <a href="https://arxiv.org/abs/2302.03027" rel="nofollow">original
paper</a>. Used in discovering the edit direction.`,name:"target_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.height",description:`<strong>height</strong> (<code>int</code>, <em>optional</em>, defaults to self.unet.config.sample_size * self.vae_scale_factor) &#x2014;
The height in pixels of the generated image.`,name:"height"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.width",description:`<strong>width</strong> (<code>int</code>, <em>optional</em>, defaults to self.unet.config.sample_size * self.vae_scale_factor) &#x2014;
The width in pixels of the generated image.`,name:"width"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 7.5) &#x2014;
Guidance scale as defined in <a href="https://arxiv.org/abs/2207.12598" rel="nofollow">Classifier-Free Diffusion Guidance</a>.
<code>guidance_scale</code> is defined as <code>w</code> of equation 2. of <a href="https://arxiv.org/pdf/2205.11487.pdf" rel="nofollow">Imagen
Paper</a>. Guidance scale is enabled by setting <code>guidance_scale &gt; 1</code>. Higher guidance scale encourages to generate images that are closely linked to the text <code>prompt</code>,
usually at the expense of lower image quality.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.negative_prompt",description:`<strong>negative_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts not to guide the image generation. If not defined, one has to pass
<code>negative_prompt_embeds</code> instead. Ignored when not using guidance (i.e., ignored if <code>guidance_scale</code> is
less than <code>1</code>).`,name:"negative_prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of images to generate per prompt.`,name:"num_images_per_prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.eta",description:`<strong>eta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Corresponds to parameter eta (&#x3B7;) in the DDIM paper: <a href="https://arxiv.org/abs/2010.02502" rel="nofollow">https://arxiv.org/abs/2010.02502</a>. Only applies to
<a href="/docs/diffusers/v0.18.2/en/api/schedulers/ddim#diffusers.DDIMScheduler">schedulers.DDIMScheduler</a>, will be ignored for others.`,name:"eta"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code> or <code>List[torch.Generator]</code>, <em>optional</em>) &#x2014;
One or a list of <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">torch generator(s)</a>
to make generation deterministic.`,name:"generator"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random <code>generator</code>.`,name:"latents"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting. If not
provided, text embeddings will be generated from <code>prompt</code> input argument.`,name:"prompt_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.negative_prompt_embeds",description:`<strong>negative_prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt
weighting. If not provided, negative_prompt_embeds will be generated from <code>negative_prompt</code> input
argument.`,name:"negative_prompt_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.cross_attention_guidance_amount",description:`<strong>cross_attention_guidance_amount</strong> (<code>float</code>, defaults to 0.1) &#x2014;
Amount of guidance needed from the reference cross-attention maps.`,name:"cross_attention_guidance_amount"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generate image. Choose between
<a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow">PIL</a>: <code>PIL.Image.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/v0.18.2/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.callback",description:`<strong>callback</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
A function that will be called every <code>callback_steps</code> steps during inference. The function will be
called with the following arguments: <code>callback(step: int, timestep: int, latents: torch.FloatTensor)</code>.`,name:"callback"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.callback_steps",description:`<strong>callback_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The frequency at which the <code>callback</code> function will be called. If not specified, the callback will be
called at every step.`,name:"callback_steps"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.2/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L820",returnDescription:`
<p><a
  href="/docs/diffusers/v0.18.2/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> if <code>return_dict</code> is True, otherwise a <code>tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of </code>bool<code>s denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) content, according to the </code>safety_checker\`.</p>
`,returnType:`
<p><a
  href="/docs/diffusers/v0.18.2/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),me=new ep({props:{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.example",$$slots:{default:[ip]},$$scope:{ctx:wt}}}),dt=new bt({props:{name:"construct_direction",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.construct_direction",parameters:[{name:"embs_source",val:": Tensor"},{name:"embs_target",val:": Tensor"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.2/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L710"}}),mt=new bt({props:{name:"enable_model_cpu_offload",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.enable_model_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.2/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L397"}}),ut=new bt({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.enable_sequential_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.2/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L372"}}),ht=new bt({props:{name:"generate_caption",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.generate_caption",parameters:[{name:"images",val:""}],source:"https://github.com/huggingface/diffusers/blob/v0.18.2/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L690"}}),ft=new bt({props:{name:"invert",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert",parameters:[{name:"prompt",val:": typing.Optional[str] = None"},{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image, numpy.ndarray, typing.List[torch.FloatTensor], typing.List[PIL.Image.Image], typing.List[numpy.ndarray]] = None"},{name:"num_inference_steps",val:": int = 50"},{name:"guidance_scale",val:": float = 1"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"cross_attention_guidance_amount",val:": float = 0.1"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"callback",val:": typing.Union[typing.Callable[[int, int, torch.FloatTensor], NoneType], NoneType] = None"},{name:"callback_steps",val:": typing.Optional[int] = 1"},{name:"cross_attention_kwargs",val:": typing.Union[typing.Dict[str, typing.Any], NoneType] = None"},{name:"lambda_auto_corr",val:": float = 20.0"},{name:"lambda_kl",val:": float = 20.0"},{name:"num_reg_steps",val:": int = 5"},{name:"num_auto_corr_rolls",val:": int = 5"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the image generation. If not defined, one has to pass <code>prompt_embeds</code>.
instead.`,name:"prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.image",description:`<strong>image</strong> (<code>torch.FloatTensor</code> <code>np.ndarray</code>, <code>PIL.Image.Image</code>, <code>List[torch.FloatTensor]</code>, <code>List[PIL.Image.Image]</code>, or <code>List[np.ndarray]</code>) &#x2014;
<code>Image</code>, or tensor representing an image batch which will be used for conditioning. Can also accpet
image latents as <code>image</code>, if passing latents directly, it will not be encoded again.`,name:"image"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 1) &#x2014;
Guidance scale as defined in <a href="https://arxiv.org/abs/2207.12598" rel="nofollow">Classifier-Free Diffusion Guidance</a>.
<code>guidance_scale</code> is defined as <code>w</code> of equation 2. of <a href="https://arxiv.org/pdf/2205.11487.pdf" rel="nofollow">Imagen
Paper</a>. Guidance scale is enabled by setting <code>guidance_scale &gt; 1</code>. Higher guidance scale encourages to generate images that are closely linked to the text <code>prompt</code>,
usually at the expense of lower image quality.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.generator",description:`<strong>generator</strong> (<code>torch.Generator</code> or <code>List[torch.Generator]</code>, <em>optional</em>) &#x2014;
One or a list of <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">torch generator(s)</a>
to make generation deterministic.`,name:"generator"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random <code>generator</code>.`,name:"latents"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting. If not
provided, text embeddings will be generated from <code>prompt</code> input argument.`,name:"prompt_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.cross_attention_guidance_amount",description:`<strong>cross_attention_guidance_amount</strong> (<code>float</code>, defaults to 0.1) &#x2014;
Amount of guidance needed from the reference cross-attention maps.`,name:"cross_attention_guidance_amount"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generate image. Choose between
<a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow">PIL</a>: <code>PIL.Image.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/v0.18.2/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.callback",description:`<strong>callback</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
A function that will be called every <code>callback_steps</code> steps during inference. The function will be
called with the following arguments: <code>callback(step: int, timestep: int, latents: torch.FloatTensor)</code>.`,name:"callback"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.callback_steps",description:`<strong>callback_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The frequency at which the <code>callback</code> function will be called. If not specified, the callback will be
called at every step.`,name:"callback_steps"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.lambda_auto_corr",description:`<strong>lambda_auto_corr</strong> (<code>float</code>, <em>optional</em>, defaults to 20.0) &#x2014;
Lambda parameter to control auto correction`,name:"lambda_auto_corr"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.lambda_kl",description:`<strong>lambda_kl</strong> (<code>float</code>, <em>optional</em>, defaults to 20.0) &#x2014;
Lambda parameter to control Kullback&#x2013;Leibler divergence output`,name:"lambda_kl"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.num_reg_steps",description:`<strong>num_reg_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 5) &#x2014;
Number of regularization loss steps`,name:"num_reg_steps"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.num_auto_corr_rolls",description:`<strong>num_auto_corr_rolls</strong> (<code>int</code>, <em>optional</em>, defaults to 5) &#x2014;
Number of auto correction roll steps`,name:"num_auto_corr_rolls"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.2/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L1099",returnDescription:`
<p><code>Pix2PixInversionPipelineOutput</code> or
<code>tuple</code>:
<code>Pix2PixInversionPipelineOutput</code> if
<code>return_dict</code> is True, otherwise a \`tuple. When returning a tuple, the first element is the inverted
latents tensor and then second is the corresponding decoded image.</p>
`}}),be=new ep({props:{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.example",$$slots:{default:[rp]},$$scope:{ctx:wt}}}),{c(){J=a("meta"),E=p(),T=a("h1"),M=a("a"),U=a("span"),h(u.$$.fragment),j=p(),Ht=a("span"),il=o("Zero-shot Image-to-Image Translation"),qs=p(),S=a("h2"),te=a("a"),At=a("span"),h(Je.$$.fragment),rl=p(),qt=a("span"),pl=o("Overview"),Ls=p(),_e=a("p"),Te=a("a"),cl=o("Zero-shot Image-to-Image Translation"),dl=o("."),Os=p(),yt=a("p"),ml=o("The abstract of the paper is the following:"),Ks=p(),Mt=a("p"),Lt=a("em"),ul=o("Large-scale text-to-image generative models have shown their remarkable ability to synthesize diverse and high-quality images. However, it is still challenging to directly apply these models for editing real images for two reasons. First, it is hard for users to come up with a perfect text prompt that accurately describes every visual detail in the input image. Second, while existing models can introduce desirable changes in certain regions, they often dramatically alter the input content and introduce unexpected changes in unwanted regions. In this work, we propose pix2pix-zero, an image-to-image translation method that can preserve the content of the original image without manual prompting. We first automatically discover editing directions that reflect desired edits in the text embedding space. To preserve the general content structure after editing, we further propose cross-attention guidance, which aims to retain the cross-attention maps of the input image throughout the diffusion process. In addition, our method does not need additional training for these edits and can directly use the existing pre-trained text-to-image diffusion model. We conduct extensive experiments and show that our method outperforms existing and concurrent works for both real and synthetic image editing."),ea=p(),Jt=a("p"),hl=o("Resources:"),ta=p(),B=a("ul"),_t=a("li"),ve=a("a"),fl=o("Project Page"),gl=o("."),bl=p(),Tt=a("li"),je=a("a"),wl=o("Paper"),yl=o("."),Ml=p(),vt=a("li"),Ze=a("a"),Jl=o("Original Code"),_l=o("."),Tl=p(),jt=a("li"),Ue=a("a"),vl=o("Demo"),jl=o("."),sa=p(),Y=a("h2"),se=a("a"),Ot=a("span"),h(Ie.$$.fragment),Zl=p(),Kt=a("span"),Ul=o("Tips"),aa=p(),Z=a("ul"),es=a("li"),Il=o("The pipeline can be conditioned on real input images. Check out the code examples below to know more."),xl=p(),x=a("li"),Gl=o("The pipeline exposes two arguments namely "),ts=a("code"),El=o("source_embeds"),Bl=o(" and "),ss=a("code"),Wl=o("target_embeds"),kl=o(`
that let you control the direction of the semantic edits in the final image to be generated. Let\u2019s say,
you wanted to translate from \u201Ccat\u201D to \u201Cdog\u201D. In this case, the edit direction will be \u201Ccat -> dog\u201D. To reflect
this in the pipeline, you simply have to set the embeddings related to the phrases including \u201Ccat\u201D to
`),as=a("code"),Xl=o("source_embeds"),Rl=o(" and \u201Cdog\u201D to "),ls=a("code"),Pl=o("target_embeds"),Vl=o(". Refer to the code example below for more details."),Nl=p(),$=a("li"),Cl=o("When you\u2019re using this pipeline from a prompt, specify the "),ns=a("em"),Sl=o("source"),Yl=o(` concept in the prompt. Taking
the above example, a valid input prompt would be: \u201Ca high resolution painting of a `),os=a("strong"),$l=o("cat"),Fl=o(" in the style of van gough\u201D."),zl=p(),Zt=a("li"),Dl=o("If you wanted to reverse the direction in the example above, i.e., \u201Cdog -> cat\u201D, then it\u2019s recommended to:"),xe=a("ul"),F=a("li"),Ql=o("Swap the "),is=a("code"),Hl=o("source_embeds"),Al=o(" and "),rs=a("code"),ql=o("target_embeds"),Ll=o("."),Ol=p(),ps=a("li"),Kl=o("Change the input prompt to include \u201Cdog\u201D."),en=p(),Ge=a("li"),tn=o("To learn more about how the source and target embeddings are generated, refer to the "),Ee=a("a"),sn=o(`original
paper`),an=o(". Below, we also provide some directions on how to generate the embeddings."),ln=p(),X=a("li"),nn=o("Note that the quality of the outputs generated with this pipeline is dependent on how good the "),cs=a("code"),on=o("source_embeds"),rn=o(" and "),ds=a("code"),pn=o("target_embeds"),cn=o(" are. Please, refer to "),Ut=a("a"),dn=o("this discussion"),mn=o(" for some suggestions on the topic."),la=p(),z=a("h2"),ae=a("a"),ms=a("span"),h(Be.$$.fragment),un=p(),us=a("span"),hn=o("Available Pipelines:"),na=p(),le=a("table"),hs=a("thead"),D=a("tr"),fs=a("th"),fn=o("Pipeline"),gn=p(),gs=a("th"),bn=o("Tasks"),wn=p(),It=a("th"),yn=o("Demo"),Mn=p(),bs=a("tbody"),Q=a("tr"),ws=a("td"),We=a("a"),Jn=o("StableDiffusionPix2PixZeroPipeline"),_n=p(),ys=a("td"),Ms=a("em"),Tn=o("Text-Based Image Editing"),vn=p(),xt=a("td"),ke=a("a"),jn=o("\u{1F917} Space"),oa=p(),H=a("h2"),ne=a("a"),Js=a("span"),h(Xe.$$.fragment),Zn=p(),_s=a("span"),Un=o("Usage example"),ia=p(),A=a("h3"),oe=a("a"),Ts=a("span"),h(Re.$$.fragment),In=p(),vs=a("span"),xn=o("Based on an image generated with the input prompt"),ra=p(),h(Pe.$$.fragment),pa=p(),q=a("h3"),ie=a("a"),js=a("span"),h(Ve.$$.fragment),Gn=p(),Zs=a("span"),En=o("Based on an input image"),ca=p(),re=a("p"),Bn=o(`When the pipeline is conditioned on an input image, we first obtain an inverted
noise from it using a `),Us=a("code"),Wn=o("DDIMInverseScheduler"),kn=o(` with the help of a generated caption. Then
the inverted noise is used to start the generation process.`),da=p(),Gt=a("p"),Xn=o("First, let\u2019s load our pipeline:"),ma=p(),h(Ne.$$.fragment),ua=p(),Et=a("p"),Rn=o("Then, we load an input image for conditioning and obtain a suitable caption for it:"),ha=p(),h(Ce.$$.fragment),fa=p(),Bt=a("p"),Pn=o("Then we employ the generated caption and the input image to get the inverted noise:"),ga=p(),h(Se.$$.fragment),ba=p(),Wt=a("p"),Vn=o("Now, generate the image with edit directions:"),wa=p(),h(Ye.$$.fragment),ya=p(),L=a("h2"),pe=a("a"),Is=a("span"),h($e.$$.fragment),Nn=p(),xs=a("span"),Cn=o("Generating source and target embeddings"),Ma=p(),W=a("p"),Sn=o("The authors originally used the "),Fe=a("a"),Yn=o("GPT-3 API"),$n=o(` to generate the source and target captions for discovering
edit directions. However, we can also leverage open source and public models for the same purpose.
Below, we provide an end-to-end example with the `),ze=a("a"),Fn=o("Flan-T5"),zn=o(` model
for generating captions and `),De=a("a"),Dn=o("CLIP"),Qn=o(` for
computing embeddings on the generated captions.`),Ja=p(),Qe=a("p"),Gs=a("strong"),Hn=o("1. Load the generation model"),An=o(":"),_a=p(),h(He.$$.fragment),Ta=p(),Ae=a("p"),Es=a("strong"),qn=o("2. Construct a starting prompt"),Ln=o(":"),va=p(),h(qe.$$.fragment),ja=p(),kt=a("p"),On=o("Here, we\u2019re interested in the \u201Ccat -> dog\u201D direction."),Za=p(),Le=a("p"),Bs=a("strong"),Kn=o("3. Generate captions"),eo=o(":"),Ua=p(),Xt=a("p"),to=o("We can use a utility like so for this purpose."),Ia=p(),h(Oe.$$.fragment),xa=p(),Rt=a("p"),so=o("And then we just call it to generate our captions:"),Ga=p(),h(Ke.$$.fragment),Ea=p(),R=a("p"),ao=o(`We encourage you to play around with the different parameters supported by the
`),Ws=a("code"),lo=o("generate()"),no=o(" method ("),et=a("a"),oo=o("documentation"),io=o(") for the generation quality you are looking for."),Ba=p(),tt=a("p"),ks=a("strong"),ro=o("4. Load the embedding model"),po=o(":"),Wa=p(),Pt=a("p"),co=o("Here, we need to use the same text encoder model used by the subsequent Stable Diffusion model."),ka=p(),h(st.$$.fragment),Xa=p(),at=a("p"),Xs=a("strong"),mo=o("5. Compute embeddings"),uo=o(":"),Ra=p(),h(lt.$$.fragment),Pa=p(),ce=a("p"),ho=o("And you\u2019re done! "),nt=a("a"),fo=o("Here"),go=o(" is a Colab Notebook that you can use to interact with the entire process."),Va=p(),Vt=a("p"),bo=o("Now, you can use these embeddings directly while calling the pipeline:"),Na=p(),h(ot.$$.fragment),Ca=p(),O=a("h2"),de=a("a"),Rs=a("span"),h(it.$$.fragment),wo=p(),Ps=a("span"),yo=o("StableDiffusionPix2PixZeroPipeline"),Sa=p(),_=a("div"),h(rt.$$.fragment),Mo=p(),Vs=a("p"),Jo=o("Pipeline for pixel-levl image editing using Pix2Pix Zero. Based on Stable Diffusion."),_o=p(),pt=a("p"),To=o("This model inherits from "),Nt=a("a"),vo=o("DiffusionPipeline"),jo=o(`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),Zo=p(),P=a("div"),h(ct.$$.fragment),Uo=p(),Ns=a("p"),Io=o("Function invoked when calling the pipeline for generation."),xo=p(),h(me.$$.fragment),Go=p(),ue=a("div"),h(dt.$$.fragment),Eo=p(),Cs=a("p"),Bo=o("Constructs the edit direction to steer the image generation process semantically."),Wo=p(),he=a("div"),h(mt.$$.fragment),ko=p(),G=a("p"),Xo=o(`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),Ss=a("code"),Ro=o("enable_sequential_cpu_offload"),Po=o(", this method moves one whole model at a time to the GPU when its "),Ys=a("code"),Vo=o("forward"),No=o(`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),$s=a("code"),Co=o("enable_sequential_cpu_offload"),So=o(", but performance is much better due to the iterative execution of the "),Fs=a("code"),Yo=o("unet"),$o=o("."),Fo=p(),fe=a("div"),h(ut.$$.fragment),zo=p(),K=a("p"),Do=o(`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),zs=a("code"),Qo=o("torch.device('meta') and loaded to GPU only when their specific submodule has its "),Ho=o("forward"),Ds=a("code"),Ao=o("method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),qo=o("enable_model_cpu_offload`, but performance is lower."),Lo=p(),ge=a("div"),h(ht.$$.fragment),Oo=p(),Qs=a("p"),Ko=o("Generates caption for a given image."),ei=p(),V=a("div"),h(ft.$$.fragment),ti=p(),Hs=a("p"),si=o("Function used to generate inverted latents given a prompt and image."),ai=p(),h(be.$$.fragment),this.h()},l(e){const r=np('[data-svelte="svelte-1phssyn"]',document.head);J=l(r,"META",{name:!0,content:!0}),r.forEach(s),E=c(e),T=l(e,"H1",{class:!0});var gt=n(T);M=l(gt,"A",{id:!0,class:!0,href:!0});var As=n(M);U=l(As,"SPAN",{});var fi=n(U);f(u.$$.fragment,fi),fi.forEach(s),As.forEach(s),j=c(gt),Ht=l(gt,"SPAN",{});var gi=n(Ht);il=i(gi,"Zero-shot Image-to-Image Translation"),gi.forEach(s),gt.forEach(s),qs=c(e),S=l(e,"H2",{class:!0});var $a=n(S);te=l($a,"A",{id:!0,class:!0,href:!0});var bi=n(te);At=l(bi,"SPAN",{});var wi=n(At);f(Je.$$.fragment,wi),wi.forEach(s),bi.forEach(s),rl=c($a),qt=l($a,"SPAN",{});var yi=n(qt);pl=i(yi,"Overview"),yi.forEach(s),$a.forEach(s),Ls=c(e),_e=l(e,"P",{});var li=n(_e);Te=l(li,"A",{href:!0,rel:!0});var Mi=n(Te);cl=i(Mi,"Zero-shot Image-to-Image Translation"),Mi.forEach(s),dl=i(li,"."),li.forEach(s),Os=c(e),yt=l(e,"P",{});var Ji=n(yt);ml=i(Ji,"The abstract of the paper is the following:"),Ji.forEach(s),Ks=c(e),Mt=l(e,"P",{});var _i=n(Mt);Lt=l(_i,"EM",{});var Ti=n(Lt);ul=i(Ti,"Large-scale text-to-image generative models have shown their remarkable ability to synthesize diverse and high-quality images. However, it is still challenging to directly apply these models for editing real images for two reasons. First, it is hard for users to come up with a perfect text prompt that accurately describes every visual detail in the input image. Second, while existing models can introduce desirable changes in certain regions, they often dramatically alter the input content and introduce unexpected changes in unwanted regions. In this work, we propose pix2pix-zero, an image-to-image translation method that can preserve the content of the original image without manual prompting. We first automatically discover editing directions that reflect desired edits in the text embedding space. To preserve the general content structure after editing, we further propose cross-attention guidance, which aims to retain the cross-attention maps of the input image throughout the diffusion process. In addition, our method does not need additional training for these edits and can directly use the existing pre-trained text-to-image diffusion model. We conduct extensive experiments and show that our method outperforms existing and concurrent works for both real and synthetic image editing."),Ti.forEach(s),_i.forEach(s),ea=c(e),Jt=l(e,"P",{});var vi=n(Jt);hl=i(vi,"Resources:"),vi.forEach(s),ta=c(e),B=l(e,"UL",{});var we=n(B);_t=l(we,"LI",{});var ni=n(_t);ve=l(ni,"A",{href:!0,rel:!0});var ji=n(ve);fl=i(ji,"Project Page"),ji.forEach(s),gl=i(ni,"."),ni.forEach(s),bl=c(we),Tt=l(we,"LI",{});var oi=n(Tt);je=l(oi,"A",{href:!0,rel:!0});var Zi=n(je);wl=i(Zi,"Paper"),Zi.forEach(s),yl=i(oi,"."),oi.forEach(s),Ml=c(we),vt=l(we,"LI",{});var ii=n(vt);Ze=l(ii,"A",{href:!0,rel:!0});var Ui=n(Ze);Jl=i(Ui,"Original Code"),Ui.forEach(s),_l=i(ii,"."),ii.forEach(s),Tl=c(we),jt=l(we,"LI",{});var ri=n(jt);Ue=l(ri,"A",{href:!0,rel:!0});var Ii=n(Ue);vl=i(Ii,"Demo"),Ii.forEach(s),jl=i(ri,"."),ri.forEach(s),we.forEach(s),sa=c(e),Y=l(e,"H2",{class:!0});var Fa=n(Y);se=l(Fa,"A",{id:!0,class:!0,href:!0});var xi=n(se);Ot=l(xi,"SPAN",{});var Gi=n(Ot);f(Ie.$$.fragment,Gi),Gi.forEach(s),xi.forEach(s),Zl=c(Fa),Kt=l(Fa,"SPAN",{});var Ei=n(Kt);Ul=i(Ei,"Tips"),Ei.forEach(s),Fa.forEach(s),aa=c(e),Z=l(e,"UL",{});var k=n(Z);es=l(k,"LI",{});var Bi=n(es);Il=i(Bi,"The pipeline can be conditioned on real input images. Check out the code examples below to know more."),Bi.forEach(s),xl=c(k),x=l(k,"LI",{});var N=n(x);Gl=i(N,"The pipeline exposes two arguments namely "),ts=l(N,"CODE",{});var Wi=n(ts);El=i(Wi,"source_embeds"),Wi.forEach(s),Bl=i(N," and "),ss=l(N,"CODE",{});var ki=n(ss);Wl=i(ki,"target_embeds"),ki.forEach(s),kl=i(N,`
that let you control the direction of the semantic edits in the final image to be generated. Let\u2019s say,
you wanted to translate from \u201Ccat\u201D to \u201Cdog\u201D. In this case, the edit direction will be \u201Ccat -> dog\u201D. To reflect
this in the pipeline, you simply have to set the embeddings related to the phrases including \u201Ccat\u201D to
`),as=l(N,"CODE",{});var Xi=n(as);Xl=i(Xi,"source_embeds"),Xi.forEach(s),Rl=i(N," and \u201Cdog\u201D to "),ls=l(N,"CODE",{});var Ri=n(ls);Pl=i(Ri,"target_embeds"),Ri.forEach(s),Vl=i(N,". Refer to the code example below for more details."),N.forEach(s),Nl=c(k),$=l(k,"LI",{});var Ct=n($);Cl=i(Ct,"When you\u2019re using this pipeline from a prompt, specify the "),ns=l(Ct,"EM",{});var Pi=n(ns);Sl=i(Pi,"source"),Pi.forEach(s),Yl=i(Ct,` concept in the prompt. Taking
the above example, a valid input prompt would be: \u201Ca high resolution painting of a `),os=l(Ct,"STRONG",{});var Vi=n(os);$l=i(Vi,"cat"),Vi.forEach(s),Fl=i(Ct," in the style of van gough\u201D."),Ct.forEach(s),zl=c(k),Zt=l(k,"LI",{});var pi=n(Zt);Dl=i(pi,"If you wanted to reverse the direction in the example above, i.e., \u201Cdog -> cat\u201D, then it\u2019s recommended to:"),xe=l(pi,"UL",{});var za=n(xe);F=l(za,"LI",{});var St=n(F);Ql=i(St,"Swap the "),is=l(St,"CODE",{});var Ni=n(is);Hl=i(Ni,"source_embeds"),Ni.forEach(s),Al=i(St," and "),rs=l(St,"CODE",{});var Ci=n(rs);ql=i(Ci,"target_embeds"),Ci.forEach(s),Ll=i(St,"."),St.forEach(s),Ol=c(za),ps=l(za,"LI",{});var Si=n(ps);Kl=i(Si,"Change the input prompt to include \u201Cdog\u201D."),Si.forEach(s),za.forEach(s),pi.forEach(s),en=c(k),Ge=l(k,"LI",{});var Da=n(Ge);tn=i(Da,"To learn more about how the source and target embeddings are generated, refer to the "),Ee=l(Da,"A",{href:!0,rel:!0});var Yi=n(Ee);sn=i(Yi,`original
paper`),Yi.forEach(s),an=i(Da,". Below, we also provide some directions on how to generate the embeddings."),Da.forEach(s),ln=c(k),X=l(k,"LI",{});var ye=n(X);nn=i(ye,"Note that the quality of the outputs generated with this pipeline is dependent on how good the "),cs=l(ye,"CODE",{});var $i=n(cs);on=i($i,"source_embeds"),$i.forEach(s),rn=i(ye," and "),ds=l(ye,"CODE",{});var Fi=n(ds);pn=i(Fi,"target_embeds"),Fi.forEach(s),cn=i(ye," are. Please, refer to "),Ut=l(ye,"A",{href:!0});var zi=n(Ut);dn=i(zi,"this discussion"),zi.forEach(s),mn=i(ye," for some suggestions on the topic."),ye.forEach(s),k.forEach(s),la=c(e),z=l(e,"H2",{class:!0});var Qa=n(z);ae=l(Qa,"A",{id:!0,class:!0,href:!0});var Di=n(ae);ms=l(Di,"SPAN",{});var Qi=n(ms);f(Be.$$.fragment,Qi),Qi.forEach(s),Di.forEach(s),un=c(Qa),us=l(Qa,"SPAN",{});var Hi=n(us);hn=i(Hi,"Available Pipelines:"),Hi.forEach(s),Qa.forEach(s),na=c(e),le=l(e,"TABLE",{});var Ha=n(le);hs=l(Ha,"THEAD",{});var Ai=n(hs);D=l(Ai,"TR",{});var Yt=n(D);fs=l(Yt,"TH",{});var qi=n(fs);fn=i(qi,"Pipeline"),qi.forEach(s),gn=c(Yt),gs=l(Yt,"TH",{});var Li=n(gs);bn=i(Li,"Tasks"),Li.forEach(s),wn=c(Yt),It=l(Yt,"TH",{align:!0});var Oi=n(It);yn=i(Oi,"Demo"),Oi.forEach(s),Yt.forEach(s),Ai.forEach(s),Mn=c(Ha),bs=l(Ha,"TBODY",{});var Ki=n(bs);Q=l(Ki,"TR",{});var $t=n(Q);ws=l($t,"TD",{});var er=n(ws);We=l(er,"A",{href:!0,rel:!0});var tr=n(We);Jn=i(tr,"StableDiffusionPix2PixZeroPipeline"),tr.forEach(s),er.forEach(s),_n=c($t),ys=l($t,"TD",{});var sr=n(ys);Ms=l(sr,"EM",{});var ar=n(Ms);Tn=i(ar,"Text-Based Image Editing"),ar.forEach(s),sr.forEach(s),vn=c($t),xt=l($t,"TD",{align:!0});var lr=n(xt);ke=l(lr,"A",{href:!0,rel:!0});var nr=n(ke);jn=i(nr,"\u{1F917} Space"),nr.forEach(s),lr.forEach(s),$t.forEach(s),Ki.forEach(s),Ha.forEach(s),oa=c(e),H=l(e,"H2",{class:!0});var Aa=n(H);ne=l(Aa,"A",{id:!0,class:!0,href:!0});var or=n(ne);Js=l(or,"SPAN",{});var ir=n(Js);f(Xe.$$.fragment,ir),ir.forEach(s),or.forEach(s),Zn=c(Aa),_s=l(Aa,"SPAN",{});var rr=n(_s);Un=i(rr,"Usage example"),rr.forEach(s),Aa.forEach(s),ia=c(e),A=l(e,"H3",{class:!0});var qa=n(A);oe=l(qa,"A",{id:!0,class:!0,href:!0});var pr=n(oe);Ts=l(pr,"SPAN",{});var cr=n(Ts);f(Re.$$.fragment,cr),cr.forEach(s),pr.forEach(s),In=c(qa),vs=l(qa,"SPAN",{});var dr=n(vs);xn=i(dr,"Based on an image generated with the input prompt"),dr.forEach(s),qa.forEach(s),ra=c(e),f(Pe.$$.fragment,e),pa=c(e),q=l(e,"H3",{class:!0});var La=n(q);ie=l(La,"A",{id:!0,class:!0,href:!0});var mr=n(ie);js=l(mr,"SPAN",{});var ur=n(js);f(Ve.$$.fragment,ur),ur.forEach(s),mr.forEach(s),Gn=c(La),Zs=l(La,"SPAN",{});var hr=n(Zs);En=i(hr,"Based on an input image"),hr.forEach(s),La.forEach(s),ca=c(e),re=l(e,"P",{});var Oa=n(re);Bn=i(Oa,`When the pipeline is conditioned on an input image, we first obtain an inverted
noise from it using a `),Us=l(Oa,"CODE",{});var fr=n(Us);Wn=i(fr,"DDIMInverseScheduler"),fr.forEach(s),kn=i(Oa,` with the help of a generated caption. Then
the inverted noise is used to start the generation process.`),Oa.forEach(s),da=c(e),Gt=l(e,"P",{});var gr=n(Gt);Xn=i(gr,"First, let\u2019s load our pipeline:"),gr.forEach(s),ma=c(e),f(Ne.$$.fragment,e),ua=c(e),Et=l(e,"P",{});var br=n(Et);Rn=i(br,"Then, we load an input image for conditioning and obtain a suitable caption for it:"),br.forEach(s),ha=c(e),f(Ce.$$.fragment,e),fa=c(e),Bt=l(e,"P",{});var wr=n(Bt);Pn=i(wr,"Then we employ the generated caption and the input image to get the inverted noise:"),wr.forEach(s),ga=c(e),f(Se.$$.fragment,e),ba=c(e),Wt=l(e,"P",{});var yr=n(Wt);Vn=i(yr,"Now, generate the image with edit directions:"),yr.forEach(s),wa=c(e),f(Ye.$$.fragment,e),ya=c(e),L=l(e,"H2",{class:!0});var Ka=n(L);pe=l(Ka,"A",{id:!0,class:!0,href:!0});var Mr=n(pe);Is=l(Mr,"SPAN",{});var Jr=n(Is);f($e.$$.fragment,Jr),Jr.forEach(s),Mr.forEach(s),Nn=c(Ka),xs=l(Ka,"SPAN",{});var _r=n(xs);Cn=i(_r,"Generating source and target embeddings"),_r.forEach(s),Ka.forEach(s),Ma=c(e),W=l(e,"P",{});var Me=n(W);Sn=i(Me,"The authors originally used the "),Fe=l(Me,"A",{href:!0,rel:!0});var Tr=n(Fe);Yn=i(Tr,"GPT-3 API"),Tr.forEach(s),$n=i(Me,` to generate the source and target captions for discovering
edit directions. However, we can also leverage open source and public models for the same purpose.
Below, we provide an end-to-end example with the `),ze=l(Me,"A",{href:!0,rel:!0});var vr=n(ze);Fn=i(vr,"Flan-T5"),vr.forEach(s),zn=i(Me,` model
for generating captions and `),De=l(Me,"A",{href:!0,rel:!0});var jr=n(De);Dn=i(jr,"CLIP"),jr.forEach(s),Qn=i(Me,` for
computing embeddings on the generated captions.`),Me.forEach(s),Ja=c(e),Qe=l(e,"P",{});var ci=n(Qe);Gs=l(ci,"STRONG",{});var Zr=n(Gs);Hn=i(Zr,"1. Load the generation model"),Zr.forEach(s),An=i(ci,":"),ci.forEach(s),_a=c(e),f(He.$$.fragment,e),Ta=c(e),Ae=l(e,"P",{});var di=n(Ae);Es=l(di,"STRONG",{});var Ur=n(Es);qn=i(Ur,"2. Construct a starting prompt"),Ur.forEach(s),Ln=i(di,":"),di.forEach(s),va=c(e),f(qe.$$.fragment,e),ja=c(e),kt=l(e,"P",{});var Ir=n(kt);On=i(Ir,"Here, we\u2019re interested in the \u201Ccat -> dog\u201D direction."),Ir.forEach(s),Za=c(e),Le=l(e,"P",{});var mi=n(Le);Bs=l(mi,"STRONG",{});var xr=n(Bs);Kn=i(xr,"3. Generate captions"),xr.forEach(s),eo=i(mi,":"),mi.forEach(s),Ua=c(e),Xt=l(e,"P",{});var Gr=n(Xt);to=i(Gr,"We can use a utility like so for this purpose."),Gr.forEach(s),Ia=c(e),f(Oe.$$.fragment,e),xa=c(e),Rt=l(e,"P",{});var Er=n(Rt);so=i(Er,"And then we just call it to generate our captions:"),Er.forEach(s),Ga=c(e),f(Ke.$$.fragment,e),Ea=c(e),R=l(e,"P",{});var Ft=n(R);ao=i(Ft,`We encourage you to play around with the different parameters supported by the
`),Ws=l(Ft,"CODE",{});var Br=n(Ws);lo=i(Br,"generate()"),Br.forEach(s),no=i(Ft," method ("),et=l(Ft,"A",{href:!0,rel:!0});var Wr=n(et);oo=i(Wr,"documentation"),Wr.forEach(s),io=i(Ft,") for the generation quality you are looking for."),Ft.forEach(s),Ba=c(e),tt=l(e,"P",{});var ui=n(tt);ks=l(ui,"STRONG",{});var kr=n(ks);ro=i(kr,"4. Load the embedding model"),kr.forEach(s),po=i(ui,":"),ui.forEach(s),Wa=c(e),Pt=l(e,"P",{});var Xr=n(Pt);co=i(Xr,"Here, we need to use the same text encoder model used by the subsequent Stable Diffusion model."),Xr.forEach(s),ka=c(e),f(st.$$.fragment,e),Xa=c(e),at=l(e,"P",{});var hi=n(at);Xs=l(hi,"STRONG",{});var Rr=n(Xs);mo=i(Rr,"5. Compute embeddings"),Rr.forEach(s),uo=i(hi,":"),hi.forEach(s),Ra=c(e),f(lt.$$.fragment,e),Pa=c(e),ce=l(e,"P",{});var el=n(ce);ho=i(el,"And you\u2019re done! "),nt=l(el,"A",{href:!0,rel:!0});var Pr=n(nt);fo=i(Pr,"Here"),Pr.forEach(s),go=i(el," is a Colab Notebook that you can use to interact with the entire process."),el.forEach(s),Va=c(e),Vt=l(e,"P",{});var Vr=n(Vt);bo=i(Vr,"Now, you can use these embeddings directly while calling the pipeline:"),Vr.forEach(s),Na=c(e),f(ot.$$.fragment,e),Ca=c(e),O=l(e,"H2",{class:!0});var tl=n(O);de=l(tl,"A",{id:!0,class:!0,href:!0});var Nr=n(de);Rs=l(Nr,"SPAN",{});var Cr=n(Rs);f(it.$$.fragment,Cr),Cr.forEach(s),Nr.forEach(s),wo=c(tl),Ps=l(tl,"SPAN",{});var Sr=n(Ps);yo=i(Sr,"StableDiffusionPix2PixZeroPipeline"),Sr.forEach(s),tl.forEach(s),Sa=c(e),_=l(e,"DIV",{class:!0});var v=n(_);f(rt.$$.fragment,v),Mo=c(v),Vs=l(v,"P",{});var Yr=n(Vs);Jo=i(Yr,"Pipeline for pixel-levl image editing using Pix2Pix Zero. Based on Stable Diffusion."),Yr.forEach(s),_o=c(v),pt=l(v,"P",{});var sl=n(pt);To=i(sl,"This model inherits from "),Nt=l(sl,"A",{href:!0});var $r=n(Nt);vo=i($r,"DiffusionPipeline"),$r.forEach(s),jo=i(sl,`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),sl.forEach(s),Zo=c(v),P=l(v,"DIV",{class:!0});var zt=n(P);f(ct.$$.fragment,zt),Uo=c(zt),Ns=l(zt,"P",{});var Fr=n(Ns);Io=i(Fr,"Function invoked when calling the pipeline for generation."),Fr.forEach(s),xo=c(zt),f(me.$$.fragment,zt),zt.forEach(s),Go=c(v),ue=l(v,"DIV",{class:!0});var al=n(ue);f(dt.$$.fragment,al),Eo=c(al),Cs=l(al,"P",{});var zr=n(Cs);Bo=i(zr,"Constructs the edit direction to steer the image generation process semantically."),zr.forEach(s),al.forEach(s),Wo=c(v),he=l(v,"DIV",{class:!0});var ll=n(he);f(mt.$$.fragment,ll),ko=c(ll),G=l(ll,"P",{});var C=n(G);Xo=i(C,`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),Ss=l(C,"CODE",{});var Dr=n(Ss);Ro=i(Dr,"enable_sequential_cpu_offload"),Dr.forEach(s),Po=i(C,", this method moves one whole model at a time to the GPU when its "),Ys=l(C,"CODE",{});var Qr=n(Ys);Vo=i(Qr,"forward"),Qr.forEach(s),No=i(C,`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),$s=l(C,"CODE",{});var Hr=n($s);Co=i(Hr,"enable_sequential_cpu_offload"),Hr.forEach(s),So=i(C,", but performance is much better due to the iterative execution of the "),Fs=l(C,"CODE",{});var Ar=n(Fs);Yo=i(Ar,"unet"),Ar.forEach(s),$o=i(C,"."),C.forEach(s),ll.forEach(s),Fo=c(v),fe=l(v,"DIV",{class:!0});var nl=n(fe);f(ut.$$.fragment,nl),zo=c(nl),K=l(nl,"P",{});var Dt=n(K);Do=i(Dt,`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),zs=l(Dt,"CODE",{});var qr=n(zs);Qo=i(qr,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),qr.forEach(s),Ho=i(Dt,"forward"),Ds=l(Dt,"CODE",{});var Lr=n(Ds);Ao=i(Lr,"method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),Lr.forEach(s),qo=i(Dt,"enable_model_cpu_offload`, but performance is lower."),Dt.forEach(s),nl.forEach(s),Lo=c(v),ge=l(v,"DIV",{class:!0});var ol=n(ge);f(ht.$$.fragment,ol),Oo=c(ol),Qs=l(ol,"P",{});var Or=n(Qs);Ko=i(Or,"Generates caption for a given image."),Or.forEach(s),ol.forEach(s),ei=c(v),V=l(v,"DIV",{class:!0});var Qt=n(V);f(ft.$$.fragment,Qt),ti=c(Qt),Hs=l(Qt,"P",{});var Kr=n(Hs);si=i(Kr,"Function used to generate inverted latents given a prompt and image."),Kr.forEach(s),ai=c(Qt),f(be.$$.fragment,Qt),Qt.forEach(s),v.forEach(s),this.h()},h(){m(J,"name","hf:doc:metadata"),m(J,"content",JSON.stringify(cp)),m(M,"id","zeroshot-imagetoimage-translation"),m(M,"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"),m(M,"href","#zeroshot-imagetoimage-translation"),m(T,"class","relative group"),m(te,"id","overview"),m(te,"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"),m(te,"href","#overview"),m(S,"class","relative group"),m(Te,"href","https://arxiv.org/abs/2302.03027"),m(Te,"rel","nofollow"),m(ve,"href","https://pix2pixzero.github.io/"),m(ve,"rel","nofollow"),m(je,"href","https://arxiv.org/abs/2302.03027"),m(je,"rel","nofollow"),m(Ze,"href","https://github.com/pix2pixzero/pix2pix-zero"),m(Ze,"rel","nofollow"),m(Ue,"href","https://huggingface.co/spaces/pix2pix-zero-library/pix2pix-zero-demo"),m(Ue,"rel","nofollow"),m(se,"id","tips"),m(se,"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"),m(se,"href","#tips"),m(Y,"class","relative group"),m(Ee,"href","https://arxiv.org/abs/2302.03027"),m(Ee,"rel","nofollow"),m(Ut,"href","#generating-source-and-target-embeddings"),m(ae,"id","available-pipelines"),m(ae,"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"),m(ae,"href","#available-pipelines"),m(z,"class","relative group"),m(It,"align","center"),m(We,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py"),m(We,"rel","nofollow"),m(ke,"href","https://huggingface.co/spaces/pix2pix-zero-library/pix2pix-zero-demo"),m(ke,"rel","nofollow"),m(xt,"align","center"),m(ne,"id","usage-example"),m(ne,"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"),m(ne,"href","#usage-example"),m(H,"class","relative group"),m(oe,"id","based-on-an-image-generated-with-the-input-prompt"),m(oe,"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"),m(oe,"href","#based-on-an-image-generated-with-the-input-prompt"),m(A,"class","relative group"),m(ie,"id","based-on-an-input-image"),m(ie,"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"),m(ie,"href","#based-on-an-input-image"),m(q,"class","relative group"),m(pe,"id","generating-source-and-target-embeddings"),m(pe,"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"),m(pe,"href","#generating-source-and-target-embeddings"),m(L,"class","relative group"),m(Fe,"href","https://openai.com/api/"),m(Fe,"rel","nofollow"),m(ze,"href","https://huggingface.co/docs/transformers/model_doc/flan-t5"),m(ze,"rel","nofollow"),m(De,"href","https://huggingface.co/docs/transformers/model_doc/clip"),m(De,"rel","nofollow"),m(et,"href","https://huggingface.co/docs/transformers/main/en/main_classes/text_generation#transformers.generation_tf_utils.TFGenerationMixin.generate"),m(et,"rel","nofollow"),m(nt,"href","https://colab.research.google.com/drive/1tz2C1EdfZYAPlzXXbTnf-5PRBiR8_R1F?usp=sharing"),m(nt,"rel","nofollow"),m(de,"id","diffusers.StableDiffusionPix2PixZeroPipeline"),m(de,"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"),m(de,"href","#diffusers.StableDiffusionPix2PixZeroPipeline"),m(O,"class","relative group"),m(Nt,"href","/docs/diffusers/v0.18.2/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),m(P,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(ue,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(he,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(fe,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(ge,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(V,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,r){t(document.head,J),d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),d(e,Xt,r),t(Xt,to),d(e,Ia,r),g(Oe,e,r),d(e,xa,r),d(e,Rt,r),t(Rt,so),d(e,Ga,r),g(Ke,e,r),d(e,Ea,r),d(e,R,r),t(R,ao),t(R,Ws),t(Ws,lo),t(R,no),t(R,et),t(et,oo),t(R,io),d(e,Ba,r),d(e,tt,r),t(tt,ks),t(ks,ro),t(tt,po),d(e,Wa,r),d(e,Pt,r),t(Pt,co),d(e,ka,r),g(st,e,r),d(e,Xa,r),d(e,at,r),t(at,Xs),t(Xs,mo),t(at,uo),d(e,Ra,r),g(lt,e,r),d(e,Pa,r),d(e,ce,r),t(ce,ho),t(ce,nt),t(nt,fo),t(ce,go),d(e,Va,r),d(e,Vt,r),t(Vt,bo),d(e,Na,r),g(ot,e,r),d(e,Ca,r),d(e,O,r),t(O,de),t(de,Rs),g(it,Rs,null),t(O,wo),t(O,Ps),t(Ps,yo),d(e,Sa,r),d(e,_,r),g(rt,_,null),t(_,Mo),t(_,Vs),t(Vs,Jo),t(_,_o),t(_,pt),t(pt,To),t(pt,Nt),t(Nt,vo),t(pt,jo),t(_,Zo),t(_,P),g(ct,P,null),t(P,Uo),t(P,Ns),t(Ns,Io),t(P,xo),g(me,P,null),t(_,Go),t(_,ue),g(dt,ue,null),t(ue,Eo),t(ue,Cs),t(Cs,Bo),t(_,Wo),t(_,he),g(mt,he,null),t(he,ko),t(he,G),t(G,Xo),t(G,Ss),t(Ss,Ro),t(G,Po),t(G,Ys),t(Ys,Vo),t(G,No),t(G,$s),t($s,Co),t(G,So),t(G,Fs),t(Fs,Yo),t(G,$o),t(_,Fo),t(_,fe),g(ut,fe,null),t(fe,zo),t(fe,K),t(K,Do),t(K,zs),t(zs,Qo),t(K,Ho),t(K,Ds),t(Ds,Ao),t(K,qo),t(_,Lo),t(_,ge),g(ht,ge,null),t(ge,Oo),t(ge,Qs),t(Qs,Ko),t(_,ei),t(_,V),g(ft,V,null),t(V,ti),t(V,Hs),t(Hs,si),t(V,ai),g(be,V,null),Ya=!0},p(e,[r]){const gt={};r&2&&(gt.$$scope={dirty:r,ctx:e}),me.$set(gt);const As={};r&2&&(As.$$scope={dirty:r,ctx:e}),be.$set(As)},i(e){Ya||(b(u.$$.fragment,e),b(Je.$$.fragment,e),b(Ie.$$.fragment,e),b(Be.$$.fragment,e),b(Xe.$$.fragment,e),b(Re.$$.fragment,e),b(Pe.$$.fragment,e),b(Ve.$$.fragment,e),b(Ne.$$.fragment,e),b(Ce.$$.fragment,e),b(Se.$$.fragment,e),b(Ye.$$.fragment,e),b($e.$$.fragment,e),b(He.$$.fragment,e),b(qe.$$.fragment,e),b(Oe.$$.fragment,e),b(Ke.$$.fragment,e),b(st.$$.fragment,e),b(lt.$$.fragment,e),b(ot.$$.fragment,e),b(it.$$.fragment,e),b(rt.$$.fragment,e),b(ct.$$.fragment,e),b(me.$$.fragment,e),b(dt.$$.fragment,e),b(mt.$$.fragment,e),b(ut.$$.fragment,e),b(ht.$$.fragment,e),b(ft.$$.fragment,e),b(be.$$.fragment,e),Ya=!0)},o(e){w(u.$$.fragment,e),w(Je.$$.fragment,e),w(Ie.$$.fragment,e),w(Be.$$.fragment,e),w(Xe.$$.fragment,e),w(Re.$$.fragment,e),w(Pe.$$.fragment,e),w(Ve.$$.fragment,e),w(Ne.$$.fragment,e),w(Ce.$$.fragment,e),w(Se.$$.fragment,e),w(Ye.$$.fragment,e),w($e.$$.fragment,e),w(He.$$.fragment,e),w(qe.$$.fragment,e),w(Oe.$$.fragment,e),w(Ke.$$.fragment,e),w(st.$$.fragment,e),w(lt.$$.fragment,e),w(ot.$$.fragment,e),w(it.$$.fragment,e),w(rt.$$.fragment,e),w(ct.$$.fragment,e),w(me.$$.fragment,e),w(dt.$$.fragment,e),w(mt.$$.fragment,e),w(ut.$$.fragment,e),w(ht.$$.fragment,e),w(ft.$$.fragment,e),w(be.$$.fragment,e),Ya=!1},d(e){s(J),e&&s(E),e&&s(T),y(u),e&&s(qs),e&&s(S),y(Je),e&&s(Ls),e&&s(_e),e&&s(Os),e&&s(yt),e&&s(Ks),e&&s(Mt),e&&s(ea),e&&s(Jt),e&&s(ta),e&&s(B),e&&s(sa),e&&s(Y),y(Ie),e&&s(aa),e&&s(Z),e&&s(la),e&&s(z),y(Be),e&&s(na),e&&s(le),e&&s(oa),e&&s(H),y(Xe),e&&s(ia),e&&s(A),y(Re),e&&s(ra),y(Pe,e),e&&s(pa),e&&s(q),y(Ve),e&&s(ca),e&&s(re),e&&s(da),e&&s(Gt),e&&s(ma),y(Ne,e),e&&s(ua),e&&s(Et),e&&s(ha),y(Ce,e),e&&s(fa),e&&s(Bt),e&&s(ga),y(Se,e),e&&s(ba),e&&s(Wt),e&&s(wa),y(Ye,e),e&&s(ya),e&&s(L),y($e),e&&s(Ma),e&&s(W),e&&s(Ja),e&&s(Qe),e&&s(_a),y(He,e),e&&s(Ta),e&&s(Ae),e&&s(va),y(qe,e),e&&s(ja),e&&s(kt),e&&s(Za),e&&s(Le),e&&s(Ua),e&&s(Xt),e&&s(Ia),y(Oe,e),e&&s(xa),e&&s(Rt),e&&s(Ga),y(Ke,e),e&&s(Ea),e&&s(R),e&&s(Ba),e&&s(tt),e&&s(Wa),e&&s(Pt),e&&s(ka),y(st,e),e&&s(Xa),e&&s(at),e&&s(Ra),y(lt,e),e&&s(Pa),e&&s(ce),e&&s(Va),e&&s(Vt),e&&s(Na),y(ot,e),e&&s(Ca),e&&s(O),y(it),e&&s(Sa),e&&s(_),y(rt),y(ct),y(me),y(dt),y(mt),y(ut),y(ht),y(ft),y(be)}}}const cp={local:"zeroshot-imagetoimage-translation",sections:[{local:"overview",title:"Overview"},{local:"tips",title:"Tips "},{local:"available-pipelines",title:"Available Pipelines:"},{local:"usage-example",sections:[{local:"based-on-an-image-generated-with-the-input-prompt",title:"Based on an image generated with the input prompt"},{local:"based-on-an-input-image",title:"Based on an input image"}],title:"Usage example"},{local:"generating-source-and-target-embeddings",title:"Generating source and target embeddings "},{local:"diffusers.StableDiffusionPix2PixZeroPipeline",title:"StableDiffusionPix2PixZeroPipeline"}],title:"Zero-shot Image-to-Image Translation"};function dp(wt){return op(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class bp extends sp{constructor(J){super();ap(this,J,dp,pp,lp,{})}}export{bp as default,cp as metadata};
