MCPcopy Create free account
hub / github.com/UX-Decoder/Semantic-SAM / FocalNet

Class FocalNet

semantic_sam/backbone/focal_dw.py:434–692  ·  view source on GitHub ↗

FocalNet backbone. Args: pretrain_img_size (int): Input image size for training the pretrained model, used in absolute postion embedding. Default 224. patch_size (int | tuple(int)): Patch size. Default: 4. in_chans (int): Number of input image channels. Defa

Source from the content-addressed store, hash-verified

432
433
434class FocalNet(nn.Module):
435 """ FocalNet backbone.
436
437 Args:
438 pretrain_img_size (int): Input image size for training the pretrained model,
439 used in absolute postion embedding. Default 224.
440 patch_size (int | tuple(int)): Patch size. Default: 4.
441 in_chans (int): Number of input image channels. Default: 3.
442 embed_dim (int): Number of linear projection output channels. Default: 96.
443 depths (tuple[int]): Depths of each Swin Transformer stage.
444 mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4.
445 drop_rate (float): Dropout rate.
446 drop_path_rate (float): Stochastic depth rate. Default: 0.2.
447 norm_layer (nn.Module): Normalization layer. Default: nn.LayerNorm.
448 patch_norm (bool): If True, add normalization after patch embedding. Default: True.
449 out_indices (Sequence[int]): Output from which stages.
450 frozen_stages (int): Stages to be frozen (stop grad and set eval mode).
451 -1 means not freezing any parameters.
452 focal_levels (Sequence[int]): Number of focal levels at four stages
453 focal_windows (Sequence[int]): Focal window sizes at first focal level at four stages
454 use_conv_embed (bool): Whether use overlapped convolution for patch embedding
455 use_checkpoint (bool): Whether to use checkpointing to save memory. Default: False.
456 """
457
458 def __init__(self,
459 pretrain_img_size=1600,
460 patch_size=4,
461 in_chans=3,
462 embed_dim=96,
463 depths=[2, 2, 6, 2],
464 mlp_ratio=4.,
465 drop_rate=0.,
466 drop_path_rate=0.2,
467 norm_layer=nn.LayerNorm,
468 patch_norm=True,
469 out_indices=[0, 1, 2, 3],
470 frozen_stages=-1,
471 focal_levels=[2,2,2,2],
472 focal_windows=[9,9,9,9],
473 use_pre_norms=[False, False, False, False],
474 use_conv_embed=False,
475 use_postln=False,
476 use_postln_in_modulation=False,
477 scaling_modulator=False,
478 use_layerscale=False,
479 use_checkpoint=False,
480 ):
481 super().__init__()
482
483 self.pretrain_img_size = pretrain_img_size
484 self.num_layers = len(depths)
485 self.embed_dim = embed_dim
486 self.patch_norm = patch_norm
487 self.out_indices = out_indices
488 self.frozen_stages = frozen_stages
489
490 # split image into non-overlapping patches
491 self.patch_embed = PatchEmbed(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected