swiftformer
mindnlp.transformers.models.swiftformer.configuration_swiftformer
¶
SwiftFormer model configuration
mindnlp.transformers.models.swiftformer.configuration_swiftformer.SwiftFormerConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [SwiftFormerModel]. It is used to instantiate an
SwiftFormer model according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield a similar configuration to that of the SwiftFormer
MBZUAI/swiftformer-xs architecture.
Configuration objects inherit from [PretrainedConfig] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig] for more information.
| PARAMETER | DESCRIPTION |
|---|---|
image_size
|
The size (resolution) of each image
TYPE:
|
num_channels
|
The number of input channels
TYPE:
|
depths
|
Depth of each stage
TYPE:
|
embed_dims
|
The embedding dimension at each stage
TYPE:
|
mlp_ratio
|
Ratio of size of the hidden dimensionality of an MLP to the dimensionality of its input.
TYPE:
|
downsamples
|
Whether or not to downsample inputs between two stages.
TYPE:
|
hidden_act
|
The non-linear activation function (string).
TYPE:
|
down_patch_size
|
The size of patches in downsampling layers.
TYPE:
|
down_stride
|
The stride of convolution kernels in downsampling layers.
TYPE:
|
down_pad
|
Padding in downsampling layers.
TYPE:
|
drop_path_rate
|
Rate at which to increase dropout probability in DropPath.
TYPE:
|
drop_mlp_rate
|
Dropout rate for the MLP component of SwiftFormer.
TYPE:
|
drop_conv_encoder_rate
|
Dropout rate for the ConvEncoder component of SwiftFormer.
TYPE:
|
use_layer_scale
|
Whether to scale outputs from token mixers.
TYPE:
|
layer_scale_init_value
|
Factor by which outputs from token mixers are scaled.
TYPE:
|
batch_norm_eps
|
The epsilon used by the batch normalization layers.
TYPE:
|
Example
>>> from transformers import SwiftFormerConfig, SwiftFormerModel
...
>>> # Initializing a SwiftFormer swiftformer-base-patch16-224 style configuration
>>> configuration = SwiftFormerConfig()
...
>>> # Initializing a model (with random weights) from the swiftformer-base-patch16-224 style configuration
>>> model = SwiftFormerModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp\transformers\models\swiftformer\configuration_swiftformer.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer
¶
MindSpore SwiftFormer model.
mindnlp.transformers.models.swiftformer.modeling_swiftformer.SwiftFormerConvEncoder
¶
Bases: Module
SwiftFormerConvEncoder with 3*3 and 1*1 convolutions.
Input: tensor of shape [batch_size, channels, height, width]
Output: tensor of shape [batch_size, channels, height, width]
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer.SwiftFormerDropPath
¶
Bases: Module
Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
98 99 100 101 102 103 104 105 106 107 108 109 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer.SwiftFormerEfficientAdditiveAttention
¶
Bases: Module
Efficient Additive Attention module for SwiftFormer.
Input: tensor of shape [batch_size, channels, height, width]
Output: tensor of shape [batch_size, channels, height, width]
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer.SwiftFormerEmbeddings
¶
Bases: Module
Embeddings layer consisting of a single 2D convolutional and batch normalization layer.
Input: tensor of shape [batch_size, channels, height, width]
Output: tensor of shape [batch_size, channels, height/stride, width/stride]
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer.SwiftFormerEncoderBlock
¶
Bases: Module
SwiftFormer Encoder Block for SwiftFormer. It consists of (1) Local representation module, (2) SwiftFormerEfficientAdditiveAttention, and (3) MLP block.
Input: tensor of shape [batch_size, channels, height, width]
Output: tensor of shape [batch_size, channels,height, width]
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer.SwiftFormerForImageClassification
¶
Bases: SwiftFormerPreTrainedModel
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer.SwiftFormerForImageClassification.forward(pixel_values=None, labels=None, output_hidden_states=None, return_dict=None)
¶
labels (mindspore.Tensor of shape (batch_size,), optional):
Labels for computing the image classification/regression loss. Indices should be in [0, ...,
config.num_labels - 1]. If config.num_labels == 1 a regression loss is computed (Mean-Square loss), If
config.num_labels > 1 a classification loss is computed (Cross-Entropy).
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer.SwiftFormerLocalRepresentation
¶
Bases: Module
Local Representation module for SwiftFormer that is implemented by 3*3 depth-wise and point-wise convolutions.
Input: tensor of shape [batch_size, channels, height, width]
Output: tensor of shape [batch_size, channels, height, width]
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer.SwiftFormerMlp
¶
Bases: Module
MLP layer with 1*1 convolutions.
Input: tensor of shape [batch_size, channels, height, width]
Output: tensor of shape [batch_size, channels, height, width]
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer.SwiftFormerPatchEmbedding
¶
Bases: Module
Patch Embedding Layer constructed of two 2D convolutional layers.
Input: tensor of shape [batch_size, in_channels, height, width]
Output: tensor of shape [batch_size, out_channels, height/4, width/4]
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer.SwiftFormerPreTrainedModel
¶
Bases: PreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer.SwiftFormerStage
¶
Bases: Module
A Swiftformer stage consisting of a series of SwiftFormerConvEncoder blocks and a final
SwiftFormerEncoderBlock.
Input: tensor in shape [batch_size, channels, height, width]
Output: tensor in shape [batch_size, channels, height, width]
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
mindnlp.transformers.models.swiftformer.modeling_swiftformer.drop_path(input, drop_prob=0.0, training=False)
¶
Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
Comment by Ross Wightman: This is the same as the DropConnect impl I created for EfficientNet, etc networks, however, the original name is misleading as 'Drop Connect' is a different form of dropout in a separate paper... See discussion: https://github.com/tensorflow/tpu/issues/494#issuecomment-532968956 ... I've opted for changing the layer and argument names to 'drop path' rather than mix DropConnect as a layer name and use 'survival rate' as the argument.
Source code in mindnlp\transformers\models\swiftformer\modeling_swiftformer.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |