StableDiffusion3TextToImage
類別keras_hub.models.StableDiffusion3TextToImage(backbone, preprocessor, **kwargs)
用於文字生成圖像的端對端 Stable Diffusion 3 模型。
此模型具有 generate()
方法,可根據提示詞生成圖像。
引數
keras_hub.models.StableDiffusion3Backbone
實例。keras_hub.models.StableDiffusion3TextToImagePreprocessor
實例。範例
使用 generate()
進行圖像生成。
text_to_image = keras_hub.models.StableDiffusion3TextToImage.from_preset(
"stable_diffusion_3_medium", image_shape=(512, 512, 3)
)
text_to_image.generate(
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
)
# Generate with batched prompts.
text_to_image.generate(
["cute wallpaper art of a cat", "cute wallpaper art of a dog"]
)
# Generate with different `num_steps` and `guidance_scale`.
text_to_image.generate(
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
num_steps=50,
guidance_scale=5.0,
)
# Generate with `negative_prompts`.
prompt = (
"Astronaut in a jungle, cold color palette, muted colors, "
"detailed, 8k"
)
text_to_image.generate(
{
"prompts": prompt,
"negative_prompts": "green color",
}
)
from_preset
方法StableDiffusion3TextToImage.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.StableDiffusion3TextToImage.backbone
具有核心架構的 keras_hub.models.Backbone
模型。
generate
方法StableDiffusion3TextToImage.generate(
inputs, num_steps=28, guidance_scale=7.0, seed=None
)
根據提供的 inputs
生成圖像。
通常,inputs
包含用於引導圖像生成的文字描述(稱為提示詞)。
某些模型支援 negative_prompts
鍵,這有助於引導模型避開生成某些風格和元素。若要啟用此功能,請將 prompts
和 negative_prompts
作為字典傳遞
prompt = (
"Astronaut in a jungle, cold color palette, muted colors, "
"detailed, 8k"
)
text_to_image.generate(
{
"prompts": prompt,
"negative_prompts": "green color",
}
)
如果 inputs
是 tf.data.Dataset
,則輸出將「逐批次」生成並串聯。否則,所有輸入都將作為批次處理。
引數
tf.data.Dataset
。格式必須是以下之一tf.data.Dataset
,具有 "prompts" 和/或 "negative_prompts" 鍵preprocessor
屬性keras_hub.models.StableDiffusion3TextToImage.preprocessor
用於預處理輸入的 keras_hub.models.Preprocessor
層。