Keras 3 API 文件 / KerasCV / 模型 / 骨幹網路 / MobileNetV3 骨幹網路

MobileNetV3 骨幹網路

[來源]

MobileNetV3Backbone 類別

keras_cv.models.MobileNetV3Backbone(
    stackwise_expansion,
    stackwise_filters,
    stackwise_kernel_size,
    stackwise_stride,
    stackwise_se_ratio,
    stackwise_activation,
    include_rescaling,
    input_shape=(None, None, 3),
    input_tensor=None,
    alpha=1.0,
    **kwargs
)

實例化 MobileNetV3 架構。

參考資料

對於遷移學習用例,請務必閱讀遷移學習和微調指南

參數

  • stackwise_expansion:整數或浮點數列表,模型中每個反向殘差區塊的擴展比例。
  • stackwise_filters:整數列表,模型中每個反向殘差區塊的過濾器數量。
  • stackwise_stride:整數列表,模型中每個反向殘差區塊的步幅長度。
  • include_rescaling:布林值,是否重新調整輸入。如果設為 True,則輸入將通過 Rescaling(scale=1 / 255) 層。
  • input_shape:可選的形狀元組,預設為 (None, None, 3)。
  • input_tensor:可選的 Keras 張量(即 layers.Input() 的輸出),用作模型的圖像輸入。
  • alpha:浮點數,控制網路的寬度。這在 MobileNetV3 論文中稱為深度乘數,但為了與 Keras 中的 MobileNetV1 保持一致,保留了此名稱。
    • 如果 alpha < 1.0,則按比例減少每一層中的過濾器數量。
    • 如果 alpha > 1.0,則按比例增加每一層中的過濾器數量。
    • 如果 alpha = 1,則在每一層使用論文中的預設過濾器數量。

範例

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

# Randomly initialized backbone with a custom config
model = MobileNetV3Backbone(
    stackwise_expansion=[1, 72.0 / 16, 88.0 / 24, 4, 6, 6, 3, 3, 6, 6, 6],
    stackwise_filters=[16, 24, 24, 40, 40, 40, 48, 48, 96, 96, 96],
    stackwise_kernel_size=[3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5],
    stackwise_stride=[2, 2, 1, 2, 1, 1, 1, 1, 2, 1, 1],
    stackwise_se_ratio=[0.25, None, None, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25],
    stackwise_activation=["relu", "relu", "relu", "hard_swish", "hard_swish", "hard_swish", "hard_swish", "hard_swish", "hard_swish", "hard_swish", "hard_swish"],
    include_rescaling=False,
)
output = model(input_data)

[來源]

from_preset 方法

MobileNetV3Backbone.from_preset()

從預設配置和權重實例化 MobileNetV3Backbone 模型。

參數

  • preset:字串。必須是 "mobilenet_v3_small"、"mobilenet_v3_large"、"mobilenet_v3_large_imagenet"、"mobilenet_v3_small_imagenet" 其中之一。如果要尋找具有預先訓練權重的預設配置,請選擇 "mobilenet_v3_large_imagenet" 或 "mobilenet_v3_small_imagenet" 其中之一。
  • load_weights:是否將預先訓練的權重載入模型。預設為 None,這取決於預設配置是否有可用的預先訓練權重。

範例

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

# Load randomly initialized model from preset architecture with weights
model = keras_cv.models.MobileNetV3Backbone.from_preset(
    "mobilenet_v3_large_imagenet",
    load_weights=False,
預設名稱 參數 說明
mobilenet_v3_small 933.50K 具有 14 層的 MobileNetV3 模型,在卷積層後應用批次標準化和硬性 swish 激活函數。
mobilenet_v3_large 2.99M 具有 28 層的 MobileNetV3 模型,在卷積層後應用批次標準化和硬性 swish 激活函數。
mobilenet_v3_large_imagenet 2.99M 具有 28 層的 MobileNetV3 模型,在卷積層後應用批次標準化和硬性 swish 激活函數。在 ImageNet 2012 分類任務上進行了預先訓練。
mobilenet_v3_small_imagenet 933.50K 具有 14 層的 MobileNetV3 模型,在卷積層後應用批次標準化和硬性 swish 激活函數。在 ImageNet 2012 分類任務上進行了預先訓練。

[來源]

MobileNetV3SmallBackbone 類別

keras_cv.models.MobileNetV3SmallBackbone(
    stackwise_expansion,
    stackwise_filters,
    stackwise_kernel_size,
    stackwise_stride,
    stackwise_se_ratio,
    stackwise_activation,
    include_rescaling,
    input_shape=(None, None, 3),
    input_tensor=None,
    alpha=1.0,
    **kwargs
)

具有 14 層的 MobileNetV3Backbone 模型。

參考資料

對於遷移學習用例,請務必閱讀遷移學習和微調指南

參數

  • include_rescaling:布林值,是否重新縮放輸入。如果設定為 True,則輸入將通過 Rescaling(scale=1 / 255) 層。預設值為 True。
  • input_shape:可選的形狀元組,預設為 (None, None, 3)。
  • input_tensor:可選的 Keras 張量(即 layers.Input() 的輸出),用作模型的圖像輸入。

範例

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

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

[來源]

MobileNetV3LargeBackbone 類別

keras_cv.models.MobileNetV3LargeBackbone(
    stackwise_expansion,
    stackwise_filters,
    stackwise_kernel_size,
    stackwise_stride,
    stackwise_se_ratio,
    stackwise_activation,
    include_rescaling,
    input_shape=(None, None, 3),
    input_tensor=None,
    alpha=1.0,
    **kwargs
)

具有 28 層的 MobileNetV3Backbone 模型。

參考資料

對於遷移學習用例,請務必閱讀遷移學習和微調指南

參數

  • include_rescaling:布林值,是否重新縮放輸入。如果設定為 True,則輸入將通過 Rescaling(scale=1 / 255) 層。預設值為 True。
  • input_shape:可選的形狀元組,預設為 (None, None, 3)。
  • input_tensor:可選的 Keras 張量(即 layers.Input() 的輸出),用作模型的圖像輸入。

範例

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

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