Predicts masks given an image and prompt embeddings, using a transformer architecture. Arguments: transformer_dim (int): the channel dimension of the transformer transformer (nn.Module): the transformer used to predict masks num_multimask_outpu
(
self,
*,
transformer_dim: int,
transformer: nn.Module,
num_multimask_outputs: int = 3,
activation: Type[nn.Module] = nn.GELU,
iou_head_depth: int = 3,
iou_head_hidden_dim: int = 256,
use_high_res_features: bool = False,
iou_prediction_use_sigmoid=False,
dynamic_multimask_via_stability=False,
dynamic_multimask_stability_delta=0.05,
dynamic_multimask_stability_thresh=0.98,
pred_obj_scores: bool = False,
pred_obj_scores_mlp: bool = False,
use_multimask_token_for_obj_ptr: bool = False,
)
| 14 | |
| 15 | class MaskDecoder(nn.Module): |
| 16 | def __init__( |
| 17 | self, |
| 18 | *, |
| 19 | transformer_dim: int, |
| 20 | transformer: nn.Module, |
| 21 | num_multimask_outputs: int = 3, |
| 22 | activation: Type[nn.Module] = nn.GELU, |
| 23 | iou_head_depth: int = 3, |
| 24 | iou_head_hidden_dim: int = 256, |
| 25 | use_high_res_features: bool = False, |
| 26 | iou_prediction_use_sigmoid=False, |
| 27 | dynamic_multimask_via_stability=False, |
| 28 | dynamic_multimask_stability_delta=0.05, |
| 29 | dynamic_multimask_stability_thresh=0.98, |
| 30 | pred_obj_scores: bool = False, |
| 31 | pred_obj_scores_mlp: bool = False, |
| 32 | use_multimask_token_for_obj_ptr: bool = False, |
| 33 | ) -> None: |
| 34 | """ |
| 35 | Predicts masks given an image and prompt embeddings, using a |
| 36 | transformer architecture. |
| 37 | |
| 38 | Arguments: |
| 39 | transformer_dim (int): the channel dimension of the transformer |
| 40 | transformer (nn.Module): the transformer used to predict masks |
| 41 | num_multimask_outputs (int): the number of masks to predict |
| 42 | when disambiguating masks |
| 43 | activation (nn.Module): the type of activation to use when |
| 44 | upscaling masks |
| 45 | iou_head_depth (int): the depth of the MLP used to predict |
| 46 | mask quality |
| 47 | iou_head_hidden_dim (int): the hidden dimension of the MLP |
| 48 | used to predict mask quality |
| 49 | """ |
| 50 | super().__init__() |
| 51 | self.transformer_dim = transformer_dim |
| 52 | self.transformer = transformer |
| 53 | |
| 54 | self.num_multimask_outputs = num_multimask_outputs |
| 55 | |
| 56 | self.iou_token = nn.Embedding(1, transformer_dim) |
| 57 | self.num_mask_tokens = num_multimask_outputs + 1 |
| 58 | self.mask_tokens = nn.Embedding(self.num_mask_tokens, transformer_dim) |
| 59 | |
| 60 | self.pred_obj_scores = pred_obj_scores |
| 61 | if self.pred_obj_scores: |
| 62 | self.obj_score_token = nn.Embedding(1, transformer_dim) |
| 63 | self.use_multimask_token_for_obj_ptr = use_multimask_token_for_obj_ptr |
| 64 | |
| 65 | self.output_upscaling = nn.Sequential( |
| 66 | nn.ConvTranspose2d( |
| 67 | transformer_dim, transformer_dim // 4, kernel_size=2, stride=2 |
| 68 | ), |
| 69 | LayerNorm2d(transformer_dim // 4), |
| 70 | activation(), |
| 71 | nn.ConvTranspose2d( |
| 72 | transformer_dim // 4, transformer_dim // 8, kernel_size=2, stride=2 |
| 73 | ), |
nothing calls this directly
no test coverage detected