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 模型 (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"