MCPcopy Create free account
hub / github.com/VCIP-RGBD/DFormer / PatchEmbed

Class PatchEmbed

mmseg/models/utils/embed.py:77–197  ·  view source on GitHub ↗

Image to Patch Embedding. We use a conv layer to implement PatchEmbed. Args: in_channels (int): The num of input channels. Default: 3 embed_dims (int): The dimensions of embedding. Default: 768 conv_type (str): The config dict for embedding conv layer ty

Source from the content-addressed store, hash-verified

75
76
77class PatchEmbed(BaseModule):
78 """Image to Patch Embedding.
79
80 We use a conv layer to implement PatchEmbed.
81
82 Args:
83 in_channels (int): The num of input channels. Default: 3
84 embed_dims (int): The dimensions of embedding. Default: 768
85 conv_type (str): The config dict for embedding
86 conv layer type selection. Default: "Conv2d".
87 kernel_size (int): The kernel_size of embedding conv. Default: 16.
88 stride (int, optional): The slide stride of embedding conv.
89 Default: None (Would be set as `kernel_size`).
90 padding (int | tuple | string ): The padding length of
91 embedding conv. When it is a string, it means the mode
92 of adaptive padding, support "same" and "corner" now.
93 Default: "corner".
94 dilation (int): The dilation rate of embedding conv. Default: 1.
95 bias (bool): Bias of embed conv. Default: True.
96 norm_cfg (dict, optional): Config dict for normalization layer.
97 Default: None.
98 input_size (int | tuple | None): The size of input, which will be
99 used to calculate the out size. Only work when `dynamic_size`
100 is False. Default: None.
101 init_cfg (`mmcv.ConfigDict`, optional): The Config for initialization.
102 Default: None.
103 """
104
105 def __init__(
106 self,
107 in_channels=3,
108 embed_dims=768,
109 conv_type="Conv2d",
110 kernel_size=16,
111 stride=None,
112 padding="corner",
113 dilation=1,
114 bias=True,
115 norm_cfg=None,
116 input_size=None,
117 init_cfg=None,
118 ):
119 super(PatchEmbed, self).__init__(init_cfg=init_cfg)
120
121 self.embed_dims = embed_dims
122 if stride is None:
123 stride = kernel_size
124
125 kernel_size = to_2tuple(kernel_size)
126 stride = to_2tuple(stride)
127 dilation = to_2tuple(dilation)
128
129 if isinstance(padding, str):
130 self.adap_padding = AdaptivePadding(
131 kernel_size=kernel_size, stride=stride, dilation=dilation, padding=padding
132 )
133 # disable the padding of conv
134 padding = 0

Callers 5

__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected