efficientformer
mindnlp.transformers.models.efficientformer.configuration_efficientformer
¶
EfficientFormer model configuration
mindnlp.transformers.models.efficientformer.configuration_efficientformer.EfficientFormerConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of an [EfficientFormerModel
]. It is used to
instantiate an EfficientFormer 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 EfficientFormer
snap-research/efficientformer-l1 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 |
---|---|
dim |
Number of channels in Meta3D layers
TYPE:
|
key_dim |
The size of the key in meta3D block.
TYPE:
|
attention_ratio |
Ratio of the dimension of the query and value to the dimension of the key in MSHA block
TYPE:
|
num_hidden_layers |
Number of hidden layers in the Transformer encoder.
TYPE:
|
num_attention_heads |
Number of attention heads for each attention layer in the 3D MetaBlock.
TYPE:
|
mlp_expansion_ratio |
Ratio of size of the hidden dimensionality of an MLP to the dimensionality of its input.
TYPE:
|
hidden_dropout_prob |
The dropout probability for all fully connected layers in the embeddings and encoder.
TYPE:
|
patch_size |
The size (resolution) of each patch.
TYPE:
|
num_channels |
The number of input channels.
TYPE:
|
pool_size |
Kernel size of pooling layers.
TYPE:
|
downsample_patch_size |
The size of patches in downsampling layers.
TYPE:
|
downsample_stride |
The stride of convolution kernels in downsampling layers.
TYPE:
|
downsample_pad |
Padding in downsampling layers.
TYPE:
|
drop_path_rate |
Rate at which to increase dropout probability in DropPath.
TYPE:
|
num_meta3d_blocks |
The number of 3D MetaBlocks in the last stage.
TYPE:
|
distillation |
Whether to add a distillation head.
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:
|
hidden_act |
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
initializer_range |
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
layer_norm_eps |
The epsilon used by the layer normalization layers.
TYPE:
|
image_size |
The size (resolution) of each image.
TYPE:
|
Example
>>> from transformers import EfficientFormerConfig, EfficientFormerModel
...
>>> # Initializing a EfficientFormer efficientformer-l1 style configuration
>>> configuration = EfficientFormerConfig()
...
>>> # Initializing a EfficientFormerModel (with random weights) from the efficientformer-l3 style configuration
>>> model = EfficientFormerModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/efficientformer/configuration_efficientformer.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 142 143 144 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 |
|
mindnlp.transformers.models.efficientformer.image_processing_efficientformer
¶
Image processor class for EfficientFormer.
mindnlp.transformers.models.efficientformer.image_processing_efficientformer.EfficientFormerImageProcessor
¶
Bases: BaseImageProcessor
Constructs a EfficientFormer image processor.
PARAMETER | DESCRIPTION |
---|---|
do_resize |
Whether to resize the image's (height, width) dimensions to the specified
TYPE:
|
size |
224, "width": 224}
TYPE:
|
resample |
Resampling filter to use if resizing the image. Can be overridden by the
TYPE:
|
do_center_crop |
Whether to center crop the image to the specified
TYPE:
|
crop_size |
Size of the output image after applying
TYPE:
|
do_rescale |
Whether to rescale the image by the specified scale
TYPE:
|
rescale_factor |
Scale factor to use if rescaling the image. Can be overridden by the
TYPE:
|
do_normalize |
Whether to normalize the image. Can be overridden by the
TYPE:
|
image_mean |
Mean to use if normalizing the image. This is a float or list of floats the length of the number of
channels in the image. Can be overridden by the
TYPE:
|
image_std |
Standard deviation to use if normalizing the image. This is a float or list of floats the length of the
number of channels in the image. Can be overridden by the
TYPE:
|
Source code in mindnlp/transformers/models/efficientformer/image_processing_efficientformer.py
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 142 143 144 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 175 176 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 204 205 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 244 245 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 275 276 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 318 319 320 321 322 323 324 |
|
mindnlp.transformers.models.efficientformer.image_processing_efficientformer.EfficientFormerImageProcessor.preprocess(images, do_resize=None, size=None, resample=None, do_center_crop=None, crop_size=None, do_rescale=None, rescale_factor=None, do_normalize=None, image_mean=None, image_std=None, return_tensors=None, data_format=ChannelDimension.FIRST, input_data_format=None, **kwargs)
¶
Preprocess an image or batch of images.
PARAMETER | DESCRIPTION |
---|---|
images |
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set
TYPE:
|
do_resize |
Whether to resize the image.
TYPE:
|
size |
Dictionary in the format
TYPE:
|
resample |
TYPE:
|
do_center_crop |
Whether to center crop the image.
TYPE:
|
do_rescale |
Whether to rescale the image values between [0 - 1].
TYPE:
|
rescale_factor |
Rescale factor to rescale the image by if
TYPE:
|
crop_size |
Size of the center crop. Only has an effect if
TYPE:
|
do_normalize |
Whether to normalize the image.
TYPE:
|
image_mean |
Image mean to use if
TYPE:
|
image_std |
Image standard deviation to use if
TYPE:
|
return_tensors |
The type of tensors to return. Can be one of:
TYPE:
|
data_format |
The channel dimension format for the output image. Can be one of:
TYPE:
|
input_data_format |
The channel dimension format for the input image. If unset, the channel dimension format is inferred from the input image. Can be one of:
TYPE:
|
Source code in mindnlp/transformers/models/efficientformer/image_processing_efficientformer.py
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 204 205 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 244 245 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 275 276 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 318 319 320 321 322 323 324 |
|
mindnlp.transformers.models.efficientformer.image_processing_efficientformer.EfficientFormerImageProcessor.resize(image, size, resample=PILImageResampling.BILINEAR, data_format=None, input_data_format=None, **kwargs)
¶
Resize an image to (size["height"], size["width"])
.
PARAMETER | DESCRIPTION |
---|---|
image |
Image to resize.
TYPE:
|
size |
Dictionary in the format
TYPE:
|
resample |
TYPE:
|
data_format |
The channel dimension format for the output image. If unset, the channel dimension format of the input image is used. Can be one of:
TYPE:
|
input_data_format |
The channel dimension format of the input image. If not provided, it will be inferred.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
|
Source code in mindnlp/transformers/models/efficientformer/image_processing_efficientformer.py
132 133 134 135 136 137 138 139 140 141 142 143 144 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 175 176 |
|
mindnlp.transformers.models.efficientformer.modeling_efficientformer
¶
MindSpore EfficientFormer model.
mindnlp.transformers.models.efficientformer.modeling_efficientformer.EfficientFormerDropPath
¶
Bases: Module
Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
Source code in mindnlp/transformers/models/efficientformer/modeling_efficientformer.py
253 254 255 256 257 258 259 260 261 262 263 264 |
|
mindnlp.transformers.models.efficientformer.modeling_efficientformer.EfficientFormerForImageClassification
¶
Bases: EfficientFormerPreTrainedModel
Source code in mindnlp/transformers/models/efficientformer/modeling_efficientformer.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
|
mindnlp.transformers.models.efficientformer.modeling_efficientformer.EfficientFormerForImageClassification.forward(pixel_values=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the image classification/regression loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/efficientformer/modeling_efficientformer.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
|
mindnlp.transformers.models.efficientformer.modeling_efficientformer.EfficientFormerForImageClassificationWithTeacherOutput
dataclass
¶
Bases: ModelOutput
Output type of [EfficientFormerForImageClassificationWithTeacher
].
PARAMETER | DESCRIPTION |
---|---|
logits |
Prediction scores as the average of the cls_logits and distillation logits.
TYPE:
|
cls_logits |
Prediction scores of the classification head (i.e. the linear layer on top of the final hidden state of the class token).
TYPE:
|
distillation_logits |
Prediction scores of the distillation head (i.e. the linear layer on top of the final hidden state of the distillation token).
TYPE:
|
hidden_states |
Tuple of
TYPE:
|
attentions |
Tuple of
TYPE:
|
Source code in mindnlp/transformers/models/efficientformer/modeling_efficientformer.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
|
mindnlp.transformers.models.efficientformer.modeling_efficientformer.EfficientFormerPatchEmbeddings
¶
Bases: Module
This class performs downsampling between two stages. For the input tensor with the shape [batch_size, num_channels, height, width] it produces output tensor with the shape [batch_size, num_channels, height/stride, width/stride]
Source code in mindnlp/transformers/models/efficientformer/modeling_efficientformer.py
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 |
|
mindnlp.transformers.models.efficientformer.modeling_efficientformer.EfficientFormerPreTrainedModel
¶
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/efficientformer/modeling_efficientformer.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
|
mindnlp.transformers.models.efficientformer.modeling_efficientformer.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/efficientformer/modeling_efficientformer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|