poolformer
mindnlp.transformers.models.poolformer.configuration_poolformer
¶
PoolFormer model configuration
mindnlp.transformers.models.poolformer.configuration_poolformer.PoolFormerConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of [PoolFormerModel
]. It is used to instantiate a
PoolFormer 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 PoolFormer
sail/poolformer_s12 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 |
---|---|
num_channels |
The number of channels in the input image.
TYPE:
|
patch_size |
The size of the input patch.
TYPE:
|
stride |
The stride of the input patch.
TYPE:
|
pool_size |
The size of the pooling window.
TYPE:
|
mlp_ratio |
The ratio of the number of channels in the output of the MLP to the number of channels in the input.
TYPE:
|
depths |
The depth of each encoder block.
TYPE:
|
hidden_sizes |
The hidden sizes of each encoder block.
TYPE:
|
patch_sizes |
The size of the input patch for each encoder block.
TYPE:
|
strides |
The stride of the input patch for each encoder block.
TYPE:
|
padding |
The padding of the input patch for each encoder block.
TYPE:
|
num_encoder_blocks |
The number of encoder blocks.
TYPE:
|
drop_path_rate |
The dropout rate for the dropout layers.
TYPE:
|
hidden_act |
The activation function for the hidden layers.
TYPE:
|
use_layer_scale |
Whether to use layer scale.
TYPE:
|
layer_scale_init_value |
The initial value for the layer scale.
TYPE:
|
initializer_range |
The initializer range for the weights.
TYPE:
|
Example
>>> from transformers import PoolFormerConfig, PoolFormerModel
...
>>> # Initializing a PoolFormer sail/poolformer_s12 style configuration
>>> configuration = PoolFormerConfig()
...
>>> # Initializing a model (with random weights) from the sail/poolformer_s12 style configuration
>>> model = PoolFormerModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/poolformer/configuration_poolformer.py
20 21 22 23 24 25 26 27 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 |
|
mindnlp.transformers.models.poolformer.feature_extraction_poolformer
¶
Feature extractor class for PoolFormer.
mindnlp.transformers.models.poolformer.image_processing_poolformer
¶
Image processor class for PoolFormer.
mindnlp.transformers.models.poolformer.image_processing_poolformer.PoolFormerImageProcessor
¶
Bases: BaseImageProcessor
Constructs a PoolFormer image processor.
PARAMETER | DESCRIPTION |
---|---|
do_resize |
Whether to resize the image's (height, width) dimensions to the specified
TYPE:
|
size |
224}
If crop_pct is set:
TYPE:
|
crop_pct |
Percentage of the image to crop from the center. Can be overridden by
TYPE:
|
resample |
Resampling filter to use if resizing the image. Can be overridden by
TYPE:
|
do_center_crop |
Whether to center crop the image. If the input size is smaller than
TYPE:
|
crop_size |
224, "width": 224}
TYPE:
|
rescale_factor |
Scale factor to use if rescaling the image. Can be overridden by the
TYPE:
|
do_rescale |
Whether to rescale the image by the specified scale
TYPE:
|
do_normalize |
Controls 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/poolformer/image_processing_poolformer.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 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 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 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
|
mindnlp.transformers.models.poolformer.image_processing_poolformer.PoolFormerImageProcessor.preprocess(images, do_resize=None, size=None, crop_pct=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 |
Size of the image after applying resize.
TYPE:
|
crop_pct |
Percentage of the image to crop. Only has an effect if
TYPE:
|
resample |
Resampling filter to use if resizing the image. This can be one of the enum
TYPE:
|
do_center_crop |
Whether to center crop the image.
TYPE:
|
crop_size |
Size of the image after applying center crop.
TYPE:
|
do_rescale |
Whether to rescale the image values between [0 - 1].
TYPE:
|
rescale_factor |
Rescale factor to rescale the image by if
TYPE:
|
do_normalize |
Whether to normalize the image.
TYPE:
|
image_mean |
Image mean.
TYPE:
|
image_std |
Image standard deviation.
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/poolformer/image_processing_poolformer.py
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 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 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
|
mindnlp.transformers.models.poolformer.image_processing_poolformer.PoolFormerImageProcessor.resize(image, size, crop_pct=None, resample=PILImageResampling.BICUBIC, data_format=None, input_data_format=None, **kwargs)
¶
Resize an image.
-
If crop_pct is unset:
- size is
{"height": h, "width": w}
: the image is resized to(h, w)
. - size is
{"shortest_edge": s}
: the shortest edge of the image is resized to s whilst maintaining the aspect ratio.
- size is
-
if crop_pct is set:
- size is
{"height": h, "width": w}
: the image is resized to(int(floor(h/crop_pct)), int(floor(w/crop_pct)))
- size is
{"height": c, "width": c}
: the shortest edge of the image is resized toint(floor(c/crop_pct)
whilst maintaining the aspect ratio. - size is
{"shortest_edge": c}
: the shortest edge of the image is resized toint(floor(c/crop_pct)
whilst maintaining the aspect ratio.
- size is
PARAMETER | DESCRIPTION |
---|---|
image |
Image to resize.
TYPE:
|
size |
Size of the output image.
TYPE:
|
crop_pct |
Percentage of the image that will be cropped from the center. If set, the image is resized
TYPE:
|
resample |
Resampling filter to use when resizing the image.
TYPE:
|
data_format |
The channel dimension format of the image. If not provided, it will be the same as the input image.
TYPE:
|
input_data_format |
The channel dimension format of the input image. If not provided, it will be inferred.
TYPE:
|
Source code in mindnlp/transformers/models/poolformer/image_processing_poolformer.py
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 |
|
mindnlp.transformers.models.poolformer.modeling_poolformer
¶
MindSpore PoolFormer model.
mindnlp.transformers.models.poolformer.modeling_poolformer.PoolFormerDropPath
¶
Bases: Module
Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
Source code in mindnlp/transformers/models/poolformer/modeling_poolformer.py
70 71 72 73 74 75 76 77 78 79 80 81 |
|
mindnlp.transformers.models.poolformer.modeling_poolformer.PoolFormerEmbeddings
¶
Bases: Module
Construct Patch Embeddings.
Source code in mindnlp/transformers/models/poolformer/modeling_poolformer.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
mindnlp.transformers.models.poolformer.modeling_poolformer.PoolFormerForImageClassification
¶
Bases: PoolFormerPreTrainedModel
Source code in mindnlp/transformers/models/poolformer/modeling_poolformer.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
|
mindnlp.transformers.models.poolformer.modeling_poolformer.PoolFormerForImageClassification.forward(pixel_values=None, labels=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/poolformer/modeling_poolformer.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
|
mindnlp.transformers.models.poolformer.modeling_poolformer.PoolFormerGroupNorm
¶
Bases: GroupNorm
Group Normalization with 1 group. Input: tensor in shape [B, C, H, W]
Source code in mindnlp/transformers/models/poolformer/modeling_poolformer.py
108 109 110 111 112 113 114 |
|
mindnlp.transformers.models.poolformer.modeling_poolformer.PoolFormerLayer
¶
Bases: Module
This corresponds to the 'PoolFormerBlock' class in the original implementation.
Source code in mindnlp/transformers/models/poolformer/modeling_poolformer.py
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 |
|
mindnlp.transformers.models.poolformer.modeling_poolformer.PoolFormerPreTrainedModel
¶
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/poolformer/modeling_poolformer.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
mindnlp.transformers.models.poolformer.modeling_poolformer.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/poolformer/modeling_poolformer.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|