Skip to content

Instantly share code, notes, and snippets.

@perk11
Created September 28, 2024 16:50
Show Gist options
  • Save perk11/11d7b0397e95375bda2fd7c0ac8ace67 to your computer and use it in GitHub Desktop.
Save perk11/11d7b0397e95375bda2fd7c0ac8ace67 to your computer and use it in GitHub Desktop.
import torch
from diffusers.utils import load_image
from diffusers import FluxControlNetModel
from diffusers.pipelines import FluxControlNetPipeline
# Load pipeline
controlnet = FluxControlNetModel.from_pretrained(
"jasperai/Flux.1-dev-Controlnet-Upscaler",
torch_dtype=torch.bfloat16
)
pipe = FluxControlNetPipeline.from_pretrained(
"black-forest-labs/FLUX.1-dev",
controlnet=controlnet,
torch_dtype=torch.bfloat16
)
#pipe.to("cuda")
pipe.enable_sequential_cpu_offload() #save some VRAM by offloading the model to CPU. Remove this if you have enough GPU power
# Load a control image
control_image = load_image(
"https://huggingface.co/jasperai/Flux.1-dev-Controlnet-Upscaler/resolve/main/examples/input.jpg"
)
w, h = control_image.size
# Upscale x4
control_image = control_image.resize((4*w,4*h))
image = pipe(
prompt="",
control_image=control_image,
controlnet_conditioning_scale=0.6,
num_inference_steps=28,
guidance_scale=3.5,
height=control_image.size[1],
width=control_image.size[0]
).images[0]
image.save("out.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment