MCPcopy Create free account
hub / github.com/alinlab/SelfPatch / MixVisionTransformer

Class MixVisionTransformer

segmentation/backbones/mit.py:246–405  ·  view source on GitHub ↗

The backbone of Segformer. This backbone is the implementation of `SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers `_. Args: in_channels (int): Number of input channels. Default: 3. embed_dims (int

Source from the content-addressed store, hash-verified

244
245@BACKBONES.register_module()
246class MixVisionTransformer(BaseModule):
247 """The backbone of Segformer.
248
249 This backbone is the implementation of `SegFormer: Simple and
250 Efficient Design for Semantic Segmentation with
251 Transformers <https://arxiv.org/abs/2105.15203>`_.
252
253 Args:
254 in_channels (int): Number of input channels. Default: 3.
255 embed_dims (int): Embedding dimension. Default: 768.
256 num_stags (int): The num of stages. Default: 4.
257 num_layers (Sequence[int]): The layer number of each transformer encode
258 layer. Default: [3, 4, 6, 3].
259 num_heads (Sequence[int]): The attention heads of each transformer
260 encode layer. Default: [1, 2, 4, 8].
261 patch_sizes (Sequence[int]): The patch_size of each overlapped patch
262 embedding. Default: [7, 3, 3, 3].
263 strides (Sequence[int]): The stride of each overlapped patch embedding.
264 Default: [4, 2, 2, 2].
265 sr_ratios (Sequence[int]): The spatial reduction rate of each
266 transformer encode layer. Default: [8, 4, 2, 1].
267 out_indices (Sequence[int] | int): Output from which stages.
268 Default: (0, 1, 2, 3).
269 mlp_ratio (int): ratio of mlp hidden dim to embedding dim.
270 Default: 4.
271 qkv_bias (bool): Enable bias for qkv if True. Default: True.
272 drop_rate (float): Probability of an element to be zeroed.
273 Default 0.0
274 attn_drop_rate (float): The drop out rate for attention layer.
275 Default 0.0
276 drop_path_rate (float): stochastic depth rate. Default 0.0
277 norm_cfg (dict): Config dict for normalization layer.
278 Default: dict(type='LN')
279 act_cfg (dict): The activation config for FFNs.
280 Defalut: dict(type='GELU').
281 pretrained (str, optional): model pretrained path. Default: None.
282 init_cfg (dict or list[dict], optional): Initialization config dict.
283 Default: None.
284 """
285
286 def __init__(self,
287 in_channels=3,
288 embed_dims=64,
289 num_stages=4,
290 num_layers=[3, 4, 6, 3],
291 num_heads=[1, 2, 4, 8],
292 patch_sizes=[7, 3, 3, 3],
293 strides=[4, 2, 2, 2],
294 sr_ratios=[8, 4, 2, 1],
295 out_indices=(0, 1, 2, 3),
296 mlp_ratio=4,
297 qkv_bias=True,
298 drop_rate=0.,
299 attn_drop_rate=0.,
300 drop_path_rate=0.,
301 act_cfg=dict(type='GELU'),
302 norm_cfg=dict(type='LN', eps=1e-6),
303 pretrained=None,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected