Buckets:

download
raw
5.71 kB
import"../chunks/DsnmJJEf.js";import{i as u,h as f,C as b,H as w,a as r,E as M,s as y}from"../chunks/CmJXCtRL.js";import{p as J,o as T,s as e,f as Z,a as d,b as U,d as g,n as W}from"../chunks/DK803DsY.js";import{D as j}from"../chunks/icy4GrpL.js";const _='{"title":"Text-guided depth-to-image generation","local":"text-guided-depth-to-image-generation","sections":[],"depth":1}';var k=g('<meta name="hf:doc:metadata"/>'),v=g('<p></p> <!> <!> <!> <p>The <a href="/docs/diffusers/pr_14313/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline">StableDiffusionDepth2ImgPipeline</a> lets you pass a text prompt and an initial image to condition the generation of new images. In addition, you can also pass a <code>depth_map</code> to preserve the image structure. If no <code>depth_map</code> is provided, the pipeline automatically predicts the depth via an integrated <a href="https://github.com/isl-org/MiDaS" rel="nofollow">depth-estimation model</a>.</p> <p>Start by creating an instance of the <a href="/docs/diffusers/pr_14313/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline">StableDiffusionDepth2ImgPipeline</a>:</p> <!> <p>Now pass your prompt to the pipeline. You can also pass a <code>negative_prompt</code> to prevent certain words from guiding how an image is generated:</p> <!> <table><thead><tr><th>Input</th><th>Output</th></tr></thead><tbody><tr><td><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/coco-cats.png" width="500"/></td><td><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/depth2img-tigers.png" width="500"/></td></tr></tbody></table> <!> <p></p>',1);function V(m,h){J(h,!1),T(()=>{new URLSearchParams(window.location.search).get("fw")}),u();var a=v();f("1t2itkw",n=>{var p=k();y(p,"content",_),d(n,p)});var t=e(Z(a),2);b(t,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var i=e(t,2);j(i,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;",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"}]});var s=e(i,2);w(s,{title:"Text-guided depth-to-image generation",local:"text-guided-depth-to-image-generation",headingTag:"h1"});var o=e(s,6);r(o,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uRGVwdGgySW1nUGlwZWxpbmUlMEFmcm9tJTIwZGlmZnVzZXJzLnV0aWxzJTIwaW1wb3J0JTIwbG9hZF9pbWFnZSUyQyUyMG1ha2VfaW1hZ2VfZ3JpZCUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uRGVwdGgySW1nUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi0yLWRlcHRoJTIyJTJDJTBBJTIwJTIwJTIwJTIwZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBJTIwJTIwJTIwJTIwdXNlX3NhZmV0ZW5zb3JzJTNEVHJ1ZSUyQyUwQSkudG8oJTIyY3VkYSUyMik=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionDepth2ImgPipeline
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image, make_image_grid
pipeline = StableDiffusionDepth2ImgPipeline.from_pretrained(
<span class="hljs-string">&quot;stabilityai/stable-diffusion-2-depth&quot;</span>,
dtype=torch.float16,
use_safetensors=<span class="hljs-literal">True</span>,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)`,lang:"python",wrap:!1});var l=e(o,4);r(l,{code:"dXJsJTIwJTNEJTIwJTIyaHR0cCUzQSUyRiUyRmltYWdlcy5jb2NvZGF0YXNldC5vcmclMkZ2YWwyMDE3JTJGMDAwMDAwMDM5NzY5LmpwZyUyMiUwQWluaXRfaW1hZ2UlMjAlM0QlMjBsb2FkX2ltYWdlKHVybCklMEFwcm9tcHQlMjAlM0QlMjAlMjJ0d28lMjB0aWdlcnMlMjIlMEFuZWdhdGl2ZV9wcm9tcHQlMjAlM0QlMjAlMjJiYWQlMkMlMjBkZWZvcm1lZCUyQyUyMHVnbHklMkMlMjBiYWQlMjBhbmF0b215JTIyJTBBaW1hZ2UlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQlM0Rwcm9tcHQlMkMlMjBpbWFnZSUzRGluaXRfaW1hZ2UlMkMlMjBuZWdhdGl2ZV9wcm9tcHQlM0RuZWdhdGl2ZV9wcm9tcHQlMkMlMjBzdHJlbmd0aCUzRDAuNykuaW1hZ2VzJTVCMCU1RCUwQW1ha2VfaW1hZ2VfZ3JpZCglNUJpbml0X2ltYWdlJTJDJTIwaW1hZ2UlNUQlMkMlMjByb3dzJTNEMSUyQyUyMGNvbHMlM0QyKQ==",highlighted:`url = <span class="hljs-string">&quot;http://images.cocodataset.org/val2017/000000039769.jpg&quot;</span>
init_image = load_image(url)
prompt = <span class="hljs-string">&quot;two tigers&quot;</span>
negative_prompt = <span class="hljs-string">&quot;bad, deformed, ugly, bad anatomy&quot;</span>
image = pipeline(prompt=prompt, image=init_image, negative_prompt=negative_prompt, strength=<span class="hljs-number">0.7</span>).images[<span class="hljs-number">0</span>]
make_image_grid([init_image, image], rows=<span class="hljs-number">1</span>, cols=<span class="hljs-number">2</span>)`,lang:"python",wrap:!1});var c=e(l,4);M(c,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/using-diffusers/depth2img.md"}),W(2),d(m,a),U()}export{V as component};

Xet Storage Details

Size:
5.71 kB
·
Xet hash:
675e2204e028f3cdf5811d050facd3354c957c8d1ad731dad8b8498d89a779a5

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.