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 d,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,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,_,D,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,j,Pe,b,we,ka,Ia,Ee,$a,Ta,le,Sa,Ba,ke,x,Ie,R,Da,La,$e,Te,Ca,Aa,pe,ja,Ye,P,M,Se,Y,Ma,Be,qa,Xe,h,w,Fa,X,Na,Oa,Z,za,Ua,Ga,q,Wa,De,Ha,Va,K,Ra,Ya,Le,Xa,Ze,J,Ke,E,F,Ce,Q,Za,Ae,Ka,Je,f,ee,Ja,ae,Qa,je,et,at,tt,te,it,de,nt,ot,st,N,ie,rt,Me,lt,pt,O,ne,dt,oe,ct,qe,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:": CLIPImageProcessor"},{name:"requires_safety_checker",val:": bool = False"}],parametersDescription:[{anchor:"diffusers.PaintByExamplePipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/v0.16.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.image_encoder",description:`<strong>image_encoder</strong> (<code>PaintByExampleImageEncoder</code>) &#x2014;
Encodes the example input image. The unet is conditioned on the example image instead of a text prompt.`,name:"image_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.16.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.16.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.16.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/v0.16.0/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/v0.16.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>CLIPImageProcessor</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.16.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:": 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.16.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.16.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.16.0/src/diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py#L383",returnDescription:`
<p><a
  href="/docs/diffusers/v0.16.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.16.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.16.0/src/diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py#L189"}}),{c(){g=i("meta"),Oe=p(),_=i("h1"),D=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(),j=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"),Ba=p(),ke=i("tbody"),x=i("tr"),Ie=i("td"),R=i("a"),Da=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"),ja=r("-"),Ye=p(),P=i("h2"),M=i("a"),Se=i("span"),k(Y.$$.fragment),Ma=p(),Be=i("span"),qa=r("Tips"),Xe=p(),h=i("ul"),w=i("li"),Fa=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(),q=i("li"),Wa=r("To quickly demo "),De=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"),F=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 image-guided image inpainting using Stable Diffusion. "),je=i("em"),et=r("This is an experimental feature"),at=r("."),tt=p(),te=i("p"),it=r("This model inherits from "),de=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(),Me=i("p"),lt=r("Function invoked when calling the pipeline for generation."),pt=p(),O=i("div"),k(ne.$$.fragment),dt=p(),oe=i("p"),ct=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
`),qe=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 c=oi('[data-svelte="svelte-1phssyn"]',document.head);g=n(c,"META",{name:!0,content:!0}),c.forEach(t),Oe=d(a),_=n(a,"H1",{class:!0});var ea=o(_);D=n(ea,"A",{id:!0,class:!0,href:!0});var _t=o(D);ue=n(_t,"SPAN",{});var vt=o(ue);I(z.$$.fragment,vt),vt.forEach(t),_t.forEach(t),ma=d(ea),ge=n(ea,"SPAN",{});var yt=o(ge);fa=l(yt,"PaintByExample"),yt.forEach(t),ea.forEach(t),ze=d(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=d(aa),ve=n(aa,"SPAN",{});var Pt=o(ve);ua=l(Pt,"Overview"),Pt.forEach(t),aa.forEach(t),Ue=d(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=d(a),se=n(a,"P",{});var Et=o(se);va=l(Et,"The abstract of the paper is the following:"),Et.forEach(t),We=d(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=d(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=d(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=d(ia),xe=n(ia,"SPAN",{});var Bt=o(xe);Ea=l(Bt,"Available Pipelines:"),Bt.forEach(t),ia.forEach(t),Re=d(a),j=n(a,"TABLE",{});var na=o(j);Pe=n(na,"THEAD",{});var Dt=o(Pe);b=n(Dt,"TR",{});var ce=o(b);we=n(ce,"TH",{});var Lt=o(we);ka=l(Lt,"Pipeline"),Lt.forEach(t),Ia=d(ce),Ee=n(ce,"TH",{});var Ct=o(Ee);$a=l(Ct,"Tasks"),Ct.forEach(t),Ta=d(ce),le=n(ce,"TH",{align:!0});var At=o(le);Sa=l(At,"Colab"),At.forEach(t),ce.forEach(t),Dt.forEach(t),Ba=d(na),ke=n(na,"TBODY",{});var jt=o(ke);x=n(jt,"TR",{});var me=o(x);Ie=n(me,"TD",{});var Mt=o(Ie);R=n(Mt,"A",{href:!0,rel:!0});var qt=o(R);Da=l(qt,"pipeline_paint_by_example.py"),qt.forEach(t),Mt.forEach(t),La=d(me),$e=n(me,"TD",{});var Ft=o($e);Te=n(Ft,"EM",{});var Nt=o(Te);Ca=l(Nt,"Image-Guided Image Painting"),Nt.forEach(t),Ft.forEach(t),Aa=d(me),pe=n(me,"TD",{align:!0});var Ot=o(pe);ja=l(Ot,"-"),Ot.forEach(t),me.forEach(t),jt.forEach(t),na.forEach(t),Ye=d(a),P=n(a,"H2",{class:!0});var oa=o(P);M=n(oa,"A",{id:!0,class:!0,href:!0});var zt=o(M);Se=n(zt,"SPAN",{});var Ut=o(Se);I(Y.$$.fragment,Ut),Ut.forEach(t),zt.forEach(t),Ma=d(oa),Be=n(oa,"SPAN",{});var Gt=o(Be);qa=l(Gt,"Tips"),Gt.forEach(t),oa.forEach(t),Xe=d(a),h=n(a,"UL",{});var fe=o(h);w=n(fe,"LI",{});var he=o(w);Fa=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=d(fe),q=n(fe,"LI",{});var Fe=o(q);Wa=l(Fe,"To quickly demo "),De=n(Fe,"EM",{});var Vt=o(De);Ha=l(Vt,"PaintByExample"),Vt.forEach(t),Va=l(Fe,", please have a look at "),K=n(Fe,"A",{href:!0,rel:!0});var Rt=o(K);Ra=l(Rt,"this demo"),Rt.forEach(t),Fe.forEach(t),Ya=d(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=d(a),I(J.$$.fragment,a),Ke=d(a),E=n(a,"H2",{class:!0});var sa=o(E);F=n(sa,"A",{id:!0,class:!0,href:!0});var Xt=o(F);Ce=n(Xt,"SPAN",{});var Zt=o(Ce);I(Q.$$.fragment,Zt),Zt.forEach(t),Xt.forEach(t),Za=d(sa),Ae=n(sa,"SPAN",{});var Kt=o(Ae);Ka=l(Kt,"PaintByExamplePipeline"),Kt.forEach(t),sa.forEach(t),Je=d(a),f=n(a,"DIV",{class:!0});var u=o(f);I(ee.$$.fragment,u),Ja=d(u),ae=n(u,"P",{});var ra=o(ae);Qa=l(ra,"Pipeline for image-guided image inpainting using Stable Diffusion. "),je=n(ra,"EM",{});var Jt=o(je);et=l(Jt,"This is an experimental feature"),Jt.forEach(t),at=l(ra,"."),ra.forEach(t),tt=d(u),te=n(u,"P",{});var la=o(te);it=l(la,"This model inherits from "),de=n(la,"A",{href:!0});var Qt=o(de);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=d(u),N=n(u,"DIV",{class:!0});var pa=o(N);I(ie.$$.fragment,pa),rt=d(pa),Me=n(pa,"P",{});var ei=o(Me);lt=l(ei,"Function invoked when calling the pipeline for generation."),ei.forEach(t),pa.forEach(t),pt=d(u),O=n(u,"DIV",{class:!0});var da=o(O);I(ne.$$.fragment,da),dt=d(da),oe=n(da,"P",{});var ca=o(oe);ct=l(ca,`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
`),qe=n(ca,"CODE",{});var ai=o(qe);mt=l(ai,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),ai.forEach(t),ft=l(ca,"forward` method called."),ca.forEach(t),da.forEach(t),u.forEach(t),this.h()},h(){s(g,"name","hf:doc:metadata"),s(g,"content",JSON.stringify(di)),s(D,"id","paintbyexample"),s(D,"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(D,"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(M,"id","tips"),s(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"),s(M,"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(F,"id","diffusers.PaintByExamplePipeline"),s(F,"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(F,"href","#diffusers.PaintByExamplePipeline"),s(E,"class","relative group"),s(de,"href","/docs/diffusers/v0.16.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,c){e(document.head,g),m(a,Oe,c),m(a,_,c),e(_,D),e(D,ue),$(z,ue,null),e(_,ma),e(_,ge),e(ge,fa),m(a,ze,c),m(a,v,c),e(v,L),e(L,_e),$(U,_e,null),e(v,ha),e(v,ve),e(ve,ua),m(a,Ue,c),m(a,G,c),e(G,W),e(W,ga),e(G,_a),m(a,Ge,c),m(a,se,c),e(se,va),m(a,We,c),m(a,re,c),e(re,ye),e(ye,ya),m(a,He,c),m(a,C,c),e(C,ba),e(C,H),e(H,xa),e(C,Pa),m(a,Ve,c),m(a,y,c),e(y,A),e(A,be),$(V,be,null),e(y,wa),e(y,xe),e(xe,Ea),m(a,Re,c),m(a,j,c),e(j,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(j,Ba),e(j,ke),e(ke,x),e(x,Ie),e(Ie,R),e(R,Da),e(x,La),e(x,$e),e($e,Te),e(Te,Ca),e(x,Aa),e(x,pe),e(pe,ja),m(a,Ye,c),m(a,P,c),e(P,M),e(M,Se),$(Y,Se,null),e(P,Ma),e(P,Be),e(Be,qa),m(a,Xe,c),m(a,h,c),e(h,w),e(w,Fa),e(w,X),e(X,Na),e(w,Oa),e(w,Z),e(Z,za),e(w,Ua),e(h,Ga),e(h,q),e(q,Wa),e(q,De),e(De,Ha),e(q,Va),e(q,K),e(K,Ra),e(h,Ya),e(h,Le),e(Le,Xa),m(a,Ze,c),$(J,a,c),m(a,Ke,c),m(a,E,c),e(E,F),e(F,Ce),$(Q,Ce,null),e(E,Za),e(E,Ae),e(Ae,Ka),m(a,Je,c),m(a,f,c),$(ee,f,null),e(f,Ja),e(f,ae),e(ae,Qa),e(ae,je),e(je,et),e(ae,at),e(f,tt),e(f,te),e(te,it),e(te,de),e(de,nt),e(te,ot),e(f,st),e(f,N),$(ie,N,null),e(N,rt),e(N,Me),e(Me,lt),e(f,pt),e(f,O),$(ne,O,null),e(O,dt),e(O,oe),e(oe,ct),e(oe,qe),e(qe,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(_),B(z),a&&t(ze),a&&t(v),B(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),B(V),a&&t(Re),a&&t(j),a&&t(Ye),a&&t(P),B(Y),a&&t(Xe),a&&t(h),a&&t(Ze),B(J,a),a&&t(Ke),a&&t(E),B(Q),a&&t(Je),a&&t(f),B(ee),B(ie),B(ne)}}}const di={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 ci(gt){return ri(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class gi extends ti{constructor(g){super();ii(this,g,ci,pi,ni,{})}}export{gi as default,di as metadata};
