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
| 338 | |
| 339 | |
| 340 | class FocalNet(nn.Module): |
| 341 | """ FocalNet backbone. |
| 342 | |
| 343 | Args: |
| 344 | pretrain_img_size (int): Input image size for training the pretrained model, |
| 345 | used in absolute postion embedding. Default 224. |
| 346 | patch_size (int | tuple(int)): Patch size. Default: 4. |
| 347 | in_chans (int): Number of input image channels. Default: 3. |
| 348 | embed_dim (int): Number of linear projection output channels. Default: 96. |
| 349 | depths (tuple[int]): Depths of each Swin Transformer stage. |
| 350 | mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4. |
| 351 | drop_rate (float): Dropout rate. |
| 352 | drop_path_rate (float): Stochastic depth rate. Default: 0.2. |
| 353 | norm_layer (nn.Module): Normalization layer. Default: nn.LayerNorm. |
| 354 | patch_norm (bool): If True, add normalization after patch embedding. Default: True. |
| 355 | out_indices (Sequence[int]): Output from which stages. |
| 356 | frozen_stages (int): Stages to be frozen (stop grad and set eval mode). |
| 357 | -1 means not freezing any parameters. |
| 358 | focal_levels (Sequence[int]): Number of focal levels at four stages |
| 359 | focal_windows (Sequence[int]): Focal window sizes at first focal level at four stages |
| 360 | use_conv_embed (bool): Whether use overlapped convolution for patch embedding |
| 361 | use_checkpoint (bool): Whether to use checkpointing to save memory. Default: False. |
| 362 | """ |
| 363 | |
| 364 | def __init__(self, |
| 365 | pretrain_img_size=1600, |
| 366 | patch_size=4, |
| 367 | in_chans=3, |
| 368 | embed_dim=96, |
| 369 | depths=[2, 2, 6, 2], |
| 370 | mlp_ratio=4., |
| 371 | drop_rate=0., |
| 372 | drop_path_rate=0.2, |
| 373 | norm_layer=nn.LayerNorm, |
| 374 | patch_norm=True, |
| 375 | out_indices=[0, 1, 2, 3], |
| 376 | frozen_stages=-1, |
| 377 | focal_levels=[2,2,2,2], |
| 378 | focal_windows=[9,9,9,9], |
| 379 | use_conv_embed=False, |
| 380 | use_postln=False, |
| 381 | use_postln_in_modulation=False, |
| 382 | scaling_modulator=False, |
| 383 | use_layerscale=False, |
| 384 | use_checkpoint=False, |
| 385 | ): |
| 386 | super().__init__() |
| 387 | |
| 388 | self.pretrain_img_size = pretrain_img_size |
| 389 | self.num_layers = len(depths) |
| 390 | self.embed_dim = embed_dim |
| 391 | self.patch_norm = patch_norm |
| 392 | self.out_indices = out_indices |
| 393 | self.frozen_stages = frozen_stages |
| 394 | |
| 395 | # split image into non-overlapping patches |
| 396 | self.patch_embed = PatchEmbed( |
| 397 | patch_size=patch_size, in_chans=in_chans, embed_dim=embed_dim, |
nothing calls this directly
no outgoing calls
no test coverage detected