ImageSegmenter
- 원본 링크 : https://keras.io/api/keras_hub/base_classes/image_segmenter/
- 최종 확인 : 2024-11-26
ImageSegmenter
class
keras_hub.models.ImageSegmenter(*args, compile=True, **kwargs)
Base class for all image segmentation tasks.
ImageSegmenter
tasks wrap a keras_hub.models.Task
and
a keras_hub.models.Preprocessor
to create a model that can be used for
image segmentation.
All ImageSegmenter
tasks include a from_preset()
constructor which can
be used to load a pre-trained config and weights.
from_preset
method
ImageSegmenter.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:
- a built-in preset identifier like
'bert_base_en'
- a Kaggle Models handle like
'kaggle://user/bert/keras/bert_base_en'
- a Hugging Face handle like
'hf://user/bert_base_en'
- a path to a local preset directory like
'./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
- preset: string. A built-in preset identifier, a Kaggle Models handle, a Hugging Face handle, or a path to a local directory.
- load_weights: bool. If
True
, saved weights will be loaded into the model architecture. IfFalse
, 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,
)
Preset name | Parameters | Description |
---|---|---|
deeplab_v3_plus_resnet50_pascalvoc | 39.19M | DeepLabV3+ model with ResNet50 as image encoder and trained on augmented Pascal VOC dataset by Semantic Boundaries Dataset(SBD)which is having categorical accuracy of 90.01 and 0.63 Mean IoU. |
sam_base_sa1b | 93.74M | The base SAM model trained on the SA1B dataset. |
sam_large_sa1b | 641.09M | The large SAM model trained on the SA1B dataset. |
sam_huge_sa1b | 312.34M | The huge SAM model trained on the SA1B dataset. |
compile
method
ImageSegmenter.compile(optimizer="auto", loss="auto", metrics="auto", **kwargs)
Configures the ImageSegmenter
task for training.
The ImageSegmenter
task extends the default compilation signature of
keras.Model.compile
with defaults for optimizer
, loss
, and
metrics
. To override these defaults, pass any value
to these arguments during compilation.
Arguments
- optimizer:
"auto"
, an optimizer name, or akeras.Optimizer
instance. Defaults to"auto"
, which uses the default optimizer for the given model and task. Seekeras.Model.compile
andkeras.optimizers
for more info on possibleoptimizer
values. - loss:
"auto"
, a loss name, or akeras.losses.Loss
instance. Defaults to"auto"
, where akeras.losses.SparseCategoricalCrossentropy
loss will be applied for the classification task. Seekeras.Model.compile
andkeras.losses
for more info on possibleloss
values. - metrics:
"auto"
, or a list of metrics to be evaluated by the model during training and testing. Defaults to"auto"
, where akeras.metrics.SparseCategoricalAccuracy
will be applied to track the accuracy of the model during training. Seekeras.Model.compile
andkeras.metrics
for more info on possiblemetrics
values. - **kwargs: See
keras.Model.compile
for a full list of arguments supported by the compile method.
save_to_preset
method
ImageSegmenter.save_to_preset(preset_dir)
Save task to a preset directory.
Arguments
- preset_dir: The path to the local model preset directory.
preprocessor
property
keras_hub.models.ImageSegmenter.preprocessor
A keras_hub.models.Preprocessor
layer used to preprocess input.
backbone
property
keras_hub.models.ImageSegmenter.backbone
A keras_hub.models.Backbone
model with the core architecture.