StableDiffusion3Inpaint
類別keras_hub.models.StableDiffusion3Inpaint(backbone, preprocessor, **kwargs)
用於圖像修復生成的端對端 Stable Diffusion 3 模型。
此模型具有 generate()
方法,可根據參考圖像、遮罩和文字提示的組合生成圖像。
引數
keras_hub.models.StableDiffusion3Backbone
實例。keras_hub.models.StableDiffusion3TextToImagePreprocessor
實例。範例
使用 generate()
進行圖像生成。
reference_image = np.ones((1024, 1024, 3), dtype="float32")
reference_mask = np.ones((1024, 1024), dtype="float32")
inpaint = keras_hub.models.StableDiffusion3Inpaint.from_preset(
"stable_diffusion_3_medium", image_shape=(512, 512, 3)
)
inpaint.generate(
reference_image,
reference_mask,
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
)
# Generate with batched prompts.
reference_images = np.ones((2, 512, 512, 3), dtype="float32")
reference_mask = np.ones((2, 1024, 1024), dtype="float32")
inpaint.generate(
reference_images,
reference_mask,
["cute wallpaper art of a cat", "cute wallpaper art of a dog"]
)
# Generate with different `num_steps`, `guidance_scale` and `strength`.
inpaint.generate(
reference_image,
reference_mask,
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
num_steps=50,
guidance_scale=5.0,
strength=0.6,
)
from_preset
方法StableDiffusion3Inpaint.from_preset(preset, load_weights=True, **kwargs)
從模型預設實例化 keras_hub.models.Task
。
預設是一個組態、權重和其他檔案資產的目錄,用於儲存和載入預訓練模型。 preset
可以作為以下其中一種傳遞
'bert_base_en'
'kaggle://user/bert/keras/bert_base_en'
'hf://user/bert_base_en'
'./bert_base_en'
對於任何 Task
子類別,您可以執行 cls.presets.keys()
以列出該類別上所有可用的內建預設。
此建構子可以透過兩種方式之一呼叫。 從任務特定的基底類別(例如 keras_hub.models.CausalLM.from_preset()
)呼叫,或從模型類別(例如 keras_hub.models.BertTextClassifier.from_preset()
)呼叫。 如果從基底類別呼叫,則傳回物件的子類別將從預設目錄中的組態推斷出來。
引數
True
,則儲存的權重將載入到模型架構中。 如果為 False
,則所有權重都將隨機初始化。範例
# Load a Gemma generative task.
causal_lm = keras_hub.models.CausalLM.from_preset(
"gemma_2b_en",
)
# Load a Bert classification task.
model = keras_hub.models.TextClassifier.from_preset(
"bert_base_en",
num_classes=2,
)
預設 | 參數 | 描述 |
---|---|---|
stable_diffusion_3_medium | 2.99B | 30 億參數,包括 CLIP L 和 CLIP G 文字編碼器、MMDiT 生成模型和 VAE 自動編碼器。 由 Stability AI 開發。 |
stable_diffusion_3.5_medium | 3.37B | 30 億參數,包括 CLIP L 和 CLIP G 文字編碼器、MMDiT-X 生成模型和 VAE 自動編碼器。 由 Stability AI 開發。 |
stable_diffusion_3.5_large | 9.05B | 90 億參數,包括 CLIP L 和 CLIP G 文字編碼器、MMDiT 生成模型和 VAE 自動編碼器。 由 Stability AI 開發。 |
stable_diffusion_3.5_large_turbo | 9.05B | 90 億參數,包括 CLIP L 和 CLIP G 文字編碼器、MMDiT 生成模型和 VAE 自動編碼器。 一個時間步蒸餾版本,消除了無分類器引導,並使用更少的步驟進行生成。 由 Stability AI 開發。 |
backbone
屬性keras_hub.models.StableDiffusion3Inpaint.backbone
具有核心架構的 keras_hub.models.Backbone
模型。
generate
方法StableDiffusion3Inpaint.generate(
inputs, num_steps=50, strength=0.6, guidance_scale=7.0, seed=None
)
根據提供的 inputs
生成圖像。
通常,inputs
是一個字典,包含 "images"
、"masks"
和 "prompts"
鍵。 "images"
是值範圍在 [-1.0, 1.0]
內的參考圖像,將調整大小為 self.backbone.image_shape
的高度和寬度,然後由 VAE 編碼器編碼為潛在空間。 "masks"
是布林值 dtype 的遮罩圖像,其中白色像素被重新繪製,而黑色像素被保留。 "prompts"
是將被 Tokenize 並由文字編碼器編碼的字串。
某些模型支援 "negative_prompts"
鍵,這有助於引導模型遠離生成某些樣式和元素。 若要啟用此功能,請將 "negative_prompts"
新增至輸入字典。
如果 inputs
是 tf.data.Dataset
,則輸出將「逐批次」生成並串聯。 否則,所有輸入都將作為批次處理。
引數
tf.data.Dataset
。 格式必須是以下之一"images"
、"masks"
、"prompts"
和/或 "negative_prompts"
鍵的字典。"images"
、"masks"
、"prompts"
和/或 "negative_prompts"
鍵的 tf.data.Dataset
。images
被轉換的程度。 必須介於 0.0
和 1.0
之間。 當 strength=1.0
時,images
本質上被忽略,並且加入的雜訊最大,去噪過程將執行 num_steps
中指定的完整迭代次數。preprocessor
屬性keras_hub.models.StableDiffusion3Inpaint.preprocessor
用於預處理輸入的 keras_hub.models.Preprocessor
層。