import{S as tn,i as nn,s as on,e as n,k as p,w as k,t as s,M as ln,c as i,d as t,m as c,a as o,x as T,h as r,b as l,G as e,g as m,y as M,L as sn,q as I,o as B,B as S,v as rn}from"../../../chunks/vendor-hf-doc-builder.js";import{D as ut}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as pn}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as De}from"../../../chunks/IconCopyLink-hf-doc-builder.js";function cn(gt){let g,Fe,_,J,ue,L,ma,ge,ha,Le,y,U,_e,X,fa,ye,ua,Xe,N,A,ga,_a,Ne,le,ya,Ae,se,ve,va,Re,$,ba,R,wa,xa,Ve,v,G,be,V,Pa,we,Ea,ze,W,xe,b,Pe,ka,Ta,Ee,Ma,Ia,re,Ba,Sa,ke,w,Te,z,Ja,Ua,Me,Ie,$a,Ga,pe,Wa,Qe,x,j,Be,Q,ja,Se,Ca,Ye,f,P,Za,Y,Da,Fa,q,La,Xa,Na,C,Aa,Je,Ra,Va,H,za,Qa,Ue,Ya,qe,O,He,E,Z,$e,K,qa,Ge,Ha,Oe,h,ee,Oa,ae,Ka,We,et,at,tt,te,nt,ce,it,ot,lt,D,ne,st,je,rt,pt,F,ie,ct,oe,dt,Ce,mt,ht,Ke;return L=new De({}),X=new De({}),V=new De({}),Q=new De({}),O=new pn({props:{code:"JTIzJTIwIXBpcCUyMGluc3RhbGwlMjBkaWZmdXNlcnMlMjB0cmFuc2Zvcm1lcnMlMEElMEFpbXBvcnQlMjBQSUwlMEFpbXBvcnQlMjByZXF1ZXN0cyUwQWltcG9ydCUyMHRvcmNoJTBBZnJvbSUyMGlvJTIwaW1wb3J0JTIwQnl0ZXNJTyUwQWZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBEaWZmdXNpb25QaXBlbGluZSUwQSUwQSUwQWRlZiUyMGRvd25sb2FkX2ltYWdlKHVybCklM0ElMEElMjAlMjAlMjAlMjByZXNwb25zZSUyMCUzRCUyMHJlcXVlc3RzLmdldCh1cmwpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwUElMLkltYWdlLm9wZW4oQnl0ZXNJTyhyZXNwb25zZS5jb250ZW50KSkuY29udmVydCglMjJSR0IlMjIpJTBBJTBBJTBBaW1nX3VybCUyMCUzRCUyMCUyMmh0dHBzJTNBJTJGJTJGcmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSUyRkZhbnRhc3ktU3R1ZGlvJTJGUGFpbnQtYnktRXhhbXBsZSUyRm1haW4lMkZleGFtcGxlcyUyRmltYWdlJTJGZXhhbXBsZV8xLnBuZyUyMiUwQW1hc2tfdXJsJTIwJTNEJTIwJTIyaHR0cHMlM0ElMkYlMkZyYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tJTJGRmFudGFzeS1TdHVkaW8lMkZQYWludC1ieS1FeGFtcGxlJTJGbWFpbiUyRmV4YW1wbGVzJTJGbWFzayUyRmV4YW1wbGVfMS5wbmclMjIlMEFleGFtcGxlX3VybCUyMCUzRCUyMCUyMmh0dHBzJTNBJTJGJTJGcmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSUyRkZhbnRhc3ktU3R1ZGlvJTJGUGFpbnQtYnktRXhhbXBsZSUyRm1haW4lMkZleGFtcGxlcyUyRnJlZmVyZW5jZSUyRmV4YW1wbGVfMS5qcGclMjIlMEElMEFpbml0X2ltYWdlJTIwJTNEJTIwZG93bmxvYWRfaW1hZ2UoaW1nX3VybCkucmVzaXplKCg1MTIlMkMlMjA1MTIpKSUwQW1hc2tfaW1hZ2UlMjAlM0QlMjBkb3dubG9hZF9pbWFnZShtYXNrX3VybCkucmVzaXplKCg1MTIlMkMlMjA1MTIpKSUwQWV4YW1wbGVfaW1hZ2UlMjAlM0QlMjBkb3dubG9hZF9pbWFnZShleGFtcGxlX3VybCkucmVzaXplKCg1MTIlMkMlMjA1MTIpKSUwQSUwQXBpcGUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyRmFudGFzeS1TdHVkaW8lMkZQYWludC1ieS1FeGFtcGxlJTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBKSUwQXBpcGUlMjAlM0QlMjBwaXBlLnRvKCUyMmN1ZGElMjIpJTBBJTBBaW1hZ2UlMjAlM0QlMjBwaXBlKGltYWdlJTNEaW5pdF9pbWFnZSUyQyUyMG1hc2tfaW1hZ2UlM0RtYXNrX2ltYWdlJTJDJTIwZXhhbXBsZV9pbWFnZSUzRGV4YW1wbGVfaW1hZ2UpLmltYWdlcyU1QjAlNUQlMEFpbWFnZQ==",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`}}),K=new De({}),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.17.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.17.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.17.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.17.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/v0.17.0/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/v0.17.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.17.0/src/diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py#L139"}}),ne=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.17.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.17.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.17.0/src/diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py#L400",returnDescription:`
<p><a
  href="/docs/diffusers/v0.17.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.17.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),ie=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.17.0/src/diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py#L192"}}),{c(){g=n("meta"),Fe=p(),_=n("h1"),J=n("a"),ue=n("span"),k(L.$$.fragment),ma=p(),ge=n("span"),ha=s("PaintByExample"),Le=p(),y=n("h2"),U=n("a"),_e=n("span"),k(X.$$.fragment),fa=p(),ye=n("span"),ua=s("Overview"),Xe=p(),N=n("p"),A=n("a"),ga=s("Paint by Example: Exemplar-based Image Editing with Diffusion Models"),_a=s(" by Binxin Yang, Shuyang Gu, Bo Zhang, Ting Zhang, Xuejin Chen, Xiaoyan Sun, Dong Chen, Fang Wen."),Ne=p(),le=n("p"),ya=s("The abstract of the paper is the following:"),Ae=p(),se=n("p"),ve=n("em"),va=s("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."),Re=p(),$=n("p"),ba=s("The original codebase can be found "),R=n("a"),wa=s("here"),xa=s("."),Ve=p(),v=n("h2"),G=n("a"),be=n("span"),k(V.$$.fragment),Pa=p(),we=n("span"),Ea=s("Available Pipelines:"),ze=p(),W=n("table"),xe=n("thead"),b=n("tr"),Pe=n("th"),ka=s("Pipeline"),Ta=p(),Ee=n("th"),Ma=s("Tasks"),Ia=p(),re=n("th"),Ba=s("Colab"),Sa=p(),ke=n("tbody"),w=n("tr"),Te=n("td"),z=n("a"),Ja=s("pipeline_paint_by_example.py"),Ua=p(),Me=n("td"),Ie=n("em"),$a=s("Image-Guided Image Painting"),Ga=p(),pe=n("td"),Wa=s("-"),Qe=p(),x=n("h2"),j=n("a"),Be=n("span"),k(Q.$$.fragment),ja=p(),Se=n("span"),Ca=s("Tips"),Ye=p(),f=n("ul"),P=n("li"),Za=s("PaintByExample is supported by the official "),Y=n("a"),Da=s("Fantasy-Studio/Paint-by-Example"),Fa=s(" checkpoint. The checkpoint has been warm-started from the "),q=n("a"),La=s("CompVis/stable-diffusion-v1-4"),Xa=s(" and with the objective to inpaint partly masked images conditioned on example / reference images"),Na=p(),C=n("li"),Aa=s("To quickly demo "),Je=n("em"),Ra=s("PaintByExample"),Va=s(", please have a look at "),H=n("a"),za=s("this demo"),Qa=p(),Ue=n("li"),Ya=s("You can run the following code snippet as an example:"),qe=p(),k(O.$$.fragment),He=p(),E=n("h2"),Z=n("a"),$e=n("span"),k(K.$$.fragment),qa=p(),Ge=n("span"),Ha=s("PaintByExamplePipeline"),Oe=p(),h=n("div"),k(ee.$$.fragment),Oa=p(),ae=n("p"),Ka=s("Pipeline for image-guided image inpainting using Stable Diffusion. "),We=n("em"),et=s("This is an experimental feature"),at=s("."),tt=p(),te=n("p"),nt=s("This model inherits from "),ce=n("a"),it=s("DiffusionPipeline"),ot=s(`. 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.)`),lt=p(),D=n("div"),k(ne.$$.fragment),st=p(),je=n("p"),rt=s("Function invoked when calling the pipeline for generation."),pt=p(),F=n("div"),k(ie.$$.fragment),ct=p(),oe=n("p"),dt=s(`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
`),Ce=n("code"),mt=s("torch.device('meta') and loaded to GPU only when their specific submodule has its "),ht=s("forward` method called."),this.h()},l(a){const d=ln('[data-svelte="svelte-1phssyn"]',document.head);g=i(d,"META",{name:!0,content:!0}),d.forEach(t),Fe=c(a),_=i(a,"H1",{class:!0});var ea=o(_);J=i(ea,"A",{id:!0,class:!0,href:!0});var _t=o(J);ue=i(_t,"SPAN",{});var yt=o(ue);T(L.$$.fragment,yt),yt.forEach(t),_t.forEach(t),ma=c(ea),ge=i(ea,"SPAN",{});var vt=o(ge);ha=r(vt,"PaintByExample"),vt.forEach(t),ea.forEach(t),Le=c(a),y=i(a,"H2",{class:!0});var aa=o(y);U=i(aa,"A",{id:!0,class:!0,href:!0});var bt=o(U);_e=i(bt,"SPAN",{});var wt=o(_e);T(X.$$.fragment,wt),wt.forEach(t),bt.forEach(t),fa=c(aa),ye=i(aa,"SPAN",{});var xt=o(ye);ua=r(xt,"Overview"),xt.forEach(t),aa.forEach(t),Xe=c(a),N=i(a,"P",{});var ft=o(N);A=i(ft,"A",{href:!0,rel:!0});var Pt=o(A);ga=r(Pt,"Paint by Example: Exemplar-based Image Editing with Diffusion Models"),Pt.forEach(t),_a=r(ft," by Binxin Yang, Shuyang Gu, Bo Zhang, Ting Zhang, Xuejin Chen, Xiaoyan Sun, Dong Chen, Fang Wen."),ft.forEach(t),Ne=c(a),le=i(a,"P",{});var Et=o(le);ya=r(Et,"The abstract of the paper is the following:"),Et.forEach(t),Ae=c(a),se=i(a,"P",{});var kt=o(se);ve=i(kt,"EM",{});var Tt=o(ve);va=r(Tt,"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."),Tt.forEach(t),kt.forEach(t),Re=c(a),$=i(a,"P",{});var ta=o($);ba=r(ta,"The original codebase can be found "),R=i(ta,"A",{href:!0,rel:!0});var Mt=o(R);wa=r(Mt,"here"),Mt.forEach(t),xa=r(ta,"."),ta.forEach(t),Ve=c(a),v=i(a,"H2",{class:!0});var na=o(v);G=i(na,"A",{id:!0,class:!0,href:!0});var It=o(G);be=i(It,"SPAN",{});var Bt=o(be);T(V.$$.fragment,Bt),Bt.forEach(t),It.forEach(t),Pa=c(na),we=i(na,"SPAN",{});var St=o(we);Ea=r(St,"Available Pipelines:"),St.forEach(t),na.forEach(t),ze=c(a),W=i(a,"TABLE",{});var ia=o(W);xe=i(ia,"THEAD",{});var Jt=o(xe);b=i(Jt,"TR",{});var de=o(b);Pe=i(de,"TH",{});var Ut=o(Pe);ka=r(Ut,"Pipeline"),Ut.forEach(t),Ta=c(de),Ee=i(de,"TH",{});var $t=o(Ee);Ma=r($t,"Tasks"),$t.forEach(t),Ia=c(de),re=i(de,"TH",{align:!0});var Gt=o(re);Ba=r(Gt,"Colab"),Gt.forEach(t),de.forEach(t),Jt.forEach(t),Sa=c(ia),ke=i(ia,"TBODY",{});var Wt=o(ke);w=i(Wt,"TR",{});var me=o(w);Te=i(me,"TD",{});var jt=o(Te);z=i(jt,"A",{href:!0,rel:!0});var Ct=o(z);Ja=r(Ct,"pipeline_paint_by_example.py"),Ct.forEach(t),jt.forEach(t),Ua=c(me),Me=i(me,"TD",{});var Zt=o(Me);Ie=i(Zt,"EM",{});var Dt=o(Ie);$a=r(Dt,"Image-Guided Image Painting"),Dt.forEach(t),Zt.forEach(t),Ga=c(me),pe=i(me,"TD",{align:!0});var Ft=o(pe);Wa=r(Ft,"-"),Ft.forEach(t),me.forEach(t),Wt.forEach(t),ia.forEach(t),Qe=c(a),x=i(a,"H2",{class:!0});var oa=o(x);j=i(oa,"A",{id:!0,class:!0,href:!0});var Lt=o(j);Be=i(Lt,"SPAN",{});var Xt=o(Be);T(Q.$$.fragment,Xt),Xt.forEach(t),Lt.forEach(t),ja=c(oa),Se=i(oa,"SPAN",{});var Nt=o(Se);Ca=r(Nt,"Tips"),Nt.forEach(t),oa.forEach(t),Ye=c(a),f=i(a,"UL",{});var he=o(f);P=i(he,"LI",{});var fe=o(P);Za=r(fe,"PaintByExample is supported by the official "),Y=i(fe,"A",{href:!0,rel:!0});var At=o(Y);Da=r(At,"Fantasy-Studio/Paint-by-Example"),At.forEach(t),Fa=r(fe," checkpoint. The checkpoint has been warm-started from the "),q=i(fe,"A",{href:!0,rel:!0});var Rt=o(q);La=r(Rt,"CompVis/stable-diffusion-v1-4"),Rt.forEach(t),Xa=r(fe," and with the objective to inpaint partly masked images conditioned on example / reference images"),fe.forEach(t),Na=c(he),C=i(he,"LI",{});var Ze=o(C);Aa=r(Ze,"To quickly demo "),Je=i(Ze,"EM",{});var Vt=o(Je);Ra=r(Vt,"PaintByExample"),Vt.forEach(t),Va=r(Ze,", please have a look at "),H=i(Ze,"A",{href:!0,rel:!0});var zt=o(H);za=r(zt,"this demo"),zt.forEach(t),Ze.forEach(t),Qa=c(he),Ue=i(he,"LI",{});var Qt=o(Ue);Ya=r(Qt,"You can run the following code snippet as an example:"),Qt.forEach(t),he.forEach(t),qe=c(a),T(O.$$.fragment,a),He=c(a),E=i(a,"H2",{class:!0});var la=o(E);Z=i(la,"A",{id:!0,class:!0,href:!0});var Yt=o(Z);$e=i(Yt,"SPAN",{});var qt=o($e);T(K.$$.fragment,qt),qt.forEach(t),Yt.forEach(t),qa=c(la),Ge=i(la,"SPAN",{});var Ht=o(Ge);Ha=r(Ht,"PaintByExamplePipeline"),Ht.forEach(t),la.forEach(t),Oe=c(a),h=i(a,"DIV",{class:!0});var u=o(h);T(ee.$$.fragment,u),Oa=c(u),ae=i(u,"P",{});var sa=o(ae);Ka=r(sa,"Pipeline for image-guided image inpainting using Stable Diffusion. "),We=i(sa,"EM",{});var Ot=o(We);et=r(Ot,"This is an experimental feature"),Ot.forEach(t),at=r(sa,"."),sa.forEach(t),tt=c(u),te=i(u,"P",{});var ra=o(te);nt=r(ra,"This model inherits from "),ce=i(ra,"A",{href:!0});var Kt=o(ce);it=r(Kt,"DiffusionPipeline"),Kt.forEach(t),ot=r(ra,`. 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.)`),ra.forEach(t),lt=c(u),D=i(u,"DIV",{class:!0});var pa=o(D);T(ne.$$.fragment,pa),st=c(pa),je=i(pa,"P",{});var en=o(je);rt=r(en,"Function invoked when calling the pipeline for generation."),en.forEach(t),pa.forEach(t),pt=c(u),F=i(u,"DIV",{class:!0});var ca=o(F);T(ie.$$.fragment,ca),ct=c(ca),oe=i(ca,"P",{});var da=o(oe);dt=r(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
`),Ce=i(da,"CODE",{});var an=o(Ce);mt=r(an,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),an.forEach(t),ht=r(da,"forward` method called."),da.forEach(t),ca.forEach(t),u.forEach(t),this.h()},h(){l(g,"name","hf:doc:metadata"),l(g,"content",JSON.stringify(dn)),l(J,"id","paintbyexample"),l(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"),l(J,"href","#paintbyexample"),l(_,"class","relative group"),l(U,"id","overview"),l(U,"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"),l(U,"href","#overview"),l(y,"class","relative group"),l(A,"href","https://arxiv.org/abs/2211.13227"),l(A,"rel","nofollow"),l(R,"href","https://github.com/Fantasy-Studio/Paint-by-Example"),l(R,"rel","nofollow"),l(G,"id","available-pipelines"),l(G,"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"),l(G,"href","#available-pipelines"),l(v,"class","relative group"),l(re,"align","center"),l(z,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/paint_by_example/pipeline_paint_by_example.py"),l(z,"rel","nofollow"),l(pe,"align","center"),l(j,"id","tips"),l(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"),l(j,"href","#tips"),l(x,"class","relative group"),l(Y,"href","https://huggingface.co/Fantasy-Studio/Paint-by-Example"),l(Y,"rel","nofollow"),l(q,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),l(q,"rel","nofollow"),l(H,"href","https://huggingface.co/spaces/Fantasy-Studio/Paint-by-Example"),l(H,"rel","nofollow"),l(Z,"id","diffusers.PaintByExamplePipeline"),l(Z,"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"),l(Z,"href","#diffusers.PaintByExamplePipeline"),l(E,"class","relative group"),l(ce,"href","/docs/diffusers/v0.17.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),l(D,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(F,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(h,"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,Fe,d),m(a,_,d),e(_,J),e(J,ue),M(L,ue,null),e(_,ma),e(_,ge),e(ge,ha),m(a,Le,d),m(a,y,d),e(y,U),e(U,_e),M(X,_e,null),e(y,fa),e(y,ye),e(ye,ua),m(a,Xe,d),m(a,N,d),e(N,A),e(A,ga),e(N,_a),m(a,Ne,d),m(a,le,d),e(le,ya),m(a,Ae,d),m(a,se,d),e(se,ve),e(ve,va),m(a,Re,d),m(a,$,d),e($,ba),e($,R),e(R,wa),e($,xa),m(a,Ve,d),m(a,v,d),e(v,G),e(G,be),M(V,be,null),e(v,Pa),e(v,we),e(we,Ea),m(a,ze,d),m(a,W,d),e(W,xe),e(xe,b),e(b,Pe),e(Pe,ka),e(b,Ta),e(b,Ee),e(Ee,Ma),e(b,Ia),e(b,re),e(re,Ba),e(W,Sa),e(W,ke),e(ke,w),e(w,Te),e(Te,z),e(z,Ja),e(w,Ua),e(w,Me),e(Me,Ie),e(Ie,$a),e(w,Ga),e(w,pe),e(pe,Wa),m(a,Qe,d),m(a,x,d),e(x,j),e(j,Be),M(Q,Be,null),e(x,ja),e(x,Se),e(Se,Ca),m(a,Ye,d),m(a,f,d),e(f,P),e(P,Za),e(P,Y),e(Y,Da),e(P,Fa),e(P,q),e(q,La),e(P,Xa),e(f,Na),e(f,C),e(C,Aa),e(C,Je),e(Je,Ra),e(C,Va),e(C,H),e(H,za),e(f,Qa),e(f,Ue),e(Ue,Ya),m(a,qe,d),M(O,a,d),m(a,He,d),m(a,E,d),e(E,Z),e(Z,$e),M(K,$e,null),e(E,qa),e(E,Ge),e(Ge,Ha),m(a,Oe,d),m(a,h,d),M(ee,h,null),e(h,Oa),e(h,ae),e(ae,Ka),e(ae,We),e(We,et),e(ae,at),e(h,tt),e(h,te),e(te,nt),e(te,ce),e(ce,it),e(te,ot),e(h,lt),e(h,D),M(ne,D,null),e(D,st),e(D,je),e(je,rt),e(h,pt),e(h,F),M(ie,F,null),e(F,ct),e(F,oe),e(oe,dt),e(oe,Ce),e(Ce,mt),e(oe,ht),Ke=!0},p:sn,i(a){Ke||(I(L.$$.fragment,a),I(X.$$.fragment,a),I(V.$$.fragment,a),I(Q.$$.fragment,a),I(O.$$.fragment,a),I(K.$$.fragment,a),I(ee.$$.fragment,a),I(ne.$$.fragment,a),I(ie.$$.fragment,a),Ke=!0)},o(a){B(L.$$.fragment,a),B(X.$$.fragment,a),B(V.$$.fragment,a),B(Q.$$.fragment,a),B(O.$$.fragment,a),B(K.$$.fragment,a),B(ee.$$.fragment,a),B(ne.$$.fragment,a),B(ie.$$.fragment,a),Ke=!1},d(a){t(g),a&&t(Fe),a&&t(_),S(L),a&&t(Le),a&&t(y),S(X),a&&t(Xe),a&&t(N),a&&t(Ne),a&&t(le),a&&t(Ae),a&&t(se),a&&t(Re),a&&t($),a&&t(Ve),a&&t(v),S(V),a&&t(ze),a&&t(W),a&&t(Qe),a&&t(x),S(Q),a&&t(Ye),a&&t(f),a&&t(qe),S(O,a),a&&t(He),a&&t(E),S(K),a&&t(Oe),a&&t(h),S(ee),S(ne),S(ie)}}}const dn={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 mn(gt){return rn(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class _n extends tn{constructor(g){super();nn(this,g,mn,cn,on,{})}}export{_n as default,dn as metadata};
