(self,
img_size=32,
patch_size=2,
in_chans=3,
num_classes=10,
embed_dim=96,
depths=[2, 2, 6, 2],
mlp_ratio=4.,
drop_rate=0.,
drop_path_rate=0.1,
norm_layer=nn.LayerNorm,
patch_norm=True,
use_checkpoint=False,
focal_levels=[2, 2, 2, 2],
focal_windows=[3, 3, 3, 3],
use_conv_embed=False,
use_layerscale=False,
layerscale_value=1e-4,
use_postln=False,
use_postln_in_modulation=False,
normalize_modulator=False,
**kwargs)
| 398 | """ |
| 399 | |
| 400 | def __init__(self, |
| 401 | img_size=32, |
| 402 | patch_size=2, |
| 403 | in_chans=3, |
| 404 | num_classes=10, |
| 405 | embed_dim=96, |
| 406 | depths=[2, 2, 6, 2], |
| 407 | mlp_ratio=4., |
| 408 | drop_rate=0., |
| 409 | drop_path_rate=0.1, |
| 410 | norm_layer=nn.LayerNorm, |
| 411 | patch_norm=True, |
| 412 | use_checkpoint=False, |
| 413 | focal_levels=[2, 2, 2, 2], |
| 414 | focal_windows=[3, 3, 3, 3], |
| 415 | use_conv_embed=False, |
| 416 | use_layerscale=False, |
| 417 | layerscale_value=1e-4, |
| 418 | use_postln=False, |
| 419 | use_postln_in_modulation=False, |
| 420 | normalize_modulator=False, |
| 421 | **kwargs): |
| 422 | super().__init__() |
| 423 | |
| 424 | self.num_layers = len(depths) |
| 425 | embed_dim = [embed_dim * (2 ** i) for i in range(self.num_layers)] |
| 426 | |
| 427 | self.num_classes = num_classes |
| 428 | self.embed_dim = embed_dim |
| 429 | self.patch_norm = patch_norm |
| 430 | self.num_features = embed_dim[-1] |
| 431 | self.mlp_ratio = mlp_ratio |
| 432 | |
| 433 | # split image into patches using either non-overlapped embedding or overlapped embedding |
| 434 | self.patch_embed = PatchEmbed( |
| 435 | img_size=to_2tuple(img_size), |
| 436 | patch_size=patch_size, |
| 437 | in_chans=in_chans, |
| 438 | embed_dim=embed_dim[0], |
| 439 | use_conv_embed=use_conv_embed, |
| 440 | norm_layer=norm_layer if self.patch_norm else None, |
| 441 | is_stem=True) |
| 442 | |
| 443 | num_patches = self.patch_embed.num_patches |
| 444 | patches_resolution = self.patch_embed.patches_resolution |
| 445 | self.patches_resolution = patches_resolution |
| 446 | self.pos_drop = nn.Dropout(p=drop_rate) |
| 447 | |
| 448 | # stochastic depth |
| 449 | dpr = [x.item() for x in torch.linspace(0, drop_path_rate, sum(depths))] # stochastic depth decay rule |
| 450 | |
| 451 | # build layers |
| 452 | self.layers = nn.ModuleList() |
| 453 | for i_layer in range(self.num_layers): |
| 454 | layer = BasicLayer(dim=embed_dim[i_layer], |
| 455 | out_dim=embed_dim[i_layer + 1] if (i_layer < self.num_layers - 1) else None, |
| 456 | input_resolution=(patches_resolution[0] // (2 ** i_layer), |
| 457 | patches_resolution[1] // (2 ** i_layer)), |
nothing calls this directly
no test coverage detected