参考资料 ultralytics/models/sam/modules/decoders.py
备注
该文件可在https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/ sam/modules/decoders .py 下找到。如果您发现问题,请通过提交 Pull Request🛠️ 帮助修复。谢谢🙏!
ultralytics.models.sam.modules.decoders.MaskDecoder
垒球 Module
用于生成掩码及其相关质量分数的解码器模块,使用转换器架构来预测 给定图像和提示嵌入的掩码。
属性
名称 | 类型 | 说明 |
---|---|---|
transformer_dim |
int
|
变压器模块的通道尺寸。 |
transformer |
Module
|
用于掩码预测的变压器模块。 |
num_multimask_outputs |
int
|
预测消歧掩码的掩码数。 |
iou_token |
Embedding
|
嵌入 IoU 标记。 |
num_mask_tokens |
int
|
掩码令牌数量。 |
mask_tokens |
Embedding
|
嵌入掩码标记。 |
output_upscaling |
Sequential
|
用于提升输出的神经网络序列。 |
output_hypernetworks_mlps |
ModuleList
|
用于生成掩码的超网络 MLP。 |
iou_prediction_head |
Module
|
用于预测掩膜质量的 MLP |
源代码 ultralytics/models/sam/modules/decoders.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
__init__(*, transformer_dim, transformer, num_multimask_outputs=3, activation=nn.GELU, iou_head_depth=3, iou_head_hidden_dim=256)
利用变换器架构,预测给定图像和提示嵌入的掩码。
参数
名称 | 类型 | 说明 | 默认值 |
---|---|---|---|
transformer_dim |
int
|
变压器模块的通道尺寸 |
所需 |
transformer |
Module
|
用于预测掩码的转换器 |
所需 |
num_multimask_outputs |
int
|
消除歧义时要预测的掩码数量 |
3
|
activation |
Module
|
上调掩码时使用的激活类型 |
GELU
|
iou_head_depth |
int
|
用于预测掩膜质量的 MLP 深度 |
3
|
iou_head_hidden_dim |
int
|
用于预测掩膜质量的 MLP 的隐藏维度 |
256
|
源代码 ultralytics/models/sam/modules/decoders.py
forward(image_embeddings, image_pe, sparse_prompt_embeddings, dense_prompt_embeddings, multimask_output)
预测给定图像的掩码并提示嵌入。
参数
名称 | 类型 | 说明 | 默认值 |
---|---|---|---|
image_embeddings |
Tensor
|
来自图像编码器的嵌入信息 |
所需 |
image_pe |
Tensor
|
用图像嵌入形状进行位置编码 |
所需 |
sparse_prompt_embeddings |
Tensor
|
点和方框的嵌入 |
所需 |
dense_prompt_embeddings |
Tensor
|
掩码输入的嵌入 |
所需 |
multimask_output |
bool
|
是返回多个掩码还是单个掩码。 |
所需 |
返回:
类型 | 说明 |
---|---|
Tensor
|
torchTensor: 分批预测掩码 |
Tensor
|
torch.Tensor :分批预测掩膜质量 |
源代码 ultralytics/models/sam/modules/decoders.py
predict_masks(image_embeddings, image_pe, sparse_prompt_embeddings, dense_prompt_embeddings)
预测面具
详见 "前进"。
源代码 ultralytics/models/sam/modules/decoders.py
ultralytics.models.sam.modules.decoders.MLP
垒球 Module
MLP(多层感知器)模型改编自 https://github.com/facebookresearch/MaskFormer/blob/main/mask_former/modeling/transformer/transformer_predictor.py
源代码 ultralytics/models/sam/modules/decoders.py
__init__(input_dim, hidden_dim, output_dim, num_layers, sigmoid_output=False)
初始化 MLP(多层感知器)模型。
参数
名称 | 类型 | 说明 | 默认值 |
---|---|---|---|
input_dim |
int
|
输入特征的维度。 |
所需 |
hidden_dim |
int
|
隐藏层的维度。 |
所需 |
output_dim |
int
|
输出层的维度。 |
所需 |
num_layers |
int
|
隐藏层数。 |
所需 |
sigmoid_output |
bool
|
对输出层应用 sigmoid 激活。默认为假。 |
False
|
源代码 ultralytics/models/sam/modules/decoders.py
forward(x)
在神经网络模块内执行前馈,并应用激活。