ImageSegmenter classkeras_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 methodImageSegmenter.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,
)
| Preset | Parameters | Description |
|---|---|---|
| basnet_duts | 108.89M | BASNet model with a 34-layer ResNet backbone, pre-trained on the DUTS image dataset at a 288x288 resolution. Model training was performed by Hamid Ali (https://github.com/hamidriasat/BASNet). |
| 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_huge_sa1b | 312.34M | The huge SAM model trained on the SA1B dataset. |
| sam_large_sa1b | 641.09M | The large SAM model trained on the SA1B dataset. |
| segformer_b0_ade20k_512 | 3.72M | SegFormer model with MiTB0 backbone fine-tuned on ADE20k in 512x512 resolution. |
| segformer_b0_cityscapes_1024 | 3.72M | SegFormer model with MiTB0 backbone fine-tuned on Cityscapes in 1024x1024 resolution. |
| segformer_b1_ade20k_512 | 13.68M | SegFormer model with MiTB1 backbone fine-tuned on ADE20k in 512x512 resolution. |
| segformer_b1_cityscapes_1024 | 13.68M | SegFormer model with MiTB1 backbone fine-tuned on Cityscapes in 1024x1024 resolution. |
| segformer_b2_ade20k_512 | 24.73M | SegFormer model with MiTB2 backbone fine-tuned on ADE20k in 512x512 resolution. |
| segformer_b2_cityscapes_1024 | 24.73M | SegFormer model with MiTB2 backbone fine-tuned on Cityscapes in 1024x1024 resolution. |
| segformer_b3_ade20k_512 | 44.60M | SegFormer model with MiTB3 backbone fine-tuned on ADE20k in 512x512 resolution. |
| segformer_b3_cityscapes_1024 | 44.60M | SegFormer model with MiTB3 backbone fine-tuned on Cityscapes in 1024x1024 resolution. |
| segformer_b4_ade20k_512 | 61.37M | SegFormer model with MiTB4 backbone fine-tuned on ADE20k in 512x512 resolution. |
| segformer_b4_cityscapes_1024 | 61.37M | SegFormer model with MiTB4 backbone fine-tuned on Cityscapes in 1024x1024 resolution. |
| segformer_b5_ade20k_640 | 81.97M | SegFormer model with MiTB5 backbone fine-tuned on ADE20k in 640x640 resolution. |
| segformer_b5_cityscapes_1024 | 81.97M | SegFormer model with MiTB5 backbone fine-tuned on Cityscapes in 1024x1024 resolution. |
compile methodImageSegmenter.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
"auto", an optimizer name, or a keras.Optimizer
instance. Defaults to "auto", which uses the default optimizer
for the given model and task. See keras.Model.compile and
keras.optimizers for more info on possible optimizer values."auto", a loss name, or a keras.losses.Loss instance.
Defaults to "auto", where a
keras.losses.SparseCategoricalCrossentropy loss will be
applied for the classification task. See
keras.Model.compile and keras.losses for more info on
possible loss values."auto", or a list of metrics to be evaluated by
the model during training and testing. Defaults to "auto",
where a keras.metrics.SparseCategoricalAccuracy will be
applied to track the accuracy of the model during training.
See keras.Model.compile and keras.metrics for
more info on possible metrics values.keras.Model.compile for a full list of arguments
supported by the compile method.save_to_preset methodImageSegmenter.save_to_preset(preset_dir, max_shard_size=10)
Save task to a preset directory.
Arguments
int or float. Maximum size in GB for each
sharded file. If None, no sharding will be done. Defaults to
10.preprocessor propertykeras_hub.models.ImageSegmenter.preprocessor
A keras_hub.models.Preprocessor layer used to preprocess input.
backbone propertykeras_hub.models.ImageSegmenter.backbone
A keras_hub.models.Backbone model with the core architecture.