老闆下午要上新品頁面,阿凱需要同一隻狐狸玩偶在「雪地黃昏」和「月光夜晚」兩種情境的照片,但現場根本沒拍
FLUX.3 Klein 是 Black Forest Labs 新發表的開源圖像生成模型,Hugging Face 的 DiffusersHugging Face 出的 Python 套件,把各種繪圖模型包成統一的呼叫方式,不用自己拼底層零件 已經支援它。你只要安裝套件、下載模型,就能在自己的顯示卡上畫圖。「開源」的意思是模型的權重(checkpoint模型訓練完存下來的檔案,載入後就能直接使用,像遊戲的存檔點)公開,任何人都能下載。
同一個模型一次涵蓋三件事:文字生圖(寫一段描述,產出一張圖)、多張參考圖生圖(丟一張或多張圖給它,再描述想要的變化),以及用邊界框(bounding-box在畫面上框出一個長方形,告訴模型「這個東西要放在這個範圍」)控制版面。以前這些常常要分別用不同模型,現在合併成一個。
官方一次放出兩個 checkpoint。第一個是蒸餾版(flux-3-image-klein),官方說明是 time step distilled時間步蒸餾:讓模型學會用更少的畫圖步驟,達到接近原版的成果,像把十道工序濃縮成三道,預設只跑 16 步、不需要 CFG,在 H100 上畫一張 1024 × 1024 的圖約 2 秒。第二個是基礎版(flux-3-image-klein-base),預設跑 50 步並使用 CFGClassifier-Free Guidance,一個讓畫面更貼近你文字描述的調節機制,但每一步要多算一次,所以比較慢,適合想拿來微調或追求原始行為的人。
文字理解的部分,這個模型使用 Qwen3-VL 當作 text encoder文字編碼器:把你寫的句子轉成模型看得懂的一串數字,是文字和圖像之間的翻譯官,所以安裝時除了 diffusers,還要更新 transformers 套件。
| 項目 | flux-3-image-klein(蒸餾版) | flux-3-image-klein-base(基礎版) |
|---|---|---|
| 定位 | 快速推論 | 基礎模型 |
| 預設步數 | 16 步 | 50 步 |
| CFG | 不使用 | 使用 |
| 適合情境 | 快速出圖、反覆試 prompt | 需要原始模型行為、做微調的起點 |
這段程式載入蒸餾版 FLUX.3 Klein,用一句描述畫出一隻紅狐狸並存檔。
import torchfrom diffusers import ModularPipelinepipe = ModularPipeline.from_pretrained("black-forest-labs/flux-3-image-klein")pipe.load_components(dtype=torch.bfloat16)pipe.to("cuda")pipe(prompt="a red fox", output="images")[0].save("fox.png")這是一個真實小專案:下載(或複製)檔案,照步驟在你電腦上跑起來。
import torch
from diffusers import ModularPipeline
# 為什麼先用蒸餾版:16 步、不用 CFG,反覆試 prompt 的等待時間最短
pipe = ModularPipeline.from_pretrained("black-forest-labs/flux-3-image-klein")
pipe.load_components(dtype=torch.bfloat16)
pipe.to("cuda")
# 完整場景描述:主體、場景、光線、構圖、風格都寫進去
prompt = (
"A wide-angle wildlife photograph of a red fox standing alert in a snow-covered forest clearing at golden hour. "
"The fox is centered in the frame, its thick orange winter coat contrasting with the fresh white snow, breath "
"visible in the cold air. Snow-laden pine trees fill the softly blurred background, and low warm sunlight rakes "
"across the scene from the left, casting long blue shadows."
)
# 固定 seed,同一段描述才能重現同一張圖,方便比較改動的效果
fox = pipe(
prompt=prompt,
generator=torch.Generator().manual_seed(0),
output="images",
)[0]
fox.save("fox.png")
# 參考圖編輯:prompt 要寫成「想要的那張新圖」的說明,並把改動寫進去
prompt_night = (
"The same red fox in the same snow-covered forest clearing, now at night under a full moon: cool blue "
"moonlight, deep shadows, stars visible through the pine branches, the fox's eyes catching the light."
)
night = pipe(
prompt=prompt_night,
image=fox,
generator=torch.Generator().manual_seed(0),
output="images",
)[0]
night.save("night.png")
print("完成:fox.png(白天)與 night.png(夜晚)")