DeepLabV3Plus
classkeras_cv.models.DeepLabV3Plus(
backbone,
num_classes,
projection_filters=48,
spatial_pyramid_pooling=None,
segmentation_head=None,
**kwargs
)
A Keras model implementing the DeepLabV3+ architecture for semantic segmentation.
References
Arguments
keras.Model
. The backbone network for the model that is
used as a feature extractor for the DeepLabV3+ Encoder. Should
either be a keras_cv.models.backbones.backbone.Backbone
or a
keras.Model
that implements the pyramid_level_inputs
property with keys "P2" and "P5" and layer names as values. A
somewhat sensible backbone to use in many cases is the
keras_cv.models.ResNet50V2Backbone.from_preset("resnet50_v2_imagenet")
.num_classes
contains the background class, and the
classes from the data should be represented by integers with range
[0, num_classes
).backbone
. The default
value is set to 48
, as per the
TensorFlow implementation of DeepLab. # noqa: E501keras.layers.Layer
. Also known
as Atrous Spatial Pyramid Pooling (ASPP). Performs spatial pooling
on different spatial levels in the pyramid, with dilation. If
provided, the feature map from the backbone is passed to it inside
the DeepLabV3 Encoder, otherwise
keras_cv.layers.spatial_pyramid.SpatialPyramidPooling
is used.keras.layers.Layer
. If provided, the
outputs of the DeepLabV3 encoder is passed to this layer and it
should predict the segmentation mask based on feature from backbone
and feature from decoder, otherwise a default DeepLabV3
convolutional head is used.Example
import keras_cv
images = np.ones(shape=(1, 96, 96, 3))
labels = np.zeros(shape=(1, 96, 96, 1))
backbone = keras_cv.models.ResNet50V2Backbone(input_shape=[96, 96, 3])
model = keras_cv.models.segmentation.DeepLabV3Plus(
num_classes=1, backbone=backbone,
)
# Evaluate model
model(images)
# Train model
model.compile(
optimizer="adam",
loss=keras.losses.BinaryCrossentropy(from_logits=False),
metrics=["accuracy"],
)
model.fit(images, labels, epochs=3)
from_preset
methodDeepLabV3Plus.from_preset()
Instantiate DeepLabV3Plus model from preset config and weights.
Arguments
None
, which follows whether the preset has
pretrained weights available.None
.If None
, the preset
value will be used.Example
# Load architecture and weights from preset
model = keras_cv.models.DeepLabV3Plus.from_preset(
"resnet50_imagenet",
)
# Load randomly initialized model from preset architecture with weights
model = keras_cv.models.DeepLabV3Plus.from_preset(
"resnet50_imagenet",
load_weights=False,
Preset name | Parameters | Description |
---|---|---|
deeplab_v3_plus_resnet50_pascalvoc | 39.19M | DeeplabV3Plus with a ResNet50 v2 backbone. Trained on PascalVOC 2012 Semantic segmentation task, which consists of 20 classes and one background class. This model achieves a final categorical accuracy of 89.34% and mIoU of 0.6391 on evaluation dataset. This preset is only comptabile with Keras 3. |