Buckets:
hf-doc-build/doc / diffusers /v0.16.0 /en /_app /pages /using-diffusers /depth2img.mdx-hf-doc-builder.js
| import{S as st,i as rt,s as nt,e as o,k as d,w as pe,t as n,M as pt,c as i,d as t,m as h,a as s,x as le,h as p,b as l,N as Oe,G as a,g as m,y as me,L as lt,q as fe,o as de,B as he,v as mt}from"../../chunks/vendor-hf-doc-builder.js";import{I as ft}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as it}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as dt}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function ht(Le){let c,z,b,_,M,$,ue,N,ge,J,D,U,f,ce,T,be,_e,C,ve,we,O,ye,$e,E,De,Ee,K,v,Ie,q,ke,Pe,Q,I,V,w,Se,L,Te,qe,W,k,X,y,B,P,H,je,xe,R,Ae,Me,F,S,G,j,Be,Ne,Y,x,He,Z,A,Ce,ee,u,Re,te;return $=new ft({}),D=new dt({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/depth2img.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/depth2img.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/depth2img.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/depth2img.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/depth2img.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/depth2img.ipynb"}]}}),I=new it({props:{code:`import torch | |
| import requests | |
| from PIL import Image | |
| from diffusers import StableDiffusionDepth2ImgPipeline | |
| pipe = StableDiffusionDepth2ImgPipeline.from_pretrained( | |
| "stabilityai/stable-diffusion-2-depth", | |
| torch_dtype=torch.float16, | |
| ).to("cuda")`,highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">import</span> requests | |
| <span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionDepth2ImgPipeline | |
| pipe = StableDiffusionDepth2ImgPipeline.from_pretrained( | |
| <span class="hljs-string">"stabilityai/stable-diffusion-2-depth"</span>, | |
| torch_dtype=torch.float16, | |
| ).to(<span class="hljs-string">"cuda"</span>)`}}),k=new it({props:{code:`url = "http://images.cocodataset.org/val2017/000000039769.jpg" | |
| init_image = Image.open(requests.get(url, stream=True).raw) | |
| prompt = "two tigers" | |
| n_prompt = "bad, deformed, ugly, bad anatomy" | |
| image = pipe(prompt=prompt, image=init_image, negative_prompt=n_prompt, strength=0.7).images[0] | |
| image`,highlighted:`url = <span class="hljs-string">"http://images.cocodataset.org/val2017/000000039769.jpg"</span> | |
| init_image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw) | |
| prompt = <span class="hljs-string">"two tigers"</span> | |
| n_prompt = <span class="hljs-string">"bad, deformed, ugly, bad anatomy"</span> | |
| image = pipe(prompt=prompt, image=init_image, negative_prompt=n_prompt, strength=<span class="hljs-number">0.7</span>).images[<span class="hljs-number">0</span>] | |
| image`}}),{c(){c=o("meta"),z=d(),b=o("h1"),_=o("a"),M=o("span"),pe($.$$.fragment),ue=d(),N=o("span"),ge=n("Text-guided depth-to-image generation"),J=d(),pe(D.$$.fragment),U=d(),f=o("p"),ce=n("The "),T=o("a"),be=n("StableDiffusionDepth2ImgPipeline"),_e=n(" lets you pass a text prompt and an initial image to condition the generation of new images. In addition, you can also pass a "),C=o("code"),ve=n("depth_map"),we=n(" to preserve the image structure. If no "),O=o("code"),ye=n("depth_map"),$e=n(" is provided, the pipeline automatically predicts the depth via an integrated "),E=o("a"),De=n("depth-estimation model"),Ee=n("."),K=d(),v=o("p"),Ie=n("Start by creating an instance of the "),q=o("a"),ke=n("StableDiffusionDepth2ImgPipeline"),Pe=n(":"),Q=d(),pe(I.$$.fragment),V=d(),w=o("p"),Se=n("Now pass your prompt to the pipeline. You can also pass a "),L=o("code"),Te=n("negative_prompt"),qe=n(" to prevent certain words from guiding how an image is generated:"),W=d(),pe(k.$$.fragment),X=d(),y=o("table"),B=o("thead"),P=o("tr"),H=o("th"),je=n("Input"),xe=d(),R=o("th"),Ae=n("Output"),Me=d(),F=o("tbody"),S=o("tr"),G=o("td"),j=o("img"),Ne=d(),Y=o("td"),x=o("img"),Z=d(),A=o("p"),Ce=n("Play around with the Spaces below and see if you notice a difference between generated images with and without a depth map!"),ee=d(),u=o("iframe"),this.h()},l(e){const r=pt('[data-svelte="svelte-1phssyn"]',document.head);c=i(r,"META",{name:!0,content:!0}),r.forEach(t),z=h(e),b=i(e,"H1",{class:!0});var ae=s(b);_=i(ae,"A",{id:!0,class:!0,href:!0});var Fe=s(_);M=i(Fe,"SPAN",{});var Ge=s(M);le($.$$.fragment,Ge),Ge.forEach(t),Fe.forEach(t),ue=h(ae),N=i(ae,"SPAN",{});var Ye=s(N);ge=p(Ye,"Text-guided depth-to-image generation"),Ye.forEach(t),ae.forEach(t),J=h(e),le(D.$$.fragment,e),U=h(e),f=i(e,"P",{});var g=s(f);ce=p(g,"The "),T=i(g,"A",{href:!0});var ze=s(T);be=p(ze,"StableDiffusionDepth2ImgPipeline"),ze.forEach(t),_e=p(g," lets you pass a text prompt and an initial image to condition the generation of new images. In addition, you can also pass a "),C=i(g,"CODE",{});var Je=s(C);ve=p(Je,"depth_map"),Je.forEach(t),we=p(g," to preserve the image structure. If no "),O=i(g,"CODE",{});var Ue=s(O);ye=p(Ue,"depth_map"),Ue.forEach(t),$e=p(g," is provided, the pipeline automatically predicts the depth via an integrated "),E=i(g,"A",{href:!0,rel:!0});var Ke=s(E);De=p(Ke,"depth-estimation model"),Ke.forEach(t),Ee=p(g,"."),g.forEach(t),K=h(e),v=i(e,"P",{});var oe=s(v);Ie=p(oe,"Start by creating an instance of the "),q=i(oe,"A",{href:!0});var Qe=s(q);ke=p(Qe,"StableDiffusionDepth2ImgPipeline"),Qe.forEach(t),Pe=p(oe,":"),oe.forEach(t),Q=h(e),le(I.$$.fragment,e),V=h(e),w=i(e,"P",{});var ie=s(w);Se=p(ie,"Now pass your prompt to the pipeline. You can also pass a "),L=i(ie,"CODE",{});var Ve=s(L);Te=p(Ve,"negative_prompt"),Ve.forEach(t),qe=p(ie," to prevent certain words from guiding how an image is generated:"),ie.forEach(t),W=h(e),le(k.$$.fragment,e),X=h(e),y=i(e,"TABLE",{});var se=s(y);B=i(se,"THEAD",{});var We=s(B);P=i(We,"TR",{});var re=s(P);H=i(re,"TH",{});var Xe=s(H);je=p(Xe,"Input"),Xe.forEach(t),xe=h(re),R=i(re,"TH",{});var Ze=s(R);Ae=p(Ze,"Output"),Ze.forEach(t),re.forEach(t),We.forEach(t),Me=h(se),F=i(se,"TBODY",{});var et=s(F);S=i(et,"TR",{});var ne=s(S);G=i(ne,"TD",{});var tt=s(G);j=i(tt,"IMG",{src:!0,width:!0}),tt.forEach(t),Ne=h(ne),Y=i(ne,"TD",{});var at=s(Y);x=i(at,"IMG",{src:!0,width:!0}),at.forEach(t),ne.forEach(t),et.forEach(t),se.forEach(t),Z=h(e),A=i(e,"P",{});var ot=s(A);Ce=p(ot,"Play around with the Spaces below and see if you notice a difference between generated images with and without a depth map!"),ot.forEach(t),ee=h(e),u=i(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),s(u).forEach(t),this.h()},h(){l(c,"name","hf:doc:metadata"),l(c,"content",JSON.stringify(ut)),l(_,"id","textguided-depthtoimage-generation"),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"),l(_,"href","#textguided-depthtoimage-generation"),l(b,"class","relative group"),l(T,"href","/docs/diffusers/v0.16.0/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline"),l(E,"href","https://github.com/isl-org/MiDaS"),l(E,"rel","nofollow"),l(q,"href","/docs/diffusers/v0.16.0/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline"),Oe(j.src,Be="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/coco-cats.png")||l(j,"src",Be),l(j,"width","500"),Oe(x.src,He="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/depth2img-tigers.png")||l(x,"src",He),l(x,"width","500"),Oe(u.src,Re="https://radames-stable-diffusion-depth2img.hf.space")||l(u,"src",Re),l(u,"frameborder","0"),l(u,"width","850"),l(u,"height","500")},m(e,r){a(document.head,c),m(e,z,r),m(e,b,r),a(b,_),a(_,M),me($,M,null),a(b,ue),a(b,N),a(N,ge),m(e,J,r),me(D,e,r),m(e,U,r),m(e,f,r),a(f,ce),a(f,T),a(T,be),a(f,_e),a(f,C),a(C,ve),a(f,we),a(f,O),a(O,ye),a(f,$e),a(f,E),a(E,De),a(f,Ee),m(e,K,r),m(e,v,r),a(v,Ie),a(v,q),a(q,ke),a(v,Pe),m(e,Q,r),me(I,e,r),m(e,V,r),m(e,w,r),a(w,Se),a(w,L),a(L,Te),a(w,qe),m(e,W,r),me(k,e,r),m(e,X,r),m(e,y,r),a(y,B),a(B,P),a(P,H),a(H,je),a(P,xe),a(P,R),a(R,Ae),a(y,Me),a(y,F),a(F,S),a(S,G),a(G,j),a(S,Ne),a(S,Y),a(Y,x),m(e,Z,r),m(e,A,r),a(A,Ce),m(e,ee,r),m(e,u,r),te=!0},p:lt,i(e){te||(fe($.$$.fragment,e),fe(D.$$.fragment,e),fe(I.$$.fragment,e),fe(k.$$.fragment,e),te=!0)},o(e){de($.$$.fragment,e),de(D.$$.fragment,e),de(I.$$.fragment,e),de(k.$$.fragment,e),te=!1},d(e){t(c),e&&t(z),e&&t(b),he($),e&&t(J),he(D,e),e&&t(U),e&&t(f),e&&t(K),e&&t(v),e&&t(Q),he(I,e),e&&t(V),e&&t(w),e&&t(W),he(k,e),e&&t(X),e&&t(y),e&&t(Z),e&&t(A),e&&t(ee),e&&t(u)}}}const ut={local:"textguided-depthtoimage-generation",title:"Text-guided depth-to-image generation"};function gt(Le){return mt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class wt extends st{constructor(c){super();rt(this,c,gt,ht,nt,{})}}export{wt as default,ut as metadata}; | |
Xet Storage Details
- Size:
- 9.38 kB
- Xet hash:
- 472e2b308e061b9c623afd0af4e32ee63010165244fc87ccb5bc018a7455219a
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.