source
stringclasses
273 values
url
stringlengths
47
172
file_type
stringclasses
1 value
chunk
stringlengths
1
512
chunk_id
stringlengths
5
9
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#prompt-weighting
.md
[`AutoPipelineForImage2Image`] has a `prompt_embeds` (and `negative_prompt_embeds` if you're using a negative prompt) parameter where you can pass the embeddings which replaces the `prompt` parameter. ```py from diffusers import AutoPipelineForImage2Image import torch
83_15_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#prompt-weighting
.md
pipeline = AutoPipelineForImage2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", torch_dtype=torch.float16, variant="fp16", use_safetensors=True ) pipeline.enable_model_cpu_offload() # remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed pipeline.enable_xfo...
83_15_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#prompt-weighting
.md
image = pipeline(prompt_embeds=prompt_embeds, # generated from Compel negative_prompt_embeds=negative_prompt_embeds, # generated from Compel image=init_image, ).images[0] ```
83_15_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#controlnet
.md
ControlNets provide a more flexible and accurate way to control image generation because you can use an additional conditioning image. The conditioning image can be a canny image, depth map, image segmentation, and even scribbles! Whatever type of conditioning image you choose, the ControlNet generates an image that pr...
83_16_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#controlnet
.md
For example, let's condition an image with a depth map to keep the spatial information in the image. ```py from diffusers.utils import load_image, make_image_grid
83_16_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#controlnet
.md
# prepare image url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-init.png" init_image = load_image(url) init_image = init_image.resize((958, 960)) # resize to depth image dimensions depth_image = load_image("https://huggingface.co/lllyasviel/control_v11f1p_sd15_dept...
83_16_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#controlnet
.md
make_image_grid([init_image, depth_image], rows=1, cols=2) ``` Load a ControlNet model conditioned on depth maps and the [`AutoPipelineForImage2Image`]: ```py from diffusers import ControlNetModel, AutoPipelineForImage2Image import torch
83_16_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#controlnet
.md
controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11f1p_sd15_depth", torch_dtype=torch.float16, variant="fp16", use_safetensors=True) pipeline = AutoPipelineForImage2Image.from_pretrained( "stable-diffusion-v1-5/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float16, variant="fp16", us...
83_16_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#controlnet
.md
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed pipeline.enable_xformers_memory_efficient_attention() ``` Now generate a new image conditioned on the depth map, initial image, and prompt: ```py prompt = "Astronaut in a jungle, cold color palette, muted colors, detail...
83_16_5
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#controlnet
.md
make_image_grid([init_image, depth_image, image_control_net], rows=1, cols=3) ``` <div class="flex flex-row gap-4"> <div class="flex-1"> <img class="rounded-xl" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-init.png"/> <figcaption class="mt-2 text-center text-sm ...
83_16_6
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#controlnet
.md
<figcaption class="mt-2 text-center text-sm text-gray-500">initial image</figcaption> </div> <div class="flex-1"> <img class="rounded-xl" src="https://huggingface.co/lllyasviel/control_v11f1p_sd15_depth/resolve/main/images/control.png"/> <figcaption class="mt-2 text-center text-sm text-gray-500">depth image</figcaption...
83_16_7
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#controlnet
.md
<figcaption class="mt-2 text-center text-sm text-gray-500">ControlNet image</figcaption> </div> </div> Let's apply a new [style](https://huggingface.co/nitrosocke/elden-ring-diffusion) to the image generated from the ControlNet by chaining it with an image-to-image pipeline: ```py pipeline = AutoPipelineForImage2Im...
83_16_8
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#controlnet
.md
"nitrosocke/elden-ring-diffusion", torch_dtype=torch.float16, ) pipeline.enable_model_cpu_offload() # remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed pipeline.enable_xformers_memory_efficient_attention()
83_16_9
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#controlnet
.md
prompt = "elden ring style astronaut in a jungle" # include the token "elden ring style" in the prompt negative_prompt = "ugly, deformed, disfigured, poor details, bad anatomy"
83_16_10
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#controlnet
.md
image_elden_ring = pipeline(prompt, negative_prompt=negative_prompt, image=image_control_net, strength=0.45, guidance_scale=10.5).images[0] make_image_grid([init_image, depth_image, image_control_net, image_elden_ring], rows=2, cols=2) ``` <div class="flex justify-center"> <img src="https://huggingface.co/datasets/hu...
83_16_11
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#optimize
.md
Running diffusion models is computationally expensive and intensive, but with a few optimization tricks, it is entirely possible to run them on consumer and free-tier GPUs. For example, you can use a more memory-efficient form of attention such as PyTorch 2.0's [scaled-dot product attention](../optimization/torch2.0#sc...
83_17_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#optimize
.md
(you can use one or the other, but there's no need to use both). You can also offload the model to the GPU while the other pipeline components wait on the CPU.
83_17_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/img2img.md
https://huggingface.co/docs/diffusers/en/using-diffusers/img2img/#optimize
.md
```diff + pipeline.enable_model_cpu_offload() + pipeline.enable_xformers_memory_efficient_attention() ``` With [`torch.compile`](../optimization/torch2.0#torchcompile), you can boost your inference speed even more by wrapping your UNet with it: ```py pipeline.unet = torch.compile(pipeline.unet, mode="reduce-overhea...
83_17_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/unconditional_image_generation.md
https://huggingface.co/docs/diffusers/en/using-diffusers/unconditional_image_generation/
.md
<!--Copyright 2024 The HuggingFace Team. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agr...
84_0_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/unconditional_image_generation.md
https://huggingface.co/docs/diffusers/en/using-diffusers/unconditional_image_generation/
.md
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
84_0_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/unconditional_image_generation.md
https://huggingface.co/docs/diffusers/en/using-diffusers/unconditional_image_generation/#unconditional-image-generation
.md
[[open-in-colab]] Unconditional image generation generates images that look like a random sample from the training data the model was trained on because the denoising process is not guided by any additional context like text or image.
84_1_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/unconditional_image_generation.md
https://huggingface.co/docs/diffusers/en/using-diffusers/unconditional_image_generation/#unconditional-image-generation
.md
To get started, use the [`DiffusionPipeline`] to load the [anton-l/ddpm-butterflies-128](https://huggingface.co/anton-l/ddpm-butterflies-128) checkpoint to generate images of butterflies. The [`DiffusionPipeline`] downloads and caches all the model components required to generate an image. ```py from diffusers import...
84_1_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/unconditional_image_generation.md
https://huggingface.co/docs/diffusers/en/using-diffusers/unconditional_image_generation/#unconditional-image-generation
.md
generator = DiffusionPipeline.from_pretrained("anton-l/ddpm-butterflies-128").to("cuda") image = generator().images[0] image ``` <Tip> Want to generate images of something else? Take a look at the training [guide](../training/unconditional_training) to learn how to train a model to generate your own images. </Tip...
84_1_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/unconditional_image_generation.md
https://huggingface.co/docs/diffusers/en/using-diffusers/unconditional_image_generation/#unconditional-image-generation
.md
```py image.save("generated_image.png") ``` You can also try experimenting with the `num_inference_steps` parameter, which controls the number of denoising steps. More denoising steps typically produce higher quality images, but it'll take longer to generate. Feel free to play around with this parameter to see how it...
84_1_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/unconditional_image_generation.md
https://huggingface.co/docs/diffusers/en/using-diffusers/unconditional_image_generation/#unconditional-image-generation
.md
image ``` Try out the Space below to generate an image of a butterfly! <iframe src="https://stevhliu-unconditional-image-generation.hf.space" frameborder="0" width="850" height="500" ></iframe>
84_1_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/create_a_server.md
https://huggingface.co/docs/diffusers/en/using-diffusers/create_a_server/#create-a-server
.md
Diffusers' pipelines can be used as an inference engine for a server. It supports concurrent and multithreaded requests to generate images that may be requested by multiple users at the same time. This guide will show you how to use the [`StableDiffusion3Pipeline`] in a server, but feel free to use any pipeline you w...
85_0_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/create_a_server.md
https://huggingface.co/docs/diffusers/en/using-diffusers/create_a_server/#create-a-server
.md
```py pip install . pip install -f requirements.txt ``` Launch the server with the following command. ```py python server.py ``` The server is accessed at http://localhost:8000. You can curl this model with the following command. ``` curl -X POST -H "Content-Type: application/json" --data '{"model": "something", ...
85_0_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/create_a_server.md
https://huggingface.co/docs/diffusers/en/using-diffusers/create_a_server/#create-a-server
.md
``` If you need to upgrade some dependencies, you can use either [pip-tools](https://github.com/jazzband/pip-tools) or [uv](https://github.com/astral-sh/uv). For example, upgrade the dependencies with `uv` using the following command. ``` uv pip compile requirements.in -o requirements.txt ``` The server is built ...
85_0_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/create_a_server.md
https://huggingface.co/docs/diffusers/en/using-diffusers/create_a_server/#create-a-server
.md
```py @app.post("/v1/images/generations") async def generate_image(image_input: TextToImageInput): try: loop = asyncio.get_event_loop() scheduler = shared_pipeline.pipeline.scheduler.from_config(shared_pipeline.pipeline.scheduler.config) pipeline = StableDiffusion3Pipeline.from_pipe(shared_pipeline.pipeline, scheduler=...
85_0_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/create_a_server.md
https://huggingface.co/docs/diffusers/en/using-diffusers/create_a_server/#create-a-server
.md
generator = torch.Generator(device="cuda") generator.manual_seed(random.randint(0, 10000000)) output = await loop.run_in_executor(None, lambda: pipeline(image_input.prompt, generator = generator)) logger.info(f"output: {output}") image_url = save_image(output.images[0]) return {"data": [{"url": image_url}]} except Exce...
85_0_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/create_a_server.md
https://huggingface.co/docs/diffusers/en/using-diffusers/create_a_server/#create-a-server
.md
raise e elif hasattr(e, 'message'): raise HTTPException(status_code=500, detail=e.message + traceback.format_exc()) raise HTTPException(status_code=500, detail=str(e) + traceback.format_exc()) ```
85_0_5
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/create_a_server.md
https://huggingface.co/docs/diffusers/en/using-diffusers/create_a_server/#create-a-server
.md
The `generate_image` function is defined as asynchronous with the [async](https://fastapi.tiangolo.com/async/) keyword so that FastAPI knows that whatever is happening in this function won't necessarily return a result right away. Once it hits some point in the function that it needs to await some other [Task](https://...
85_0_6
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/create_a_server.md
https://huggingface.co/docs/diffusers/en/using-diffusers/create_a_server/#create-a-server
.md
the main thread goes back to answering other HTTP requests. This is shown in the code below with the [await](https://fastapi.tiangolo.com/async/#async-and-await) keyword.
85_0_7
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/create_a_server.md
https://huggingface.co/docs/diffusers/en/using-diffusers/create_a_server/#create-a-server
.md
```py output = await loop.run_in_executor(None, lambda: pipeline(image_input.prompt, generator = generator)) ``` At this point, the execution of the pipeline function is placed onto a [new thread](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.run_in_executor), and the main thread performs other ...
85_0_8
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/create_a_server.md
https://huggingface.co/docs/diffusers/en/using-diffusers/create_a_server/#create-a-server
.md
Another important aspect of this implementation is creating a `pipeline` from `shared_pipeline`. The goal behind this is to avoid loading the underlying model more than once onto the GPU while still allowing for each new request that is running on a separate thread to have its own generator and scheduler. The scheduler...
85_0_9
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/using-diffusers/create_a_server.md
https://huggingface.co/docs/diffusers/en/using-diffusers/create_a_server/#create-a-server
.md
like: `IndexError: index 21 is out of bounds for dimension 0 with size 21` if you try to use the same scheduler across multiple threads.
85_0_10
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/
.md
<!--Copyright 2024 The HuggingFace Team. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agr...
86_0_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/
.md
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
86_0_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpainting
.md
Outpainting extends an image beyond its original boundaries, allowing you to add, replace, or modify visual elements in an image while preserving the original image. Like [inpainting](../using-diffusers/inpaint), you want to fill the white area (in this case, the area outside of the original image) with new visual elem...
86_1_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpainting
.md
keeping the original image (represented by a mask of black pixels). There are a couple of ways to outpaint, such as with a [ControlNet](https://hf.co/blog/OzzyGT/outpainting-controlnet) or with [Differential Diffusion](https://hf.co/blog/OzzyGT/outpainting-differential-diffusion).
86_1_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpainting
.md
This guide will show you how to outpaint with an inpainting model, ControlNet, and a ZoeDepth estimator. Before you begin, make sure you have the [controlnet_aux](https://github.com/huggingface/controlnet_aux) library installed so you can use the ZoeDepth estimator. ```py !pip install -q controlnet_aux ```
86_1_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#image-preparation
.md
Start by picking an image to outpaint with and remove the background with a Space like [BRIA-RMBG-1.4](https://hf.co/spaces/briaai/BRIA-RMBG-1.4). <iframe src="https://briaai-bria-rmbg-1-4.hf.space" frameborder="0" width="850" height="450" ></iframe> For example, remove the background from this image of a pair of s...
86_2_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#image-preparation
.md
<img class="rounded-xl" src="https://huggingface.co/datasets/stevhliu/testing-images/resolve/main/original-jordan.png"/> <figcaption class="mt-2 text-center text-sm text-gray-500">original image</figcaption> </div> <div class="flex-1"> <img class="rounded-xl" src="https://huggingface.co/datasets/stevhliu/testing-images...
86_2_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#image-preparation
.md
<figcaption class="mt-2 text-center text-sm text-gray-500">background removed</figcaption> </div> </div> [Stable Diffusion XL (SDXL)](../using-diffusers/sdxl) models work best with 1024x1024 images, but you can resize the image to any size as long as your hardware has enough memory to support it. The transparent back...
86_2_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#image-preparation
.md
import requests import torch from controlnet_aux import ZoeDetector from PIL import Image, ImageOps from diffusers import ( AutoencoderKL, ControlNetModel, StableDiffusionXLControlNetPipeline, StableDiffusionXLInpaintPipeline, ) def scale_and_paste(original_image): aspect_ratio = original_image.width / original_image...
86_2_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#image-preparation
.md
resized_original = original_image.resize((new_width, new_height), Image.LANCZOS) white_background = Image.new("RGBA", (1024, 1024), "white") x = (1024 - new_width) // 2 y = (1024 - new_height) // 2 white_background.paste(resized_original, (x, y), resized_original) return resized_original, white_background
86_2_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#image-preparation
.md
original_image = Image.open( requests.get( "https://huggingface.co/datasets/stevhliu/testing-images/resolve/main/no-background-jordan.png", stream=True, ).raw ).convert("RGBA") resized_img, white_bg_image = scale_and_paste(original_image) ``` To avoid adding unwanted extra details, use the ZoeDepth estimator to provi...
86_2_5
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#image-preparation
.md
```py zoe = ZoeDetector.from_pretrained("lllyasviel/Annotators") image_zoe = zoe(white_bg_image, detect_resolution=512, image_resolution=1024) image_zoe ``` <div class="flex justify-center"> <img src="https://huggingface.co/datasets/stevhliu/testing-images/resolve/main/zoedepth-jordan.png"/> </div>
86_2_6
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpaint
.md
Once your image is ready, you can generate content in the white area around the shoes with [controlnet-inpaint-dreamer-sdxl](https://hf.co/destitech/controlnet-inpaint-dreamer-sdxl), a SDXL ControlNet trained for inpainting. Load the inpainting ControlNet, ZoeDepth model, VAE and pass them to the [`StableDiffusionXLC...
86_3_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpaint
.md
```py controlnets = [ ControlNetModel.from_pretrained( "destitech/controlnet-inpaint-dreamer-sdxl", torch_dtype=torch.float16, variant="fp16" ), ControlNetModel.from_pretrained( "diffusers/controlnet-zoe-depth-sdxl-1.0", torch_dtype=torch.float16 ), ] vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix",...
86_3_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpaint
.md
pipeline = StableDiffusionXLControlNetPipeline.from_pretrained( "SG161222/RealVisXL_V4.0", torch_dtype=torch.float16, variant="fp16", controlnet=controlnets, vae=vae ).to("cuda")
86_3_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpaint
.md
def generate_image(prompt, negative_prompt, inpaint_image, zoe_image, seed: int = None): if seed is None: seed = random.randint(0, 2**32 - 1) generator = torch.Generator(device="cpu").manual_seed(seed) image = pipeline( prompt, negative_prompt=negative_prompt, image=[inpaint_image, zoe_image], guidance_scale=6.5, num...
86_3_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpaint
.md
return image prompt = "nike air jordans on a basketball court" negative_prompt = ""
86_3_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpaint
.md
temp_image = generate_image(prompt, negative_prompt, white_bg_image, image_zoe, 908097) ``` Paste the original image over the initial outpainted image. You'll improve the outpainted background in a later step. ```py x = (1024 - resized_img.width) // 2 y = (1024 - resized_img.height) // 2 temp_image.paste(resized_im...
86_3_5
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpaint
.md
<img src="https://huggingface.co/datasets/stevhliu/testing-images/resolve/main/initial-outpaint.png"/> </div> > [!TIP] > Now is a good time to free up some memory if you're running low! > > ```py > pipeline=None > torch.cuda.empty_cache() > ``` Now that you have an initial outpainted image, load the [`StableDiffusi...
86_3_6
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpaint
.md
```py pipeline = StableDiffusionXLInpaintPipeline.from_pretrained( "OzzyGT/RealVisXL_V4.0_inpainting", torch_dtype=torch.float16, variant="fp16", vae=vae, ).to("cuda") ``` Prepare a mask for the final outpainted image. To create a more natural transition between the original image and the outpainted background, blur ...
86_3_7
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpaint
.md
```py mask = Image.new("L", temp_image.size) mask.paste(resized_img.split()[3], (x, y)) mask = ImageOps.invert(mask) final_mask = mask.point(lambda p: p > 128 and 255) mask_blurred = pipeline.mask_processor.blur(final_mask, blur_factor=20) mask_blurred ``` <div class="flex justify-center"> <img src="https://huggingfa...
86_3_8
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpaint
.md
<img src="https://huggingface.co/datasets/stevhliu/testing-images/resolve/main/blurred-mask.png"/> </div> Create a better prompt and pass it to the `generate_outpaint` function to generate the final outpainted image. Again, paste the original image over the final outpainted background. ```py def generate_outpaint(p...
86_3_9
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpaint
.md
generator = torch.Generator(device="cpu").manual_seed(seed) image = pipeline( prompt, negative_prompt=negative_prompt, image=image, mask_image=mask, guidance_scale=10.0, strength=0.8, num_inference_steps=30, generator=generator, ).images[0] return image prompt = "high quality photo of nike air jordans on a basketbal...
86_3_10
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/advanced_inference/outpaint.md
https://huggingface.co/docs/diffusers/en/advanced_inference/outpaint/#outpaint
.md
return image prompt = "high quality photo of nike air jordans on a basketball court, highly detailed" negative_prompt = "" final_image = generate_outpaint(prompt, negative_prompt, temp_image, mask_blurred, 7688778) x = (1024 - resized_img.width) // 2 y = (1024 - resized_img.height) // 2 final_image.paste(resized_img,...
86_3_11
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/outputs.md
https://huggingface.co/docs/diffusers/en/api/outputs/
.md
<!--Copyright 2024 The HuggingFace Team. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agr...
87_0_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/outputs.md
https://huggingface.co/docs/diffusers/en/api/outputs/
.md
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
87_0_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/outputs.md
https://huggingface.co/docs/diffusers/en/api/outputs/#outputs
.md
All model outputs are subclasses of [`~utils.BaseOutput`], data structures containing all the information returned by the model. The outputs can also be used as tuples or dictionaries. For example: ```python from diffusers import DDIMPipeline
87_1_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/outputs.md
https://huggingface.co/docs/diffusers/en/api/outputs/#outputs
.md
pipeline = DDIMPipeline.from_pretrained("google/ddpm-cifar10-32") outputs = pipeline() ``` The `outputs` object is a [`~pipelines.ImagePipelineOutput`] which means it has an image attribute. You can access each attribute as you normally would or with a keyword lookup, and if that attribute is not returned by the mo...
87_1_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/outputs.md
https://huggingface.co/docs/diffusers/en/api/outputs/#outputs
.md
``` When considering the `outputs` object as a tuple, it only considers the attributes that don't have `None` values. For instance, retrieving an image by indexing into it returns the tuple `(outputs.images)`: ```python outputs[:1] ``` <Tip> To check a specific pipeline or model output, refer to its correspondi...
87_1_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/outputs.md
https://huggingface.co/docs/diffusers/en/api/outputs/#baseoutput
.md
BaseOutput Base class for all model outputs as dataclass. Has a `__getitem__` that allows indexing by integer or slice (like a tuple) or strings (like a dictionary) that will ignore the `None` attributes. Otherwise behaves like a regular Python dictionary. <Tip warning={true}> You can't unpack a [`BaseOutput`] di...
87_2_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/outputs.md
https://huggingface.co/docs/diffusers/en/api/outputs/#imagepipelineoutput
.md
ImagePipelineOutput Output class for image pipelines. Args: images (`List[PIL.Image.Image]` or `np.ndarray`) List of denoised PIL images of length `batch_size` or NumPy array of shape `(batch_size, height, width, num_channels)`.
87_3_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/outputs.md
https://huggingface.co/docs/diffusers/en/api/outputs/#flaximagepipelineoutput
.md
[[autodoc]] FlaxImagePipelineOutput: No module named 'flax'
87_4_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/outputs.md
https://huggingface.co/docs/diffusers/en/api/outputs/#audiopipelineoutput
.md
AudioPipelineOutput Output class for audio pipelines. Args: audios (`np.ndarray`) List of denoised audio samples of a NumPy array of shape `(batch_size, num_channels, sample_rate)`.
87_5_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/outputs.md
https://huggingface.co/docs/diffusers/en/api/outputs/#imagetextpipelineoutput
.md
ImageTextPipelineOutput Output class for joint image-text pipelines. Args: images (`List[PIL.Image.Image]` or `np.ndarray`) List of denoised PIL images of length `batch_size` or NumPy array of shape `(batch_size, height, width, num_channels)`. text (`List[str]` or `List[List[str]]`) List of generated text strings o...
87_6_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/
.md
<!--Copyright 2024 The HuggingFace Team. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agr...
88_0_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/
.md
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
88_0_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#attention-processor
.md
An attention processor is a class for applying different types of attention mechanisms.
88_1_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#attnprocessor
.md
AttnProcessor Default processor for performing attention-related computations. AttnProcessor Default processor for performing attention-related computations. 2_0 AttnAddedKVProcessor Processor for performing attention-related computations with extra learnable key and value matrices for the text encoder. Att...
88_2_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#attnprocessor
.md
encoder. 2_0 AttnProcessor Default processor for performing attention-related computations. NPU FusedAttnProcessor2_0 Processor for implementing scaled dot-product attention (enabled by default if you're using PyTorch 2.0). It uses fused projection layers. For self-attention modules, all projection matrices (i....
88_2_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#attnprocessor
.md
For cross-attention modules, key and value projection matrices are fused. <Tip warning={true}> This API is currently 🧪 experimental in nature and can change in future. </Tip>
88_2_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#allegro
.md
AllegroAttnProcessor2_0 Processor for implementing scaled dot-product attention (enabled by default if you're using PyTorch 2.0). This is used in the Allegro model. It applies a normalization layer and rotary embedding on the query and key vector.
88_3_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#auraflow
.md
AuraFlowAttnProcessor2_0 Attention processor used typically in processing Aura Flow. FusedAuraFlowAttnProcessor2_0 Attention processor used typically in processing Aura Flow with fused projections.
88_4_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#cogvideox
.md
CogVideoXAttnProcessor2_0 Processor for implementing scaled dot-product attention for the CogVideoX model. It applies a rotary embedding on query and key vectors, but does not include spatial normalization. FusedCogVideoXAttnProcessor2_0 Processor for implementing scaled dot-product attention for the CogVideoX mo...
88_5_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#crossframeattnprocessor
.md
CrossFrameAttnProcessor Cross frame attention processor. Each frame attends the first frame. Args: batch_size: The number that represents actual batch size, other than the frames. For example, calling unet with a single prompt and num_images_per_prompt=1, batch_size should be equal to 2, due to classifier-free guid...
88_6_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#custom-diffusion
.md
CustomDiffusionAttnProcessor Processor for implementing attention for the Custom Diffusion method. Args: train_kv (`bool`, defaults to `True`): Whether to newly train the key and value matrices corresponding to the text features. train_q_out (`bool`, defaults to `True`): Whether to newly train query matrices corres...
88_7_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#custom-diffusion
.md
The hidden size of the attention layer. cross_attention_dim (`int`, *optional*, defaults to `None`): The number of channels in the `encoder_hidden_states`. out_bias (`bool`, defaults to `True`): Whether to include the bias parameter in `train_q_out`. dropout (`float`, *optional*, defaults to 0.0): The dropout probabili...
88_7_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#custom-diffusion
.md
Processor for implementing attention for the Custom Diffusion method. Args: train_kv (`bool`, defaults to `True`): Whether to newly train the key and value matrices corresponding to the text features. train_q_out (`bool`, defaults to `True`): Whether to newly train query matrices corresponding to the latent image fea...
88_7_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#custom-diffusion
.md
The hidden size of the attention layer. cross_attention_dim (`int`, *optional*, defaults to `None`): The number of channels in the `encoder_hidden_states`. out_bias (`bool`, defaults to `True`): Whether to include the bias parameter in `train_q_out`. dropout (`float`, *optional*, defaults to 0.0): The dropout probabili...
88_7_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#custom-diffusion
.md
Processor for implementing memory efficient attention using xFormers for the Custom Diffusion method. Args: train_kv (`bool`, defaults to `True`): Whether to newly train the key and value matrices corresponding to the text features. train_q_out (`bool`, defaults to `True`): Whether to newly train query matrices corre...
88_7_4
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#custom-diffusion
.md
hidden_size (`int`, *optional*, defaults to `None`): The hidden size of the attention layer. cross_attention_dim (`int`, *optional*, defaults to `None`): The number of channels in the `encoder_hidden_states`. out_bias (`bool`, defaults to `True`): Whether to include the bias parameter in `train_q_out`. dropout (`float`...
88_7_5
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#custom-diffusion
.md
The dropout probability to use. attention_op (`Callable`, *optional*, defaults to `None`): The base [operator](https://facebookresearch.github.io/xformers/components/ops.html#xformers.ops.AttentionOpBase) to use as the attention operator. It is recommended to set to `None`, and allow xFormers to choose the best operato...
88_7_6
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#flux
.md
FluxAttnProcessor2_0 Attention processor used typically in processing the SD3-like self-attention projections. FusedFluxAttnProcessor2_0 Attention processor used typically in processing the SD3-like self-attention projections. FluxSingleAttnProcessor2_0 Processor for implementing scaled dot-product attention (ena...
88_8_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#hunyuan
.md
HunyuanAttnProcessor2_0 Processor for implementing scaled dot-product attention (enabled by default if you're using PyTorch 2.0). This is used in the HunyuanDiT model. It applies a s normalization layer and rotary embedding on query and key vector. FusedHunyuanAttnProcessor2_0 Processor for implementing scaled do...
88_9_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#hunyuan
.md
Processor for implementing scaled dot-product attention (enabled by default if you're using PyTorch 2.0) with fused projection layers. This is used in the HunyuanDiT model. It applies a s normalization layer and rotary embedding on query and key vector. PAGHunyuanAttnProcessor2_0 Processor for implementing scaled d...
88_9_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#hunyuan
.md
Processor for implementing scaled dot-product attention (enabled by default if you're using PyTorch 2.0). This is used in the HunyuanDiT model. It applies a normalization layer and rotary embedding on query and key vector. This variant of the processor employs [Pertubed Attention Guidance](https://arxiv.org/abs/2403.17...
88_9_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#hunyuan
.md
Processor for implementing scaled dot-product attention (enabled by default if you're using PyTorch 2.0). This is used in the HunyuanDiT model. It applies a normalization layer and rotary embedding on query and key vector. This variant of the processor employs [Pertubed Attention Guidance](https://arxiv.org/abs/2403.17...
88_9_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#identityselfattnprocessor20
.md
PAGIdentitySelfAttnProcessor2_0 Processor for implementing PAG using scaled dot-product attention (enabled by default if you're using PyTorch 2.0). PAG reference: https://arxiv.org/abs/2403.17377 PAGCFGIdentitySelfAttnProcessor2_0 Processor for implementing PAG using scaled dot-product attention (enabled by defau...
88_10_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#ip-adapter
.md
IPAdapterAttnProcessor Attention processor for Multiple IP-Adapters. Args: hidden_size (`int`): The hidden size of the attention layer. cross_attention_dim (`int`): The number of channels in the `encoder_hidden_states`. num_tokens (`int`, `Tuple[int]` or `List[int]`, defaults to `(4,)`): The context length of the i...
88_11_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#ip-adapter
.md
the weight scale of image prompt. IPAdapterAttnProcessor Attention processor for Multiple IP-Adapters. Args: hidden_size (`int`): The hidden size of the attention layer. cross_attention_dim (`int`): The number of channels in the `encoder_hidden_states`. num_tokens (`int`, `Tuple[int]` or `List[int]`, defaults to ...
88_11_1
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#ip-adapter
.md
scale (`float` or List[`float`], defaults to 1.0): the weight scale of image prompt. 2_0 SD3IPAdapterJointAttnProcessor2_0 Attention processor for IP-Adapter used typically in processing the SD3-like self-attention projections, with additional image-based information and timestep embeddings. Args: hidden_size (`i...
88_11_2
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#ip-adapter
.md
The image feature dimension. head_dim (`int`): The number of head channels. timesteps_emb_dim (`int`, defaults to 1280): The number of input channels for timestep embedding. scale (`float`, defaults to 0.5): IP-Adapter scale.
88_11_3
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#jointattnprocessor20
.md
JointAttnProcessor2_0 Attention processor used typically in processing the SD3-like self-attention projections. PAGJointAttnProcessor2_0 Attention processor used typically in processing the SD3-like self-attention projections. PAGCFGJointAttnProcessor2_0 Attention processor used typically in processing the SD3-like...
88_12_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#lora
.md
LoRAAttnProcessor Processor for implementing attention with LoRA. LoRAAttnProcessor Processor for implementing attention with LoRA. 2_0 LoRAAttnAddedKVProcessor Processor for implementing attention with LoRA with extra learnable key and value matrices for the text encoder. LoRAXFormersAttnProcessor Proces...
88_13_0
/Users/nielsrogge/Documents/python_projecten/diffusers/docs/source/en/api/attnprocessor.md
https://huggingface.co/docs/diffusers/en/api/attnprocessor/#lumina-t2x
.md
LuminaAttnProcessor2_0 Processor for implementing scaled dot-product attention (enabled by default if you're using PyTorch 2.0). This is used in the LuminaNextDiT model. It applies a s normalization layer and rotary embedding on query and key vector.
88_14_0