Keras 3 API 文档 / KerasCV / 模型 / 骨干网络 / DenseNet 主干网络

DenseNet 主干网络

[source]

DenseNetBackbone class

keras_cv.models.DenseNetBackbone(
    stackwise_num_repeats,
    include_rescaling,
    input_shape=(None, None, 3),
    input_tensor=None,
    compression_ratio=0.5,
    growth_rate=32,
    **kwargs
)

Instantiates the DenseNet architecture.

Arguments

  • stackwise_num_repeats: list of ints, number of repeated convolutional blocks per dense block.
  • include_rescaling: bool, whether to rescale the inputs. If set to True, inputs will be passed through a Rescaling(1/255.0) layer.
  • input_shape: optional shape tuple, defaults to (None, None, 3).
  • input_tensor: optional Keras tensor (i.e. output of keras.layers.Input()) to use as image input for the model.
  • compression_ratio: float, compression rate at transition layers.
  • growth_rate: int, number of filters added by each dense block.

Examples

input_data = tf.ones(shape=(8, 224, 224, 3))

# Pretrained backbone
model = keras_cv.models.DenseNetBackbone.from_preset("densenet121_imagenet")
output = model(input_data)

# Randomly initialized backbone with a custom config
model = DenseNetBackbone(
    stackwise_num_repeats=[6, 12, 24, 16],
    include_rescaling=False,
)
output = model(input_data)

[source]

from_preset method

DenseNetBackbone.from_preset()

Instantiate DenseNetBackbone model from preset config and weights.

Arguments

  • preset: string. Must be one of "densenet121", "densenet169", "densenet201", "densenet121_imagenet", "densenet169_imagenet", "densenet201_imagenet". If looking for a preset with pretrained weights, choose one of "densenet121_imagenet", "densenet169_imagenet", "densenet201_imagenet".
  • load_weights: Whether to load pre-trained weights into model. Defaults to None, which follows whether the preset has pretrained weights available.

Examples

# Load architecture and weights from preset
model = keras_cv.models.DenseNetBackbone.from_preset(
    "densenet121_imagenet",
)

# Load randomly initialized model from preset architecture with weights
model = keras_cv.models.DenseNetBackbone.from_preset(
    "densenet121_imagenet",
    load_weights=False,
Preset name Parameters Description
densenet121 Unknown DenseNet model with 121 layers.
densenet169 Unknown DenseNet model with 169 layers.
densenet201 Unknown DenseNet model with 201 layers.
densenet121_imagenet Unknown DenseNet model with 121 layers. Trained on Imagenet 2012 classification task.
densenet169_imagenet Unknown DenseNet model with 169 layers. Trained on Imagenet 2012 classification task.
densenet201_imagenet Unknown DenseNet model with 201 layers. Trained on Imagenet 2012 classification task.

[source]

DenseNet121Backbone class

keras_cv.models.DenseNet121Backbone(
    stackwise_num_repeats,
    include_rescaling,
    input_shape=(None, None, 3),
    input_tensor=None,
    compression_ratio=0.5,
    growth_rate=32,
    **kwargs
)

DenseNetBackbone model with 121 layers.

Reference

For transfer learning use cases, make sure to read the guide to transfer learning & fine-tuning.

Arguments

  • include_rescaling: bool, whether to rescale the inputs. If set to True, inputs will be passed through a Rescaling(1/255.0) layer.
  • input_shape: optional shape tuple, defaults to (None, None, 3).
  • input_tensor: optional Keras tensor (i.e. output of layers.Input()) to use as image input for the model.

Example

input_data = tf.ones(shape=(8, 224, 224, 3))

# Randomly initialized backbone
model = DenseNet121Backbone()
output = model(input_data)

[source]

DenseNet169Backbone class

keras_cv.models.DenseNet169Backbone(
    stackwise_num_repeats,
    include_rescaling,
    input_shape=(None, None, 3),
    input_tensor=None,
    compression_ratio=0.5,
    growth_rate=32,
    **kwargs
)

DenseNetBackbone model with 169 layers.

Reference

For transfer learning use cases, make sure to read the guide to transfer learning & fine-tuning.

Arguments

  • include_rescaling: bool, whether to rescale the inputs. If set to True, inputs will be passed through a Rescaling(1/255.0) layer.
  • input_shape: optional shape tuple, defaults to (None, None, 3).
  • input_tensor: optional Keras tensor (i.e. output of layers.Input()) to use as image input for the model.

Example

input_data = tf.ones(shape=(8, 224, 224, 3))

# Randomly initialized backbone
model = DenseNet169Backbone()
output = model(input_data)

[source]

DenseNet201Backbone class

keras_cv.models.DenseNet201Backbone(
    stackwise_num_repeats,
    include_rescaling,
    input_shape=(None, None, 3),
    input_tensor=None,
    compression_ratio=0.5,
    growth_rate=32,
    **kwargs
)

DenseNetBackbone model with 201 layers.

Reference

For transfer learning use cases, make sure to read the guide to transfer learning & fine-tuning.

Arguments

  • include_rescaling: bool, whether to rescale the inputs. If set to True, inputs will be passed through a Rescaling(1/255.0) layer.
  • input_shape: optional shape tuple, defaults to (None, None, 3).
  • input_tensor: optional Keras tensor (i.e. output of layers.Input()) to use as image input for the model.

Example

input_data = tf.ones(shape=(8, 224, 224, 3))

# Randomly initialized backbone
model = DenseNet201Backbone()
output = model(input_data)