Diffusers documentation
Tạo ảnh từ độ sâu theo hướng dẫn văn bản
Bắt đầu
Suy luận
Sử dụng diffusion pipelines
Bộ thích ứng và cá nhân hóa
Tối ưu hóa và mở rộng
Hiệu suất cơ bản
Suy luận
Phương pháp từ cộng đồng
Lượng tử hóa
Tăng tốc theo phần cứng
Cung cấp dịch vụ và mở rộng quy mô
Modular Diffusers
Huấn luyện và tinh chỉnh
Tài nguyên
Công thức
Tạo ảnh không điều kiệnVăn bản sang hình ảnhẢnh sang ảnhInpaintingOutpaintingTạo videoTừ độ sâu sang ảnh
Khái niệm và bối cảnh
Đóng góp
API
You are viewing main version, which requires installation from source. If you'd like
regular pip install, checkout the latest stable version (v0.42.1).
Tạo ảnh từ độ sâu theo hướng dẫn văn bản
StableDiffusionDepth2ImgPipeline cho phép bạn truyền một prompt văn bản và một hình ảnh ban đầu để điều kiện cho việc tạo ra các hình ảnh mới. Ngoài ra, bạn cũng có thể truyền một depth_map để giữ nguyên cấu trúc của hình ảnh. Nếu không cung cấp depth_map, pipeline sẽ tự động dự đoán độ sâu thông qua một mô hình ước lượng độ sâu tích hợp sẵn.
Bắt đầu bằng cách tạo một instance của StableDiffusionDepth2ImgPipeline:
import torch
from diffusers import StableDiffusionDepth2ImgPipeline
from diffusers.utils import load_image, make_image_grid
pipeline = StableDiffusionDepth2ImgPipeline.from_pretrained(
"stabilityai/stable-diffusion-2-depth",
dtype=torch.float16,
use_safetensors=True,
).to("cuda") # or "mps", "xpu", "cpu"Bây giờ hãy truyền prompt của bạn vào pipeline. Bạn cũng có thể truyền negative_prompt để ngăn một số từ nhất định định hướng cách hình ảnh được tạo ra:
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
init_image = load_image(url)
prompt = "two tigers"
negative_prompt = "bad, deformed, ugly, bad anatomy"
image = pipeline(prompt=prompt, image=init_image, negative_prompt=negative_prompt, strength=0.7).images[0]
make_image_grid([init_image, image], rows=1, cols=2)| Đầu vào | Đầu ra |
|---|---|
![]() | ![]() |

