FluxTextToImage classkeras_hub.models.FluxTextToImage(backbone, preprocessor, **kwargs)
An end-to-end Flux model for text-to-image generation.
This model has a generate() method, which generates image based on a
prompt.
Arguments
keras_hub.models.FluxBackbone instance.keras_hub.models.FluxTextToImagePreprocessor instance.Examples
Use generate() to do image generation.
prompt = (
"Astronaut in a jungle, cold color palette, muted colors, "
"detailed, 8k"
)
text_to_image = keras_hub.models.FluxTextToImage.from_preset(
"TBA", height=512, width=512
)
text_to_image.generate(
prompt
)
# 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(
prompt,
num_steps=50,
guidance_scale=5.0,
)
# Generate with `negative_prompts`.
text_to_image.generate(
{
"prompts": prompt,
"negative_prompts": "green color",
}
)
from_preset methodFluxTextToImage.from_preset(preset, load_weights=True, **kwargs)
Instantiate a keras_hub.models.Task from a model preset.
A preset is a directory of configs, weights and other file assets used
to save and load a pre-trained model. The preset can be passed as
one of:
'bert_base_en''kaggle://user/bert/keras/bert_base_en''hf://user/bert_base_en''./bert_base_en'For any Task subclass, you can run cls.presets.keys() to list all
built-in presets available on the class.
This constructor can be called in one of two ways. Either from a task
specific base class like keras_hub.models.CausalLM.from_preset(), or
from a model class like
keras_hub.models.BertTextClassifier.from_preset().
If calling from the a base class, the subclass of the returning object
will be inferred from the config in the preset directory.
Arguments
True, saved weights will be loaded into
the model architecture. If False, all weights will be
randomly initialized.Examples
# 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,
)
backbone propertykeras_hub.models.FluxTextToImage.backbone
A keras_hub.models.Backbone model with the core architecture.
generate methodFluxTextToImage.generate(inputs, num_steps=28, guidance_scale=7.0, seed=None)
Generate image based on the provided inputs.
Typically, inputs contains a text description (known as a prompt) used
to guide the image generation.
Some models support a negative_prompts key, which helps steer the
model away from generating certain styles and elements. To enable this,
pass prompts and negative_prompts as a dict:
prompt = (
"Astronaut in a jungle, cold color palette, muted colors, "
"detailed, 8k"
)
text_to_image.generate(
{
"prompts": prompt,
"negative_prompts": "green color",
}
)
If inputs are a tf.data.Dataset, outputs will be generated
"batch-by-batch" and concatenated. Otherwise, all inputs will be
processed as batches.
Arguments
tf.data.Dataset. The format
must be one of the following:tf.data.Dataset with "prompts" and/or "negative_prompts"
keyspreprocessor propertykeras_hub.models.FluxTextToImage.preprocessor
A keras_hub.models.Preprocessor layer used to preprocess input.