BASNetImageSegmenter classkeras_hub.models.BASNetImageSegmenter(backbone, preprocessor=None, **kwargs)
BASNet image segmentation task.
Arguments
keras_hub.models.BASNetBackbone instance.None, a keras_hub.models.Preprocessor instance,
a keras.Layer instance, or a callable. If None no preprocessing
will be applied to the inputs.Example
import keras_hub
images = np.ones(shape=(1, 288, 288, 3))
labels = np.zeros(shape=(1, 288, 288, 1))
image_encoder = keras_hub.models.ResNetBackbone.from_preset(
"resnet_18_imagenet",
load_weights=False
)
backbone = keras_hub.models.BASNetBackbone(
image_encoder,
num_classes=1,
image_shape=[288, 288, 3]
)
model = keras_hub.models.BASNetImageSegmenter(backbone)
# Evaluate the model
pred_labels = model(images)
# Train the model
model.compile(
optimizer="adam",
loss=keras.losses.BinaryCrossentropy(from_logits=False),
metrics=["accuracy"],
)
model.fit(images, labels, epochs=3)
from_preset methodBASNetImageSegmenter.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). |
backbone propertykeras_hub.models.BASNetImageSegmenter.backbone
A keras_hub.models.Backbone model with the core architecture.
preprocessor propertykeras_hub.models.BASNetImageSegmenter.preprocessor
A keras_hub.models.Preprocessor layer used to preprocess input.