import{S as un,i as gn,s as hn,e as i,k as f,w,t as o,M as _n,c as a,d as n,m as c,a as s,x as P,h as r,b as l,G as e,g as v,y as D,q as $,o as S,B as x,v as bn,L as vn}from"../../../../chunks/vendor-hf-doc-builder.js";import{D as se}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as In}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as mn}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as yn}from"../../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function wn($e){let g,L,b,h,k;return h=new In({props:{code:`import requests
import torch
from PIL import Image
from io import BytesIO

from diffusers import StableDiffusionImg2ImgPipeline

device = "cuda"
model_id_or_path = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
pipe = pipe.to(device)

url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"

response = requests.get(url)
init_image = Image.open(BytesIO(response.content)).convert("RGB")
init_image = init_image.resize((768, 512))

prompt = "A fantasy landscape, trending on artstation"

images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images
images[0].save("fantasy_landscape.png")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> io <span class="hljs-keyword">import</span> BytesIO

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

<span class="hljs-meta">&gt;&gt;&gt; </span>device = <span class="hljs-string">&quot;cuda&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model_id_or_path = <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = pipe.to(device)

<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>response = requests.get(url)
<span class="hljs-meta">&gt;&gt;&gt; </span>init_image = Image.<span class="hljs-built_in">open</span>(BytesIO(response.content)).convert(<span class="hljs-string">&quot;RGB&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>init_image = init_image.resize((<span class="hljs-number">768</span>, <span class="hljs-number">512</span>))

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;A fantasy landscape, trending on artstation&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>images = pipe(prompt=prompt, image=init_image, strength=<span class="hljs-number">0.75</span>, guidance_scale=<span class="hljs-number">7.5</span>).images
<span class="hljs-meta">&gt;&gt;&gt; </span>images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;fantasy_landscape.png&quot;</span>)`}}),{c(){g=i("p"),L=o("Examples:"),b=f(),w(h.$$.fragment)},l(p){g=a(p,"P",{});var E=s(g);L=r(E,"Examples:"),E.forEach(n),b=c(p),P(h.$$.fragment,p)},m(p,E){v(p,g,E),e(g,L),v(p,b,E),D(h,p,E),k=!0},p:vn,i(p){k||($(h.$$.fragment,p),k=!0)},o(p){S(h.$$.fragment,p),k=!1},d(p){p&&n(g),p&&n(b),x(h,p)}}}function Pn($e){let g,L,b,h,k,p,E,de,ze,Se,j,q,me,G,Ge,ue,Ve,xe,_,We,V,Be,Fe,W,Ke,He,B,Re,Je,F,Qe,Xe,oe,Ye,Ze,ke,K,et,H,tt,Ee,A,re,nt,it,le,at,Ce,d,R,st,ge,ot,rt,J,lt,fe,ft,ct,pt,C,Q,dt,he,mt,ut,M,gt,T,X,ht,_e,_t,bt,be,vt,It,O,Y,yt,Z,wt,ve,Pt,Dt,$t,I,ee,St,Ie,xt,kt,ye,Et,Ct,we,Tt,jt,N,te,Lt,Pe,qt,At,U,ne,Mt,ie,Ot,De,Nt,Ut,Te;return p=new mn({}),G=new mn({}),R=new se({props:{name:"class diffusers.StableDiffusionImg2ImgPipeline",anchor:"diffusers.StableDiffusionImg2ImgPipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": CLIPTextModel"},{name:"tokenizer",val:": CLIPTokenizer"},{name:"unet",val:": UNet2DConditionModel"},{name:"scheduler",val:": KarrasDiffusionSchedulers"},{name:"safety_checker",val:": StableDiffusionSafetyChecker"},{name:"feature_extractor",val:": CLIPFeatureExtractor"},{name:"requires_safety_checker",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.StableDiffusionImg2ImgPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/main/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.StableDiffusionImg2ImgPipeline.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.StableDiffusionImg2ImgPipeline.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.StableDiffusionImg2ImgPipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/main/en/api/models#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.StableDiffusionImg2ImgPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/main/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/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/main/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/main/en/api/schedulers/pndm#diffusers.PNDMScheduler">PNDMScheduler</a>.`,name:"scheduler"},{anchor:"diffusers.StableDiffusionImg2ImgPipeline.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.StableDiffusionImg2ImgPipeline.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/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py#L93"}}),Q=new se({props:{name:"__call__",anchor:"diffusers.StableDiffusionImg2ImgPipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str]]"},{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image] = None"},{name:"strength",val:": float = 0.8"},{name:"num_inference_steps",val:": typing.Optional[int] = 50"},{name:"guidance_scale",val:": typing.Optional[float] = 7.5"},{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:": typing.Optional[float] = 0.0"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = 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"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>) &#x2014;
The prompt or prompts to guide the image generation.`,name:"prompt"},{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__call__.image",description:`<strong>image</strong> (<code>torch.FloatTensor</code> or <code>PIL.Image.Image</code>) &#x2014;
<code>Image</code>, or tensor representing an image batch, that will be used as the starting point for the
process.`,name:"image"},{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__call__.strength",description:`<strong>strength</strong> (<code>float</code>, <em>optional</em>, defaults to 0.8) &#x2014;
Conceptually, indicates how much to transform the reference <code>image</code>. Must be between 0 and 1. <code>image</code>
will be used as a starting point, adding more noise to it the larger the <code>strength</code>. The number of
denoising steps depends on the amount of noise initially added. When <code>strength</code> is 1, added noise will
be maximum and the denoising process will run for the full number of iterations specified in
<code>num_inference_steps</code>. A value of 1, therefore, essentially ignores <code>image</code>.`,name:"strength"},{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__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. This parameter will be modulated by <code>strength</code>.`,name:"num_inference_steps"},{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">schedulers.DDIMScheduler</a>, will be ignored for others.`,name:"eta"},{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py#L471",returnDescription:`
<p><a
  href="/docs/diffusers/main/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/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),M=new yn({props:{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__call__.example",$$slots:{default:[wn]},$$scope:{ctx:$e}}}),X=new se({props:{name:"enable_attention_slicing",anchor:"diffusers.StableDiffusionImg2ImgPipeline.enable_attention_slicing",parameters:[{name:"slice_size",val:": typing.Union[str, int, NoneType] = 'auto'"}],parametersDescription:[{anchor:"diffusers.StableDiffusionImg2ImgPipeline.enable_attention_slicing.slice_size",description:`<strong>slice_size</strong> (<code>str</code> or <code>int</code>, <em>optional</em>, defaults to <code>&quot;auto&quot;</code>) &#x2014;
When <code>&quot;auto&quot;</code>, halves the input to the attention heads, so attention will be computed in two steps. If
<code>&quot;max&quot;</code>, maxium amount of memory will be saved by running only one slice at a time. If a number is
provided, uses as many slices as <code>attention_head_dim // slice_size</code>. In this case, <code>attention_head_dim</code>
must be a multiple of <code>slice_size</code>.`,name:"slice_size"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L876"}}),Y=new se({props:{name:"disable_attention_slicing",anchor:"diffusers.StableDiffusionImg2ImgPipeline.disable_attention_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L892"}}),ee=new se({props:{name:"enable_xformers_memory_efficient_attention",anchor:"diffusers.StableDiffusionImg2ImgPipeline.enable_xformers_memory_efficient_attention",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L841"}}),te=new se({props:{name:"disable_xformers_memory_efficient_attention",anchor:"diffusers.StableDiffusionImg2ImgPipeline.disable_xformers_memory_efficient_attention",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L853"}}),ne=new se({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.StableDiffusionImg2ImgPipeline.enable_sequential_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py#L213"}}),{c(){g=i("meta"),L=f(),b=i("h1"),h=i("a"),k=i("span"),w(p.$$.fragment),E=f(),de=i("span"),ze=o("Image-to-Image Generation"),Se=f(),j=i("h2"),q=i("a"),me=i("span"),w(G.$$.fragment),Ge=f(),ue=i("span"),Ve=o("StableDiffusionImg2ImgPipeline"),xe=f(),_=i("p"),We=o("The Stable Diffusion model was created by the researchers and engineers from "),V=i("a"),Be=o("CompVis"),Fe=o(", "),W=i("a"),Ke=o("Stability AI"),He=o(", "),B=i("a"),Re=o("runway"),Je=o(", and "),F=i("a"),Qe=o("LAION"),Xe=o(". The "),oe=i("a"),Ye=o("StableDiffusionImg2ImgPipeline"),Ze=o(" lets you pass a text prompt and an initial image to condition the generation of new images using Stable Diffusion."),ke=f(),K=i("p"),et=o("The original codebase can be found here: "),H=i("a"),tt=o("CampVis/stable-diffusion"),Ee=f(),A=i("p"),re=i("a"),nt=o("StableDiffusionImg2ImgPipeline"),it=o(" is compatible with all Stable Diffusion checkpoints for "),le=i("a"),at=o("Text-to-Image"),Ce=f(),d=i("div"),w(R.$$.fragment),st=f(),ge=i("p"),ot=o("Pipeline for text-guided image to image generation using Stable Diffusion."),rt=f(),J=i("p"),lt=o("This model inherits from "),fe=i("a"),ft=o("DiffusionPipeline"),ct=o(`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),pt=f(),C=i("div"),w(Q.$$.fragment),dt=f(),he=i("p"),mt=o("Function invoked when calling the pipeline for generation."),ut=f(),w(M.$$.fragment),gt=f(),T=i("div"),w(X.$$.fragment),ht=f(),_e=i("p"),_t=o("Enable sliced attention computation."),bt=f(),be=i("p"),vt=o(`When this option is enabled, the attention module will split the input tensor in slices, to compute attention
in several steps. This is useful to save some memory in exchange for a small speed decrease.`),It=f(),O=i("div"),w(Y.$$.fragment),yt=f(),Z=i("p"),wt=o("Disable sliced attention computation. If "),ve=i("code"),Pt=o("enable_attention_slicing"),Dt=o(` was previously invoked, this method will go
back to computing attention in one step.`),$t=f(),I=i("div"),w(ee.$$.fragment),St=f(),Ie=i("p"),xt=o("Enable memory efficient attention as implemented in xformers."),kt=f(),ye=i("p"),Et=o(`When this option is enabled, you should observe lower GPU memory usage and a potential speed up at inference
time. Speed up at training time is not guaranteed.`),Ct=f(),we=i("p"),Tt=o(`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),jt=f(),N=i("div"),w(te.$$.fragment),Lt=f(),Pe=i("p"),qt=o("Disable memory efficient attention as implemented in xformers."),At=f(),U=i("div"),w(ne.$$.fragment),Mt=f(),ie=i("p"),Ot=o(`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),De=i("code"),Nt=o("torch.device('meta') and loaded to GPU only when their specific submodule has its "),Ut=o("forward` method called."),this.h()},l(t){const m=_n('[data-svelte="svelte-1phssyn"]',document.head);g=a(m,"META",{name:!0,content:!0}),m.forEach(n),L=c(t),b=a(t,"H1",{class:!0});var ae=s(b);h=a(ae,"A",{id:!0,class:!0,href:!0});var Gt=s(h);k=a(Gt,"SPAN",{});var Vt=s(k);P(p.$$.fragment,Vt),Vt.forEach(n),Gt.forEach(n),E=c(ae),de=a(ae,"SPAN",{});var Wt=s(de);ze=r(Wt,"Image-to-Image Generation"),Wt.forEach(n),ae.forEach(n),Se=c(t),j=a(t,"H2",{class:!0});var je=s(j);q=a(je,"A",{id:!0,class:!0,href:!0});var Bt=s(q);me=a(Bt,"SPAN",{});var Ft=s(me);P(G.$$.fragment,Ft),Ft.forEach(n),Bt.forEach(n),Ge=c(je),ue=a(je,"SPAN",{});var Kt=s(ue);Ve=r(Kt,"StableDiffusionImg2ImgPipeline"),Kt.forEach(n),je.forEach(n),xe=c(t),_=a(t,"P",{});var y=s(_);We=r(y,"The Stable Diffusion model was created by the researchers and engineers from "),V=a(y,"A",{href:!0,rel:!0});var Ht=s(V);Be=r(Ht,"CompVis"),Ht.forEach(n),Fe=r(y,", "),W=a(y,"A",{href:!0,rel:!0});var Rt=s(W);Ke=r(Rt,"Stability AI"),Rt.forEach(n),He=r(y,", "),B=a(y,"A",{href:!0,rel:!0});var Jt=s(B);Re=r(Jt,"runway"),Jt.forEach(n),Je=r(y,", and "),F=a(y,"A",{href:!0,rel:!0});var Qt=s(F);Qe=r(Qt,"LAION"),Qt.forEach(n),Xe=r(y,". The "),oe=a(y,"A",{href:!0});var Xt=s(oe);Ye=r(Xt,"StableDiffusionImg2ImgPipeline"),Xt.forEach(n),Ze=r(y," lets you pass a text prompt and an initial image to condition the generation of new images using Stable Diffusion."),y.forEach(n),ke=c(t),K=a(t,"P",{});var zt=s(K);et=r(zt,"The original codebase can be found here: "),H=a(zt,"A",{href:!0,rel:!0});var Yt=s(H);tt=r(Yt,"CampVis/stable-diffusion"),Yt.forEach(n),zt.forEach(n),Ee=c(t),A=a(t,"P",{});var Le=s(A);re=a(Le,"A",{href:!0});var Zt=s(re);nt=r(Zt,"StableDiffusionImg2ImgPipeline"),Zt.forEach(n),it=r(Le," is compatible with all Stable Diffusion checkpoints for "),le=a(Le,"A",{href:!0});var en=s(le);at=r(en,"Text-to-Image"),en.forEach(n),Le.forEach(n),Ce=c(t),d=a(t,"DIV",{class:!0});var u=s(d);P(R.$$.fragment,u),st=c(u),ge=a(u,"P",{});var tn=s(ge);ot=r(tn,"Pipeline for text-guided image to image generation using Stable Diffusion."),tn.forEach(n),rt=c(u),J=a(u,"P",{});var qe=s(J);lt=r(qe,"This model inherits from "),fe=a(qe,"A",{href:!0});var nn=s(fe);ft=r(nn,"DiffusionPipeline"),nn.forEach(n),ct=r(qe,`. 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.)`),qe.forEach(n),pt=c(u),C=a(u,"DIV",{class:!0});var ce=s(C);P(Q.$$.fragment,ce),dt=c(ce),he=a(ce,"P",{});var an=s(he);mt=r(an,"Function invoked when calling the pipeline for generation."),an.forEach(n),ut=c(ce),P(M.$$.fragment,ce),ce.forEach(n),gt=c(u),T=a(u,"DIV",{class:!0});var pe=s(T);P(X.$$.fragment,pe),ht=c(pe),_e=a(pe,"P",{});var sn=s(_e);_t=r(sn,"Enable sliced attention computation."),sn.forEach(n),bt=c(pe),be=a(pe,"P",{});var on=s(be);vt=r(on,`When this option is enabled, the attention module will split the input tensor in slices, to compute attention
in several steps. This is useful to save some memory in exchange for a small speed decrease.`),on.forEach(n),pe.forEach(n),It=c(u),O=a(u,"DIV",{class:!0});var Ae=s(O);P(Y.$$.fragment,Ae),yt=c(Ae),Z=a(Ae,"P",{});var Me=s(Z);wt=r(Me,"Disable sliced attention computation. If "),ve=a(Me,"CODE",{});var rn=s(ve);Pt=r(rn,"enable_attention_slicing"),rn.forEach(n),Dt=r(Me,` was previously invoked, this method will go
back to computing attention in one step.`),Me.forEach(n),Ae.forEach(n),$t=c(u),I=a(u,"DIV",{class:!0});var z=s(I);P(ee.$$.fragment,z),St=c(z),Ie=a(z,"P",{});var ln=s(Ie);xt=r(ln,"Enable memory efficient attention as implemented in xformers."),ln.forEach(n),kt=c(z),ye=a(z,"P",{});var fn=s(ye);Et=r(fn,`When this option is enabled, you should observe lower GPU memory usage and a potential speed up at inference
time. Speed up at training time is not guaranteed.`),fn.forEach(n),Ct=c(z),we=a(z,"P",{});var cn=s(we);Tt=r(cn,`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),cn.forEach(n),z.forEach(n),jt=c(u),N=a(u,"DIV",{class:!0});var Oe=s(N);P(te.$$.fragment,Oe),Lt=c(Oe),Pe=a(Oe,"P",{});var pn=s(Pe);qt=r(pn,"Disable memory efficient attention as implemented in xformers."),pn.forEach(n),Oe.forEach(n),At=c(u),U=a(u,"DIV",{class:!0});var Ne=s(U);P(ne.$$.fragment,Ne),Mt=c(Ne),ie=a(Ne,"P",{});var Ue=s(ie);Ot=r(Ue,`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
`),De=a(Ue,"CODE",{});var dn=s(De);Nt=r(dn,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),dn.forEach(n),Ut=r(Ue,"forward` method called."),Ue.forEach(n),Ne.forEach(n),u.forEach(n),this.h()},h(){l(g,"name","hf:doc:metadata"),l(g,"content",JSON.stringify(Dn)),l(h,"id","imagetoimage-generation"),l(h,"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(h,"href","#imagetoimage-generation"),l(b,"class","relative group"),l(q,"id","diffusers.StableDiffusionImg2ImgPipeline"),l(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"),l(q,"href","#diffusers.StableDiffusionImg2ImgPipeline"),l(j,"class","relative group"),l(V,"href","https://github.com/CompVis"),l(V,"rel","nofollow"),l(W,"href","https://stability.ai/"),l(W,"rel","nofollow"),l(B,"href","https://github.com/runwayml"),l(B,"rel","nofollow"),l(F,"href","https://laion.ai/"),l(F,"rel","nofollow"),l(oe,"href","/docs/diffusers/main/en/api/pipelines/stable_diffusion/img2img#diffusers.StableDiffusionImg2ImgPipeline"),l(H,"href","https://github.com/CompVis/stable-diffusion/blob/main/scripts/img2img.py"),l(H,"rel","nofollow"),l(re,"href","/docs/diffusers/main/en/api/pipelines/stable_diffusion/img2img#diffusers.StableDiffusionImg2ImgPipeline"),l(le,"href","./text2img"),l(fe,"href","/docs/diffusers/main/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),l(C,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(O,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(N,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(U,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),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")},m(t,m){e(document.head,g),v(t,L,m),v(t,b,m),e(b,h),e(h,k),D(p,k,null),e(b,E),e(b,de),e(de,ze),v(t,Se,m),v(t,j,m),e(j,q),e(q,me),D(G,me,null),e(j,Ge),e(j,ue),e(ue,Ve),v(t,xe,m),v(t,_,m),e(_,We),e(_,V),e(V,Be),e(_,Fe),e(_,W),e(W,Ke),e(_,He),e(_,B),e(B,Re),e(_,Je),e(_,F),e(F,Qe),e(_,Xe),e(_,oe),e(oe,Ye),e(_,Ze),v(t,ke,m),v(t,K,m),e(K,et),e(K,H),e(H,tt),v(t,Ee,m),v(t,A,m),e(A,re),e(re,nt),e(A,it),e(A,le),e(le,at),v(t,Ce,m),v(t,d,m),D(R,d,null),e(d,st),e(d,ge),e(ge,ot),e(d,rt),e(d,J),e(J,lt),e(J,fe),e(fe,ft),e(J,ct),e(d,pt),e(d,C),D(Q,C,null),e(C,dt),e(C,he),e(he,mt),e(C,ut),D(M,C,null),e(d,gt),e(d,T),D(X,T,null),e(T,ht),e(T,_e),e(_e,_t),e(T,bt),e(T,be),e(be,vt),e(d,It),e(d,O),D(Y,O,null),e(O,yt),e(O,Z),e(Z,wt),e(Z,ve),e(ve,Pt),e(Z,Dt),e(d,$t),e(d,I),D(ee,I,null),e(I,St),e(I,Ie),e(Ie,xt),e(I,kt),e(I,ye),e(ye,Et),e(I,Ct),e(I,we),e(we,Tt),e(d,jt),e(d,N),D(te,N,null),e(N,Lt),e(N,Pe),e(Pe,qt),e(d,At),e(d,U),D(ne,U,null),e(U,Mt),e(U,ie),e(ie,Ot),e(ie,De),e(De,Nt),e(ie,Ut),Te=!0},p(t,[m]){const ae={};m&2&&(ae.$$scope={dirty:m,ctx:t}),M.$set(ae)},i(t){Te||($(p.$$.fragment,t),$(G.$$.fragment,t),$(R.$$.fragment,t),$(Q.$$.fragment,t),$(M.$$.fragment,t),$(X.$$.fragment,t),$(Y.$$.fragment,t),$(ee.$$.fragment,t),$(te.$$.fragment,t),$(ne.$$.fragment,t),Te=!0)},o(t){S(p.$$.fragment,t),S(G.$$.fragment,t),S(R.$$.fragment,t),S(Q.$$.fragment,t),S(M.$$.fragment,t),S(X.$$.fragment,t),S(Y.$$.fragment,t),S(ee.$$.fragment,t),S(te.$$.fragment,t),S(ne.$$.fragment,t),Te=!1},d(t){n(g),t&&n(L),t&&n(b),x(p),t&&n(Se),t&&n(j),x(G),t&&n(xe),t&&n(_),t&&n(ke),t&&n(K),t&&n(Ee),t&&n(A),t&&n(Ce),t&&n(d),x(R),x(Q),x(M),x(X),x(Y),x(ee),x(te),x(ne)}}}const Dn={local:"imagetoimage-generation",sections:[{local:"diffusers.StableDiffusionImg2ImgPipeline",title:"StableDiffusionImg2ImgPipeline"}],title:"Image-to-Image Generation"};function $n($e){return bn(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Tn extends un{constructor(g){super();gn(this,g,$n,Pn,hn,{})}}export{Tn as default,Dn as metadata};
