Diffusers documentation

Điểm kiểm tra cũ

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).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Điểm kiểm tra cũ

Các cài đặt này chủ yếu áp dụng cho các checkpoint thuộc họ Stable Diffusion đời cũ.

Trình kiểm tra an toàn

Diffusers cung cấp trình kiểm tra an toàn cho các checkpoint Stable Diffusion cũ để ngăn chặn việc tạo ra nội dung gây hại. Nó sàng lọc đầu ra được tạo ra dựa trên một tập hợp các khái niệm gây hại được mã hóa cứng. Các mô hình mới hơn như Qwen-Image không có trình kiểm tra này.

Nếu bạn muốn tắt bộ kiểm tra an toàn, hãy truyền safety_checker=None vào from_pretrained() như minh họa bên dưới.

from diffusers import DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained(
  "stable-diffusion-v1-5/stable-diffusion-v1-5", safety_checker=None
)
"""
You have disabled the safety checker for <class 'diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline'> by passing `safety_checker=None`. Ensure that you abide by the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public. Both the diffusers team and Hugging Face strongly recommend keeping the safety filter enabled in all public-facing circumstances, disabling it only for use cases that involve analyzing network behavior or auditing its results. For more information, please have a look at https://github.com/huggingface/diffusers/pull/254 .
"""

Lịch trình điều chỉnh lại

Quá trình khử nhiễu bắt đầu từ nhiễu thuần túy, do đó tỷ số tín hiệu trên nhiễu (SNR) ban đầu bằng không. Một số mô hình thực tế không bắt đầu từ nhiễu thuần túy, khiến việc tạo ra các cực trị sáng và tối trở nên khó khăn.

Huấn luyện mô hình của riêng bạn với v_prediction bằng cách thêm cờ --prediction_type="v_prediction" vào script huấn luyện. Bạn cũng có thể tìm kiếm các mô hình hiện có được huấn luyện với v_prediction.

Đối với mô hình v_prediction, hãy bật các đối số trình lập lịch này.

  • Đặt rescale_betas_zero_snr=True để hiệu chỉnh lại lịch trình nhiễu (noise schedule) cho bước thời gian (timestep) cuối cùng với SNR bằng đúng 0
  • Đặt timestep_spacing="trailing" để buộc lấy mẫu từ bước thời gian cuối cùng với nhiễu thuần túy
from diffusers import DiffusionPipeline, DDIMScheduler

pipeline = DiffusionPipeline.from_pretrained("ptx0/pseudo-journey-v2", device_map="cuda")  # or "mps", "xpu", "cpu"

pipeline.scheduler = DDIMScheduler.from_config(
    pipeline.scheduler.config, rescale_betas_zero_snr=True, timestep_spacing="trailing"
)

Đặt guidance_rescale trong pipeline để tránh các hình ảnh bị cháy sáng. Giá trị thấp hơn sẽ làm tăng độ sáng, nhưng một số chi tiết có thể bị mờ nhạt.

prompt = """
cinematic photo of a snowy mountain at night with the northern lights aurora borealis
overhead, 35mm photograph, film, professional, 4k, highly detailed
"""
image = pipeline(prompt, guidance_rescale=0.7).images[0]
không có zero SNR
với SNR bằng không và khoảng cách phía sau
Update on GitHub