SAMMaskDecoder 层

[源]

SAMMaskDecoder

keras_hub.layers.SAMMaskDecoder(
    hidden_size,
    num_layers,
    intermediate_dim,
    num_heads,
    embedding_dim=256,
    num_multimask_outputs=3,
    iou_head_depth=3,
    iou_head_hidden_dim=256,
    activation="gelu",
    **kwargs
)

Segment Anything Model (SAM) 的掩码解码器。

这个轻量级模块有效地将图像嵌入和一组提示嵌入映射到输出掩码。在应用 Transformer 解码器之前,该层首先将一个学习到的输出 token 嵌入插入到提示嵌入集中,该嵌入将在解码器的输出中使用。为了简单起见,这些嵌入(不包括图像嵌入)统称为“token”。

图像嵌入、位置图像嵌入和 token 通过一个 Transformer 解码器。运行解码器后,该层使用两个转置卷积层将更新后的图像嵌入上采样 4 倍(相对于输入图像现在缩小了 4 倍)。然后,token 再次关注图像嵌入,更新后的输出 token 嵌入被传递给一个小型 3 层 MLP,该 MLP 输出一个与上采样图像嵌入的通道维度匹配的向量。

最后,通过上采样图像嵌入与 MLP 输出之间的空间逐点乘积来预测掩码。

参数

  • hidden_size: int。TwoWayTransformer 的隐藏大小。
  • num_layers: int。TwoWayTransformer 的层数。
  • intermediate_dim: int。TwoWayTransformer 的中间维度。
  • num_heads: int。TwoWayTransformer 的头数。
  • embedding_dim: int,可选。Transformer 解码器的输入特征数量。默认为 256
  • num_multimask_outputs: int,可选。多掩码输出的数量。模型将生成这么多额外的掩码。模型生成的总掩码数量是 1 + num_multimask_outputs。默认为 3
  • iou_head_depth: int,可选。用于预测 IoU 置信度分数的全连接网络的深度。默认为 3
  • iou_head_hidden_dim: int,可选。用于预测 IoU 置信度分数的全连接网络隐藏层中的单元数量。默认为 256
  • activation: str,可选。在掩码上采样网络中使用的激活函数。默认为 "gelu"