Comments (2)
It seems that you need to calculate depth rather than directly put the raw image into controlnet pipeline:
`from transformers import pipeline
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
from PIL import Image
import numpy as np
import torch
from diffusers.utils import load_image
depth_estimator = pipeline('depth-estimation')
image = load_image("https://huggingface.co/lllyasviel/sd-controlnet-depth/resolve/main/images/stormtrooper.png")
image = depth_estimator(image)['depth']
image = np.array(image)
image = image[:, :, None]
image = np.concatenate([image, image, image], axis=2)
image = Image.fromarray(image)
controlnet = ControlNetModel.from_pretrained(
"lllyasviel/sd-controlnet-depth", torch_dtype=torch.float16
)
pipe = StableDiffusionControlNetPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5", controlnet=controlnet, safety_checker=None, torch_dtype=torch.float16
)
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
pipe.enable_xformers_memory_efficient_attention()
pipe.enable_model_cpu_offload()
image = pipe("Stormtrooper's lecture", image, num_inference_steps=20).images[0]
image.save('./images/stormtrooper_depth_out.png')
`
from depth-anything.
Thank you for your response. My current code isn't working. Could you update the README for ControlNet with a working example (code and images) to help me debug?
Here is my code
from transformers import pipeline
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
from PIL import Image
import numpy as np
import torch
from diffusers.utils import load_image
# Paths
base_model_path = "runwayml/stable-diffusion-v1-5"
controlnet_path = "controlnet" # Use a ControlNet model suited for depth
# Step 1: Estimate depth of the input image
depth_estimator = pipeline('depth-estimation')
# Load the input image
input_image_path = "bdd100k/images/100k/train_day/0a0a0b1a-7c39d841.jpg"
control_image = load_image(input_image_path)
# Estimate depth
depth_map = depth_estimator(control_image)['depth']
depth_map = np.array(depth_map)
depth_map = depth_map[:, :, None] # Add a channel dimension
depth_map = np.concatenate([depth_map, depth_map, depth_map], axis=2) # Make it 3-channel
depth_map = Image.fromarray(depth_map)
# Step 2: Set up the ControlNet pipeline with the depth model
controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)
pipe = StableDiffusionControlNetPipeline.from_pretrained(
base_model_path, controlnet=controlnet, torch_dtype=torch.float16
)
# Optimize the pipeline
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
# pipe.enable_xformers_memory_efficient_attention()
pipe.enable_model_cpu_offload()
# Define the prompt
prompt = "day to night"
# Step 3: Generate the image using the depth map as the control image
generator = torch.manual_seed(0)
output_image = pipe(
prompt, num_inference_steps=20, generator=generator, image=depth_map
).images[0]
# Save the output image
output_image.save("./output.png")
Here is my original (left) and result image (right)
I have also tried changing controlnet_path to this
controlnet_path = "lllyasviel/sd-controlnet-depth"
And get the following result, which is still bad.
from depth-anything.
Related Issues (20)
- No progressbar/estimation time? HOT 1
- Not detecting foreground elements HOT 2
- Model Paths for controlnet experiments
- serious issues with the new V2 metric depth anything model and others included in the N models! needs immediate attention! HOT 6
- Feature Request: Mask Support for Depth Estimation
- Whether the sky area is involved in the loss calculation? HOT 3
- Metric Depth Estimation model training HOT 1
- Train a custom unlabeled dataset on Metric depth estimation
- What are the units of depth values output by the model? HOT 1
- Training metric depth problem
- TypeError: "__init__()"miss 1 requirement positional argument:"config" HOT 2
- What is the difference between Depth-Anything and control_v11f1p_sd15_depth_fp16.safetensors?
- Want more detaile about training time and GPUs! HOT 1
- How to "not" resize image when inferencing metric depth? HOT 1
- Custom dataset training HOT 3
- How to calculate distance of the depth image ?
- How to ensure that the range of depth information obtained by the two different methods is consistent?
- mmseg::model registry error HOT 1
- train HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from depth-anything.