Views
No views yet
1from diffusers import FluxControlPipeline, FluxTransformer2DModel
2from diffusers.utils import load_image
3import torch
4
5path = "sayakpaul/FLUX.1-dev-edit-v0"
6edit_transformer = FluxTransformer2DModel.from_pretrained(path, torch_dtype=torch.bfloat16)
7pipeline = FluxControlPipeline.from_pretrained(
8 "black-forest-labs/FLUX.1-dev", transformer=edit_transformer, torch_dtype=torch.bfloat16
9).to("cuda")
10
11url = "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/flux-edit-artifacts/assets/mushroom.jpg"
12image = load_image(url) # resize as needed.
13print(image.size)
14
15prompt = "turn the color of mushroom to gray"
16image = pipeline(
17 control_image=image,
18 prompt=prompt,
19 guidance_scale=30., # change this as needed.
20 num_inference_steps=50, # change this as needed.
21 max_sequence_length=512,
22 height=image.height,
23 width=image.width,
24 generator=torch.manual_seed(0)
25).images[0]
26image.save("edited_image.png")num_inference_steps to produce a nice image by using turbo LoRA like ByteDance/Hyper-SD.peft before running the code below: pip install -U peft.1from diffusers import FluxControlPipeline, FluxTransformer2DModel
2from diffusers.utils import load_image
3from huggingface_hub import hf_hub_download
4import torch
5
6path = "sayakpaul/FLUX.1-dev-edit-v0"
7edit_transformer = FluxTransformer2DModel.from_pretrained(path, torch_dtype=torch.bfloat16)
8pipeline = FluxControlPipeline.from_pretrained(
9 "black-forest-labs/FLUX.1-dev", transformer=edit_transformer, torch_dtype=torch.bfloat16
10).to("cuda")
11
12# load the turbo LoRA
13pipeline.load_lora_weights(
14 hf_hub_download("ByteDance/Hyper-SD", "Hyper-FLUX.1-dev-8steps-lora.safetensors"), adapter_name="hyper-sd"
15)
16pipeline.set_adapters(["hyper-sd"], adapter_weights=[0.125])
17
18
19url = "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/flux-edit-artifacts/assets/mushroom.jpg"
20image = load_image(url) # resize as needed.
21print(image.size)
22
23prompt = "turn the color of mushroom to gray"
24image = pipeline(
25 control_image=image,
26 prompt=prompt,
27 guidance_scale=30., # change this as needed.
28 num_inference_steps=8, # change this as needed.
29 max_sequence_length=512,
30 height=image.height,
31 width=image.width,
32 generator=torch.manual_seed(0)
33).images[0]
34image.save("edited_image.png")| 50 steps | 8 steps |
|---|---|
![]() | ![]() |
![]() | ![]() |
![]() | ![]() |
![]() | ![]() |
guidance_scale also impacts the results:| Prompt | Collage (gs: 10) | Collage (gs: 20) | Collage (gs: 30) | Collage (gs: 40) |
|---|---|---|---|---|
| Give this the look of a traditional Japanese woodblock print. | ![]() | ![]() | ![]() | ![]() |
| transform the setting to a winter scene | ![]() | ![]() | ![]() | ![]() |
| turn the color of mushroom to gray | ![]() | ![]() | ![]() | ![]() |
bitsandbytes)1sigmas = torch.rand(batch_size)
2timesteps = (sigmas * noise_scheduler.config.num_train_timesteps).long()
3...
4
5noisy_model_input = (1.0 - sigmas) * pixel_latents + sigmas * noisepixel_latents is computed from the source images and noise is drawn from a Gaussian distribution. For more details, check out
the repository.