import{S as ti,i as ii,s as ni,e as i,k as p,w as k,t as r,M as oi,c as n,d as t,m as c,a as o,x as I,h as l,b as s,G as e,g as m,y as $,L as si,q as T,o as S,B as D,v as ri}from"../../../chunks/vendor-hf-doc-builder.js";import{D as ut}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as li}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as Ne}from"../../../chunks/IconCopyLink-hf-doc-builder.js";function pi(gt){let g,Oe,_,B,ue,z,ma,ge,fa,ze,v,L,_e,U,ha,ve,ua,Ue,G,W,ga,_a,Ge,se,va,We,re,ye,ya,He,C,ba,H,xa,Pa,Ve,y,A,be,V,wa,xe,Ea,Re,M,Pe,b,we,ka,Ia,Ee,$a,Ta,le,Sa,Da,ke,x,Ie,R,Ba,La,$e,Te,Ca,Aa,pe,Ma,Ye,P,j,Se,Y,ja,De,Fa,Xe,h,w,qa,X,Na,Oa,Z,za,Ua,Ga,F,Wa,Be,Ha,Va,K,Ra,Ya,Le,Xa,Ze,J,Ke,E,q,Ce,Q,Za,Ae,Ka,Je,f,ee,Ja,ae,Qa,Me,et,at,tt,te,it,ce,nt,ot,st,N,ie,rt,je,lt,pt,O,ne,ct,oe,dt,Fe,mt,ft,Qe;return z=new Ne({}),U=new Ne({}),V=new Ne({}),Y=new Ne({}),J=new li({props:{code:`# !pip install diffusers transformers

import PIL
import requests
import torch
from io import BytesIO
from diffusers import DiffusionPipeline


def download_image(url):
    response = requests.get(url)
    return PIL.Image.open(BytesIO(response.content)).convert("RGB")


img_url = "https://raw.githubusercontent.com/Fantasy-Studio/Paint-by-Example/main/examples/image/example_1.png"
mask_url = "https://raw.githubusercontent.com/Fantasy-Studio/Paint-by-Example/main/examples/mask/example_1.png"
example_url = "https://raw.githubusercontent.com/Fantasy-Studio/Paint-by-Example/main/examples/reference/example_1.jpg"

init_image = download_image(img_url).resize((512, 512))
mask_image = download_image(mask_url).resize((512, 512))
example_image = download_image(example_url).resize((512, 512))

pipe = DiffusionPipeline.from_pretrained(
    "Fantasy-Studio/Paint-by-Example",
    torch_dtype=torch.float16,
)
pipe = pipe.to("cuda")

image = pipe(image=init_image, mask_image=mask_image, example_image=example_image).images[0]
image`,highlighted:`<span class="hljs-comment"># !pip install diffusers transformers</span>

<span class="hljs-keyword">import</span> PIL
<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> io <span class="hljs-keyword">import</span> BytesIO
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline


<span class="hljs-keyword">def</span> <span class="hljs-title function_">download_image</span>(<span class="hljs-params">url</span>):
    response = requests.get(url)
    <span class="hljs-keyword">return</span> PIL.Image.<span class="hljs-built_in">open</span>(BytesIO(response.content)).convert(<span class="hljs-string">&quot;RGB&quot;</span>)


img_url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/Fantasy-Studio/Paint-by-Example/main/examples/image/example_1.png&quot;</span>
mask_url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/Fantasy-Studio/Paint-by-Example/main/examples/mask/example_1.png&quot;</span>
example_url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/Fantasy-Studio/Paint-by-Example/main/examples/reference/example_1.jpg&quot;</span>

init_image = download_image(img_url).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
mask_image = download_image(mask_url).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
example_image = download_image(example_url).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))

pipe = DiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;Fantasy-Studio/Paint-by-Example&quot;</span>,
    torch_dtype=torch.float16,
)
pipe = pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)

image = pipe(image=init_image, mask_image=mask_image, example_image=example_image).images[<span class="hljs-number">0</span>]
image`}}),Q=new Ne({}),ee=new ut({props:{name:"class diffusers.PaintByExamplePipeline",anchor:"diffusers.PaintByExamplePipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"image_encoder",val:": PaintByExampleImageEncoder"},{name:"unet",val:": UNet2DConditionModel"},{name:"scheduler",val:": typing.Union[diffusers.schedulers.scheduling_ddim.DDIMScheduler, diffusers.schedulers.scheduling_pndm.PNDMScheduler, diffusers.schedulers.scheduling_lms_discrete.LMSDiscreteScheduler]"},{name:"safety_checker",val:": StableDiffusionSafetyChecker"},{name:"feature_extractor",val:": CLIPFeatureExtractor"},{name:"requires_safety_checker",val:": bool = False"}],parametersDescription:[{anchor:"diffusers.PaintByExamplePipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/v0.12.0/en/api/models#diffusers.AutoencoderKL">AutoencoderKL</a>) &#x2014;
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.`,name:"vae"},{anchor:"diffusers.PaintByExamplePipeline.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.PaintByExamplePipeline.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.PaintByExamplePipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/v0.12.0/en/api/models#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.PaintByExamplePipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/v0.12.0/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.12.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/v0.12.0/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/v0.12.0/en/api/schedulers/pndm#diffusers.PNDMScheduler">PNDMScheduler</a>.`,name:"scheduler"},{anchor:"diffusers.PaintByExamplePipeline.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.PaintByExamplePipeline.feature_extractor",description:`<strong>feature_extractor</strong> (<code>CLIPFeatureExtractor</code>) &#x2014;
Model that extracts features from generated images to be used as inputs for the <code>safety_checker</code>.`,name:"feature_extractor"}],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py#L137"}}),ie=new ut({props:{name:"__call__",anchor:"diffusers.PaintByExamplePipeline.__call__",parameters:[{name:"example_image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image]"},{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image]"},{name:"mask_image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image]"},{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 = 5.0"},{name:"negative_prompt",val:": typing.Union[str, typing.List[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:"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"}],parametersDescription:[{anchor:"diffusers.PaintByExamplePipeline.__call__.example_image",description:`<strong>example_image</strong> (<code>torch.FloatTensor</code> or <code>PIL.Image.Image</code> or <code>List[PIL.Image.Image]</code>) &#x2014;
The exemplar image to guide the image generation.`,name:"example_image"},{anchor:"diffusers.PaintByExamplePipeline.__call__.image",description:`<strong>image</strong> (<code>torch.FloatTensor</code> or <code>PIL.Image.Image</code> or <code>List[PIL.Image.Image]</code>) &#x2014;
<code>Image</code>, or tensor representing an image batch which will be inpainted, <em>i.e.</em> parts of the image will
be masked out with <code>mask_image</code> and repainted according to <code>prompt</code>.`,name:"image"},{anchor:"diffusers.PaintByExamplePipeline.__call__.mask_image",description:`<strong>mask_image</strong> (<code>torch.FloatTensor</code> or <code>PIL.Image.Image</code> or <code>List[PIL.Image.Image]</code>) &#x2014;
<code>Image</code>, or tensor representing an image batch, to mask <code>image</code>. White pixels in the mask will be
repainted, while black pixels will be preserved. If <code>mask_image</code> is a PIL image, it will be converted
to a single channel (luminance) before use. If it&#x2019;s a tensor, it should contain one color channel (L)
instead of 3, so the expected shape would be <code>(B, H, W, 1)</code>.`,name:"mask_image"},{anchor:"diffusers.PaintByExamplePipeline.__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.PaintByExamplePipeline.__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.PaintByExamplePipeline.__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.PaintByExamplePipeline.__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.PaintByExamplePipeline.__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. Ignored when not using guidance (i.e., ignored
if <code>guidance_scale</code> is less than <code>1</code>).`,name:"negative_prompt"},{anchor:"diffusers.PaintByExamplePipeline.__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.PaintByExamplePipeline.__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.12.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">schedulers.DDIMScheduler</a>, will be ignored for others.`,name:"eta"},{anchor:"diffusers.PaintByExamplePipeline.__call__.generator",description:`<strong>generator</strong> (<code>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.PaintByExamplePipeline.__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.PaintByExamplePipeline.__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.PaintByExamplePipeline.__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.12.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.PaintByExamplePipeline.__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.PaintByExamplePipeline.__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.12.0/src/diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py#L385",returnDescription:`
<p><a
  href="/docs/diffusers/v0.12.0/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.12.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),ne=new ut({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.PaintByExamplePipeline.enable_sequential_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py#L191"}}),{c(){g=i("meta"),Oe=p(),_=i("h1"),B=i("a"),ue=i("span"),k(z.$$.fragment),ma=p(),ge=i("span"),fa=r("PaintByExample"),ze=p(),v=i("h2"),L=i("a"),_e=i("span"),k(U.$$.fragment),ha=p(),ve=i("span"),ua=r("Overview"),Ue=p(),G=i("p"),W=i("a"),ga=r("Paint by Example: Exemplar-based Image Editing with Diffusion Models"),_a=r(" by Binxin Yang, Shuyang Gu, Bo Zhang, Ting Zhang, Xuejin Chen, Xiaoyan Sun, Dong Chen, Fang Wen"),Ge=p(),se=i("p"),va=r("The abstract of the paper is the following:"),We=p(),re=i("p"),ye=i("em"),ya=r("Language-guided image editing has achieved great success recently. In this paper, for the first time, we investigate exemplar-guided image editing for more precise control. We achieve this goal by leveraging self-supervised training to disentangle and re-organize the source image and the exemplar. However, the naive approach will cause obvious fusing artifacts. We carefully analyze it and propose an information bottleneck and strong augmentations to avoid the trivial solution of directly copying and pasting the exemplar image. Meanwhile, to ensure the controllability of the editing process, we design an arbitrary shape mask for the exemplar image and leverage the classifier-free guidance to increase the similarity to the exemplar image. The whole framework involves a single forward of the diffusion model without any iterative optimization. We demonstrate that our method achieves an impressive performance and enables controllable editing on in-the-wild images with high fidelity."),He=p(),C=i("p"),ba=r("The original codebase can be found "),H=i("a"),xa=r("here"),Pa=r("."),Ve=p(),y=i("h2"),A=i("a"),be=i("span"),k(V.$$.fragment),wa=p(),xe=i("span"),Ea=r("Available Pipelines:"),Re=p(),M=i("table"),Pe=i("thead"),b=i("tr"),we=i("th"),ka=r("Pipeline"),Ia=p(),Ee=i("th"),$a=r("Tasks"),Ta=p(),le=i("th"),Sa=r("Colab"),Da=p(),ke=i("tbody"),x=i("tr"),Ie=i("td"),R=i("a"),Ba=r("pipeline_paint_by_example.py"),La=p(),$e=i("td"),Te=i("em"),Ca=r("Image-Guided Image Painting"),Aa=p(),pe=i("td"),Ma=r("-"),Ye=p(),P=i("h2"),j=i("a"),Se=i("span"),k(Y.$$.fragment),ja=p(),De=i("span"),Fa=r("Tips"),Xe=p(),h=i("ul"),w=i("li"),qa=r("PaintByExample is supported by the official "),X=i("a"),Na=r("Fantasy-Studio/Paint-by-Example"),Oa=r(" checkpoint. The checkpoint has been warm-started from the "),Z=i("a"),za=r("CompVis/stable-diffusion-v1-4"),Ua=r(" and with the objective to inpaint partly masked images conditioned on example / reference images"),Ga=p(),F=i("li"),Wa=r("To quickly demo "),Be=i("em"),Ha=r("PaintByExample"),Va=r(", please have a look at "),K=i("a"),Ra=r("this demo"),Ya=p(),Le=i("li"),Xa=r("You can run the following code snippet as an example:"),Ze=p(),k(J.$$.fragment),Ke=p(),E=i("h2"),q=i("a"),Ce=i("span"),k(Q.$$.fragment),Za=p(),Ae=i("span"),Ka=r("PaintByExamplePipeline"),Je=p(),f=i("div"),k(ee.$$.fragment),Ja=p(),ae=i("p"),Qa=r("Pipeline for text-guided image inpainting using Stable Diffusion. "),Me=i("em"),et=r("This is an experimental feature"),at=r("."),tt=p(),te=i("p"),it=r("This model inherits from "),ce=i("a"),nt=r("DiffusionPipeline"),ot=r(`. 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.)`),st=p(),N=i("div"),k(ie.$$.fragment),rt=p(),je=i("p"),lt=r("Function invoked when calling the pipeline for generation."),pt=p(),O=i("div"),k(ne.$$.fragment),ct=p(),oe=i("p"),dt=r(`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
`),Fe=i("code"),mt=r("torch.device('meta') and loaded to GPU only when their specific submodule has its "),ft=r("forward` method called."),this.h()},l(a){const d=oi('[data-svelte="svelte-1phssyn"]',document.head);g=n(d,"META",{name:!0,content:!0}),d.forEach(t),Oe=c(a),_=n(a,"H1",{class:!0});var ea=o(_);B=n(ea,"A",{id:!0,class:!0,href:!0});var _t=o(B);ue=n(_t,"SPAN",{});var vt=o(ue);I(z.$$.fragment,vt),vt.forEach(t),_t.forEach(t),ma=c(ea),ge=n(ea,"SPAN",{});var yt=o(ge);fa=l(yt,"PaintByExample"),yt.forEach(t),ea.forEach(t),ze=c(a),v=n(a,"H2",{class:!0});var aa=o(v);L=n(aa,"A",{id:!0,class:!0,href:!0});var bt=o(L);_e=n(bt,"SPAN",{});var xt=o(_e);I(U.$$.fragment,xt),xt.forEach(t),bt.forEach(t),ha=c(aa),ve=n(aa,"SPAN",{});var Pt=o(ve);ua=l(Pt,"Overview"),Pt.forEach(t),aa.forEach(t),Ue=c(a),G=n(a,"P",{});var ht=o(G);W=n(ht,"A",{href:!0,rel:!0});var wt=o(W);ga=l(wt,"Paint by Example: Exemplar-based Image Editing with Diffusion Models"),wt.forEach(t),_a=l(ht," by Binxin Yang, Shuyang Gu, Bo Zhang, Ting Zhang, Xuejin Chen, Xiaoyan Sun, Dong Chen, Fang Wen"),ht.forEach(t),Ge=c(a),se=n(a,"P",{});var Et=o(se);va=l(Et,"The abstract of the paper is the following:"),Et.forEach(t),We=c(a),re=n(a,"P",{});var kt=o(re);ye=n(kt,"EM",{});var It=o(ye);ya=l(It,"Language-guided image editing has achieved great success recently. In this paper, for the first time, we investigate exemplar-guided image editing for more precise control. We achieve this goal by leveraging self-supervised training to disentangle and re-organize the source image and the exemplar. However, the naive approach will cause obvious fusing artifacts. We carefully analyze it and propose an information bottleneck and strong augmentations to avoid the trivial solution of directly copying and pasting the exemplar image. Meanwhile, to ensure the controllability of the editing process, we design an arbitrary shape mask for the exemplar image and leverage the classifier-free guidance to increase the similarity to the exemplar image. The whole framework involves a single forward of the diffusion model without any iterative optimization. We demonstrate that our method achieves an impressive performance and enables controllable editing on in-the-wild images with high fidelity."),It.forEach(t),kt.forEach(t),He=c(a),C=n(a,"P",{});var ta=o(C);ba=l(ta,"The original codebase can be found "),H=n(ta,"A",{href:!0,rel:!0});var $t=o(H);xa=l($t,"here"),$t.forEach(t),Pa=l(ta,"."),ta.forEach(t),Ve=c(a),y=n(a,"H2",{class:!0});var ia=o(y);A=n(ia,"A",{id:!0,class:!0,href:!0});var Tt=o(A);be=n(Tt,"SPAN",{});var St=o(be);I(V.$$.fragment,St),St.forEach(t),Tt.forEach(t),wa=c(ia),xe=n(ia,"SPAN",{});var Dt=o(xe);Ea=l(Dt,"Available Pipelines:"),Dt.forEach(t),ia.forEach(t),Re=c(a),M=n(a,"TABLE",{});var na=o(M);Pe=n(na,"THEAD",{});var Bt=o(Pe);b=n(Bt,"TR",{});var de=o(b);we=n(de,"TH",{});var Lt=o(we);ka=l(Lt,"Pipeline"),Lt.forEach(t),Ia=c(de),Ee=n(de,"TH",{});var Ct=o(Ee);$a=l(Ct,"Tasks"),Ct.forEach(t),Ta=c(de),le=n(de,"TH",{align:!0});var At=o(le);Sa=l(At,"Colab"),At.forEach(t),de.forEach(t),Bt.forEach(t),Da=c(na),ke=n(na,"TBODY",{});var Mt=o(ke);x=n(Mt,"TR",{});var me=o(x);Ie=n(me,"TD",{});var jt=o(Ie);R=n(jt,"A",{href:!0,rel:!0});var Ft=o(R);Ba=l(Ft,"pipeline_paint_by_example.py"),Ft.forEach(t),jt.forEach(t),La=c(me),$e=n(me,"TD",{});var qt=o($e);Te=n(qt,"EM",{});var Nt=o(Te);Ca=l(Nt,"Image-Guided Image Painting"),Nt.forEach(t),qt.forEach(t),Aa=c(me),pe=n(me,"TD",{align:!0});var Ot=o(pe);Ma=l(Ot,"-"),Ot.forEach(t),me.forEach(t),Mt.forEach(t),na.forEach(t),Ye=c(a),P=n(a,"H2",{class:!0});var oa=o(P);j=n(oa,"A",{id:!0,class:!0,href:!0});var zt=o(j);Se=n(zt,"SPAN",{});var Ut=o(Se);I(Y.$$.fragment,Ut),Ut.forEach(t),zt.forEach(t),ja=c(oa),De=n(oa,"SPAN",{});var Gt=o(De);Fa=l(Gt,"Tips"),Gt.forEach(t),oa.forEach(t),Xe=c(a),h=n(a,"UL",{});var fe=o(h);w=n(fe,"LI",{});var he=o(w);qa=l(he,"PaintByExample is supported by the official "),X=n(he,"A",{href:!0,rel:!0});var Wt=o(X);Na=l(Wt,"Fantasy-Studio/Paint-by-Example"),Wt.forEach(t),Oa=l(he," checkpoint. The checkpoint has been warm-started from the "),Z=n(he,"A",{href:!0,rel:!0});var Ht=o(Z);za=l(Ht,"CompVis/stable-diffusion-v1-4"),Ht.forEach(t),Ua=l(he," and with the objective to inpaint partly masked images conditioned on example / reference images"),he.forEach(t),Ga=c(fe),F=n(fe,"LI",{});var qe=o(F);Wa=l(qe,"To quickly demo "),Be=n(qe,"EM",{});var Vt=o(Be);Ha=l(Vt,"PaintByExample"),Vt.forEach(t),Va=l(qe,", please have a look at "),K=n(qe,"A",{href:!0,rel:!0});var Rt=o(K);Ra=l(Rt,"this demo"),Rt.forEach(t),qe.forEach(t),Ya=c(fe),Le=n(fe,"LI",{});var Yt=o(Le);Xa=l(Yt,"You can run the following code snippet as an example:"),Yt.forEach(t),fe.forEach(t),Ze=c(a),I(J.$$.fragment,a),Ke=c(a),E=n(a,"H2",{class:!0});var sa=o(E);q=n(sa,"A",{id:!0,class:!0,href:!0});var Xt=o(q);Ce=n(Xt,"SPAN",{});var Zt=o(Ce);I(Q.$$.fragment,Zt),Zt.forEach(t),Xt.forEach(t),Za=c(sa),Ae=n(sa,"SPAN",{});var Kt=o(Ae);Ka=l(Kt,"PaintByExamplePipeline"),Kt.forEach(t),sa.forEach(t),Je=c(a),f=n(a,"DIV",{class:!0});var u=o(f);I(ee.$$.fragment,u),Ja=c(u),ae=n(u,"P",{});var ra=o(ae);Qa=l(ra,"Pipeline for text-guided image inpainting using Stable Diffusion. "),Me=n(ra,"EM",{});var Jt=o(Me);et=l(Jt,"This is an experimental feature"),Jt.forEach(t),at=l(ra,"."),ra.forEach(t),tt=c(u),te=n(u,"P",{});var la=o(te);it=l(la,"This model inherits from "),ce=n(la,"A",{href:!0});var Qt=o(ce);nt=l(Qt,"DiffusionPipeline"),Qt.forEach(t),ot=l(la,`. 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.)`),la.forEach(t),st=c(u),N=n(u,"DIV",{class:!0});var pa=o(N);I(ie.$$.fragment,pa),rt=c(pa),je=n(pa,"P",{});var ei=o(je);lt=l(ei,"Function invoked when calling the pipeline for generation."),ei.forEach(t),pa.forEach(t),pt=c(u),O=n(u,"DIV",{class:!0});var ca=o(O);I(ne.$$.fragment,ca),ct=c(ca),oe=n(ca,"P",{});var da=o(oe);dt=l(da,`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
`),Fe=n(da,"CODE",{});var ai=o(Fe);mt=l(ai,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),ai.forEach(t),ft=l(da,"forward` method called."),da.forEach(t),ca.forEach(t),u.forEach(t),this.h()},h(){s(g,"name","hf:doc:metadata"),s(g,"content",JSON.stringify(ci)),s(B,"id","paintbyexample"),s(B,"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"),s(B,"href","#paintbyexample"),s(_,"class","relative group"),s(L,"id","overview"),s(L,"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"),s(L,"href","#overview"),s(v,"class","relative group"),s(W,"href","https://arxiv.org/abs/2211.13227"),s(W,"rel","nofollow"),s(H,"href","https://github.com/Fantasy-Studio/Paint-by-Example"),s(H,"rel","nofollow"),s(A,"id","available-pipelines"),s(A,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),s(A,"href","#available-pipelines"),s(y,"class","relative group"),s(le,"align","center"),s(R,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py"),s(R,"rel","nofollow"),s(pe,"align","center"),s(j,"id","tips"),s(j,"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"),s(j,"href","#tips"),s(P,"class","relative group"),s(X,"href","https://huggingface.co/Fantasy-Studio/Paint-by-Example"),s(X,"rel","nofollow"),s(Z,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),s(Z,"rel","nofollow"),s(K,"href","https://huggingface.co/spaces/Fantasy-Studio/Paint-by-Example"),s(K,"rel","nofollow"),s(q,"id","diffusers.PaintByExamplePipeline"),s(q,"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"),s(q,"href","#diffusers.PaintByExamplePipeline"),s(E,"class","relative group"),s(ce,"href","/docs/diffusers/v0.12.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),s(N,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),s(O,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),s(f,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(a,d){e(document.head,g),m(a,Oe,d),m(a,_,d),e(_,B),e(B,ue),$(z,ue,null),e(_,ma),e(_,ge),e(ge,fa),m(a,ze,d),m(a,v,d),e(v,L),e(L,_e),$(U,_e,null),e(v,ha),e(v,ve),e(ve,ua),m(a,Ue,d),m(a,G,d),e(G,W),e(W,ga),e(G,_a),m(a,Ge,d),m(a,se,d),e(se,va),m(a,We,d),m(a,re,d),e(re,ye),e(ye,ya),m(a,He,d),m(a,C,d),e(C,ba),e(C,H),e(H,xa),e(C,Pa),m(a,Ve,d),m(a,y,d),e(y,A),e(A,be),$(V,be,null),e(y,wa),e(y,xe),e(xe,Ea),m(a,Re,d),m(a,M,d),e(M,Pe),e(Pe,b),e(b,we),e(we,ka),e(b,Ia),e(b,Ee),e(Ee,$a),e(b,Ta),e(b,le),e(le,Sa),e(M,Da),e(M,ke),e(ke,x),e(x,Ie),e(Ie,R),e(R,Ba),e(x,La),e(x,$e),e($e,Te),e(Te,Ca),e(x,Aa),e(x,pe),e(pe,Ma),m(a,Ye,d),m(a,P,d),e(P,j),e(j,Se),$(Y,Se,null),e(P,ja),e(P,De),e(De,Fa),m(a,Xe,d),m(a,h,d),e(h,w),e(w,qa),e(w,X),e(X,Na),e(w,Oa),e(w,Z),e(Z,za),e(w,Ua),e(h,Ga),e(h,F),e(F,Wa),e(F,Be),e(Be,Ha),e(F,Va),e(F,K),e(K,Ra),e(h,Ya),e(h,Le),e(Le,Xa),m(a,Ze,d),$(J,a,d),m(a,Ke,d),m(a,E,d),e(E,q),e(q,Ce),$(Q,Ce,null),e(E,Za),e(E,Ae),e(Ae,Ka),m(a,Je,d),m(a,f,d),$(ee,f,null),e(f,Ja),e(f,ae),e(ae,Qa),e(ae,Me),e(Me,et),e(ae,at),e(f,tt),e(f,te),e(te,it),e(te,ce),e(ce,nt),e(te,ot),e(f,st),e(f,N),$(ie,N,null),e(N,rt),e(N,je),e(je,lt),e(f,pt),e(f,O),$(ne,O,null),e(O,ct),e(O,oe),e(oe,dt),e(oe,Fe),e(Fe,mt),e(oe,ft),Qe=!0},p:si,i(a){Qe||(T(z.$$.fragment,a),T(U.$$.fragment,a),T(V.$$.fragment,a),T(Y.$$.fragment,a),T(J.$$.fragment,a),T(Q.$$.fragment,a),T(ee.$$.fragment,a),T(ie.$$.fragment,a),T(ne.$$.fragment,a),Qe=!0)},o(a){S(z.$$.fragment,a),S(U.$$.fragment,a),S(V.$$.fragment,a),S(Y.$$.fragment,a),S(J.$$.fragment,a),S(Q.$$.fragment,a),S(ee.$$.fragment,a),S(ie.$$.fragment,a),S(ne.$$.fragment,a),Qe=!1},d(a){t(g),a&&t(Oe),a&&t(_),D(z),a&&t(ze),a&&t(v),D(U),a&&t(Ue),a&&t(G),a&&t(Ge),a&&t(se),a&&t(We),a&&t(re),a&&t(He),a&&t(C),a&&t(Ve),a&&t(y),D(V),a&&t(Re),a&&t(M),a&&t(Ye),a&&t(P),D(Y),a&&t(Xe),a&&t(h),a&&t(Ze),D(J,a),a&&t(Ke),a&&t(E),D(Q),a&&t(Je),a&&t(f),D(ee),D(ie),D(ne)}}}const ci={local:"paintbyexample",sections:[{local:"overview",title:"Overview"},{local:"available-pipelines",title:"Available Pipelines:"},{local:"tips",title:"Tips"},{local:"diffusers.PaintByExamplePipeline",title:"PaintByExamplePipeline"}],title:"PaintByExample"};function di(gt){return ri(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class gi extends ti{constructor(g){super();ii(this,g,di,pi,ni,{})}}export{gi as default,ci as metadata};
