🚀 DiffusionLight:通過繪製鉻球免費獲取光照探針
DiffusionLight 提出了一種簡單而有效的技術,用於估計單張輸入圖像中的光照情況。它利用擴散模型在數十億標準圖像上的訓練成果,解決了現有技術在真實、無控制環境下的侷限性,能在不同場景中產生令人信服的光照估計結果。
🚀 快速開始
我們推薦查看 GitHub 倉庫,該倉庫提供了從任何圖像中估計光照的代碼,包括生成鉻球、從鉻球中提取環境圖,以及使用自定義曝光組合方法創建 HDR 環境圖。
✨ 主要特性
- 創新光照估計技術:利用擴散模型在標準圖像上的訓練成果,解決了現有技術依賴 HDR 全景數據集的侷限性。
- 高質量鉻球生成:發現了鉻球外觀與初始擴散噪聲圖之間的關係,能夠持續生成高質量的鉻球。
- HDR 光照估計:通過 LoRA 微調 LDR 擴散模型(Stable Diffusion XL),使其能夠進行曝光包圍以進行 HDR 光照估計。
- 廣泛適用性:在不同場景中都能產生令人信服的光照估計結果,對真實場景具有出色的泛化能力。
📦 安裝指南
模型權重以 Safetensors 格式提供,可在 Files & versions 標籤頁 中下載。
💻 使用示例
基礎用法
如果您想使用此 LoRA 僅生成鉻球,可參考以下示例代碼:
import torch
from diffusers.utils import load_image
from diffusers import StableDiffusionXLControlNetInpaintPipeline, ControlNetModel
from transformers import pipeline
from PIL import Image
import numpy as np
IS_UNDER_EXPOSURE = False
if IS_UNDER_EXPOSURE:
PROMPT = "a perfect black dark mirrored reflective chrome ball sphere"
else:
PROMPT = "a perfect mirrored reflective chrome ball sphere"
NEGATIVE_PROMPT = "matte, diffuse, flat, dull"
IMAGE_URL = "https://raw.githubusercontent.com/DiffusionLight/DiffusionLight/main/example/bed.png"
controlnet = ControlNetModel.from_pretrained("diffusers/controlnet-depth-sdxl-1.0", torch_dtype=torch.float16)
pipe = StableDiffusionXLControlNetInpaintPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
controlnet=controlnet,
torch_dtype=torch.float16,
).to("cuda")
pipe.load_lora_weights("DiffusionLight/DiffusionLight")
pipe.fuse_lora(lora_scale=0.75)
depth_estimator = pipeline(task="depth-estimation", model="Intel/dpt-large")
init_image = load_image(IMAGE_URL)
depth_image = depth_estimator(images=init_image)['depth']
def get_circle_mask(size=256):
x = torch.linspace(-1, 1, size)
y = torch.linspace(1, -1, size)
y, x = torch.meshgrid(y, x)
z = (1 - x**2 - y**2)
mask = z >= 0
return mask
mask = get_circle_mask().numpy()
depth = np.asarray(depth_image).copy()
depth[384:640, 384:640] = depth[384:640, 384:640] * (1 - mask) + (mask * 255)
depth_mask = Image.fromarray(depth)
mask_image = np.zeros_like(depth)
mask_image[384:640, 384:640] = mask * 255
mask_image = Image.fromarray(mask_image)
output = pipe(
prompt=PROMPT,
negative_prompt=NEGATIVE_PROMPT,
num_inference_steps=30,
image=init_image,
mask_image=mask_image,
control_image=depth_mask,
controlnet_conditioning_scale=0.5,
)
output["images"][0].save("output.png")
高級用法
我們採用了自定義管道來為鉻球添加滿足特定需求的功能,包括 抗鋸齒 以平滑邊緣、迭代修復 以增強光照方向的正確性,以及 嵌入插值 以在不同曝光下生成鉻球。因此,強烈建議您訪問 GitHub 倉庫 以獲取更多高級用法。
📚 詳細文檔
觸發詞
鉻球狀態 |
提示詞 |
正常曝光 |
a perfect mirrored reflective chrome ball sphere |
欠曝光 |
a perfect black dark mirrored reflective chrome ball sphere |
鉻球生成
我們使用自定義管道來為鉻球添加滿足特定需求的功能。這包括 抗鋸齒 以平滑其邊緣,迭代修復 以增強光照方向的正確性,以及 嵌入插值 以在不同曝光下生成鉻球。因此,我們強烈建議您訪問我們的 GitHub 倉庫。
📄 許可證
本項目採用 MIT 許可證。
📖 引用
如果您使用了本項目的相關內容,請引用以下文獻:
@inproceedings{Phongthawee2023DiffusionLight,
author = {Phongthawee, Pakkapon and Chinchuthakun, Worameth and Sinsunthithet, Nontaphat and Raj, Amit and Jampani, Varun and Khungurn, Pramook and Suwajanakorn, Supasorn},
title = {DiffusionLight: Light Probes for Free by Painting a Chrome Ball},
booktitle = {ArXiv},
year = {2023},
}
🏢 相關鏈接
訪問我們 🦉
