convnext
mindnlp.transformers.models.convnext.configuration_convnext
¶
ConvNeXT model configuration
mindnlp.transformers.models.convnext.configuration_convnext.ConvNextConfig
¶
Bases: BackboneConfigMixin
, PretrainedConfig
This is the configuration class to store the configuration of a [ConvNextModel
]. It is used to instantiate an
ConvNeXT 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 ConvNeXT
facebook/convnext-tiny-224 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 input channels.
TYPE:
|
patch_size |
Patch size to use in the patch embedding layer.
TYPE:
|
num_stages |
The number of stages in the model.
TYPE:
|
hidden_sizes |
Dimensionality (hidden size) at each stage.
TYPE:
|
depths |
Depth (number of blocks) for each stage.
TYPE:
|
hidden_act |
The non-linear activation function (function or string) in each block. 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:
|
layer_scale_init_value |
The initial value for the layer scale.
TYPE:
|
drop_path_rate |
The drop rate for stochastic depth.
TYPE:
|
out_features |
If used as backbone, list of features to output. Can be any of
TYPE:
|
out_indices |
If used as backbone, list of indices of features to output. Can be any of 0, 1, 2, etc. (depending on how
many stages the model has). If unset and
TYPE:
|
Example
>>> from transformers import ConvNextConfig, ConvNextModel
...
>>> # Initializing a ConvNext convnext-tiny-224 style configuration
>>> configuration = ConvNextConfig()
...
>>> # Initializing a model (with random weights) from the convnext-tiny-224 style configuration
>>> model = ConvNextModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/convnext/configuration_convnext.py
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 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.convnext.configuration_convnext.ConvNextConfig.__init__(num_channels=3, patch_size=4, num_stages=4, hidden_sizes=None, depths=None, hidden_act='gelu', initializer_range=0.02, layer_norm_eps=1e-12, layer_scale_init_value=1e-06, drop_path_rate=0.0, image_size=224, out_features=None, out_indices=None, **kwargs)
¶
Initialize a ConvNextConfig object.
PARAMETER | DESCRIPTION |
---|---|
num_channels |
Number of input channels. Default is 3.
TYPE:
|
patch_size |
Patch size used in the model. Default is 4.
TYPE:
|
num_stages |
Number of stages in the model. Default is 4.
TYPE:
|
hidden_sizes |
List of hidden layer sizes for each stage. Default is [96, 192, 384, 768].
TYPE:
|
depths |
List of depths for each stage. Default is [3, 3, 9, 3].
TYPE:
|
hidden_act |
Activation function for hidden layers. Default is 'gelu'.
TYPE:
|
initializer_range |
Range for weight initialization. Default is 0.02.
TYPE:
|
layer_norm_eps |
Epsilon value for layer normalization. Default is 1e-12.
TYPE:
|
layer_scale_init_value |
Initial value for layer scale. Default is 1e-06.
TYPE:
|
drop_path_rate |
Rate of drop path regularization. Default is 0.0.
TYPE:
|
image_size |
Size of input images. Default is 224.
TYPE:
|
out_features |
List of output features.
TYPE:
|
out_indices |
List of output indices.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/convnext/configuration_convnext.py
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.convnext.modeling_convnext
¶
MindSpore ConvNext model.
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextBackbone
¶
Bases: ConvNextPreTrainedModel
, BackboneMixin
This class represents the ConvNext backbone used in a ConvNext model for image processing tasks. It inherits functionality from ConvNextPreTrainedModel and BackboneMixin.
The ConvNextBackbone class initializes the backbone architecture with ConvNextEmbeddings and ConvNextEncoder components. It also sets up layer normalization for hidden states based on the specified configuration. The forward method processes input pixel values through the embeddings and encoder, optionally returning hidden states and feature maps. It handles the logic for outputting the desired information based on the configuration settings.
RETURNS | DESCRIPTION |
---|---|
BackboneOutput
|
A named tuple containing the feature maps and hidden states of the backbone. |
Example
>>> from transformers import AutoImageProcessor, AutoBackbone
>>> import torch
>>> from PIL import Image
>>> import requests
...
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
...
>>> processor = AutoImageProcessor.from_pretrained("facebook/convnext-tiny-224")
>>> model = AutoBackbone.from_pretrained("facebook/convnext-tiny-224")
...
>>> inputs = processor(image, return_tensors="pt")
>>> outputs = model(**inputs)
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextBackbone.__init__(config)
¶
Initializes an instance of the ConvNextBackbone class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
A configuration object containing the necessary parameters for initializing the backbone. It should have the following attributes:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextBackbone.forward(pixel_values, output_hidden_states=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
BackboneOutput
|
BackboneOutput |
Example
>>> from transformers import AutoImageProcessor, AutoBackbone
>>> import torch
>>> from PIL import Image
>>> import requests
...
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
...
>>> processor = AutoImageProcessor.from_pretrained("facebook/convnext-tiny-224")
>>> model = AutoBackbone.from_pretrained("facebook/convnext-tiny-224")
...
>>> inputs = processor(image, return_tensors="pt")
>>> outputs = model(**inputs)
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextDropPath
¶
Bases: Module
Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextDropPath.__init__(drop_prob=None)
¶
Initializes an instance of the ConvNextDropPath class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ConvNextDropPath class.
TYPE:
|
drop_prob |
The probability of dropping a connection during training. If not provided, defaults to None. Should be a float value between 0 and 1, inclusive.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextDropPath.extra_repr()
¶
Method to generate a string representation of the drop probability in the ConvNextDropPath class.
PARAMETER | DESCRIPTION |
---|---|
self |
ConvNextDropPath object. Represents the instance of the ConvNextDropPath class.
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representing the drop probability of the ConvNextDropPath object.
TYPE:
|
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextDropPath.forward(hidden_states)
¶
Construct a drop path operation on the hidden states.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ConvNextDropPath class.
TYPE:
|
hidden_states |
The input tensor of hidden states on which the drop path operation will be performed.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: The tensor resulting from applying the drop path operation on the input hidden states. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the drop probability is not within the valid range. |
TypeError
|
If the input hidden_states is not a valid tensor type. |
RuntimeError
|
If the operation fails due to an internal error. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextEmbeddings
¶
Bases: Module
This class is comparable to (and inspired by) the SwinEmbeddings class found in src/transformers/models/swin/modeling_swin.py.
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextEmbeddings.__init__(config)
¶
Initializes the ConvNextEmbeddings class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ConvNextEmbeddings class.
|
config |
An object containing the configuration parameters for the ConvNextEmbeddings class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextEmbeddings.forward(pixel_values)
¶
Constructs embeddings from the input pixel values using the ConvNextEmbeddings class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ConvNextEmbeddings class.
TYPE:
|
pixel_values |
A tensor containing pixel values with shape (batch_size, num_channels, height, width). The pixel values should align with the channel dimension specified in the configuration.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: A tensor representing the embeddings generated from the input pixel values. The embeddings have the same shape as the input pixel values. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the number of channels in the input pixel values does not match the configured number of channels. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
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.convnext.modeling_convnext.ConvNextEncoder
¶
Bases: Module
ConvNextEncoder is a Python class that represents an encoder for a Convolutional Neural Network (CNN) model.
This class inherits from the nn.Module class, which is a base class for all neural network layers in the MindSpore framework.
The ConvNextEncoder class initializes a list of stages, where each stage consists of a ConvNextStage module. The number of stages is defined by the config.num_stages attribute. Each stage performs convolutional operations with different parameters, such as input and output channels, stride, and depth. The drop_path_rates parameter specifies the drop path rates for each stage.
The forward method of the ConvNextEncoder class takes a tensor of hidden states as input and performs the forward pass through each stage. It optionally returns a tuple containing all hidden states at each stage, as specified by the output_hidden_states parameter. If return_dict is set to True, it returns an instance of the BaseModelOutputWithNoAttention class, which encapsulates the last hidden state and all hidden states.
Note that this docstring is generated based on the provided code, and the actual implementation may contain additional methods or attributes.
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
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 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextEncoder.__init__(config)
¶
Initializes an instance of the ConvNextEncoder class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ConvNextEncoder class.
TYPE:
|
config |
A configuration object containing various settings for the ConvNextEncoder.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextEncoder.forward(hidden_states, output_hidden_states=False, return_dict=True)
¶
Constructs the encoder for the ConvNext model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ConvNextEncoder class.
TYPE:
|
hidden_states |
The input hidden states to be processed by the encoder.
TYPE:
|
output_hidden_states |
Whether to output hidden states for each layer. Defaults to False.
TYPE:
|
return_dict |
Whether to return the output as a dictionary. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, BaseModelOutputWithNoAttention]
|
Union[Tuple, BaseModelOutputWithNoAttention]: The output value which can be a tuple of hidden states or BaseModelOutputWithNoAttention object. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextForImageClassification
¶
Bases: ConvNextPreTrainedModel
ConvNextForImageClassification
This class represents a Convolutional Neural Network (CNN) model for image classification using the ConvNext architecture. The model is designed for tasks such as single-label or multi-label classification and regression. It inherits from the ConvNextPreTrainedModel class.
ATTRIBUTE | DESCRIPTION |
---|---|
num_labels |
The number of labels in the classification task.
TYPE:
|
convnext |
The ConvNext model used for feature extraction.
TYPE:
|
classifier |
The classifier layer for predicting the final output.
TYPE:
|
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 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 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextForImageClassification.__init__(config)
¶
init
Initializes an instance of the ConvNextForImageClassification class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An instance of the configuration class containing the necessary parameters for model initialization.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
631 632 633 634 635 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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextForImageClassification.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/convnext/modeling_convnext.py
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextLayer
¶
Bases: Module
This corresponds to the Block
class in the original implementation.
There are two equivalent implementations: [DwConv, LayerNorm (channels_first), Conv, GELU,1x1 Conv]; all in (N, C, H, W) (2) [DwConv, Permute to (N, H, W, C), LayerNorm (channels_last), Linear, GELU, Linear]; Permute back
The authors used (2) as they find it slightly faster in PyTorch.
PARAMETER | DESCRIPTION |
---|---|
config |
Model configuration class.
TYPE:
|
dim |
Number of input channels.
TYPE:
|
drop_path |
Stochastic depth rate. Default: 0.0.
TYPE:
|
Source code in mindnlp/transformers/models/convnext/modeling_convnext.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 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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextLayer.__init__(config, dim, drop_path=0)
¶
Initializes the ConvNextLayer.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object containing configuration settings.
|
dim |
An integer representing the dimension for convolution operation.
|
drop_path |
A float representing the dropout probability for drop path regularization.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If config.hidden_act is not found in ACT2FN. |
TypeError
|
If config.layer_scale_init_value is not a positive number. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextLayer.forward(hidden_states)
¶
Construct method in the ConvNextLayer class.
PARAMETER | DESCRIPTION |
---|---|
self |
ConvNextLayer instance.
|
hidden_states |
The input hidden states tensor.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: The output tensor after applying the convolutional layer operations. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextLayerNorm
¶
Bases: Module
LayerNorm that supports two data formats: channels_last (default) or channels_first. The ordering of the dimensions in the inputs. channels_last corresponds to inputs with shape (batch_size, height, width, channels) while channels_first corresponds to inputs with shape (batch_size, channels, height, width).
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextLayerNorm.__init__(normalized_shape, eps=1e-06, data_format='channels_last')
¶
Initializes an instance of the ConvNextLayerNorm class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
normalized_shape |
The shape of the input tensor normalized over the specified axes.
TYPE:
|
eps |
A small value added to the denominator for numerical stability. Defaults to 1e-06.
TYPE:
|
data_format |
The format of the input data. Must be either 'channels_last' or 'channels_first'. Defaults to 'channels_last'.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
NotImplementedError
|
If the data format is not supported. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextLayerNorm.forward(x)
¶
Constructs the ConvNextLayerNorm.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ConvNextLayerNorm class.
TYPE:
|
x |
The input tensor to be normalized.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: The normalized tensor. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input tensor is not of type mindspore.Tensor. |
ValueError
|
If the data format is not 'channels_last' or 'channels_first'. |
ValueError
|
If the input tensor has an unsupported dtype. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextModel
¶
Bases: ConvNextPreTrainedModel
The ConvNextModel class represents a ConvNext model for image processing tasks. It inherits from ConvNextPreTrainedModel and includes methods for model initialization and forwardion.
The init method initializes the ConvNextModel with the provided configuration. It sets up the embeddings, encoder, and layer normalization based on the configuration parameters.
The forward method processes the input pixel values using the embeddings and encoder, and returns the last hidden state and pooled output. It allows for customization of returning hidden states and outputs as specified in the configuration parameters.
Note
This docstring is based on the provided code snippet and does not include complete signatures or any other code.
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
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 548 549 550 551 552 553 554 555 556 557 558 559 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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextModel.__init__(config)
¶
Initializes a new instance of the ConvNextModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ConvNextModel class.
|
config |
A dictionary containing configuration parameters for the model.
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the provided config parameter is not a dictionary. |
ValueError
|
If the config parameter does not contain the required keys for initializing the model. |
RuntimeError
|
If an error occurs during the initialization process. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextModel.forward(pixel_values=None, output_hidden_states=None, return_dict=None)
¶
Constructs a ConvNextModel by processing the given pixel values.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ConvNextModel class.
TYPE:
|
pixel_values |
The input pixel values. It should be a tensor.
TYPE:
|
output_hidden_states |
Whether or not to output hidden states. Defaults to None.
TYPE:
|
return_dict |
Whether or not to use a return dictionary. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, BaseModelOutputWithPoolingAndNoAttention]
|
Union[Tuple, BaseModelOutputWithPoolingAndNoAttention]: The forwarded ConvNextModel output. It can be either a tuple or an instance of BaseModelOutputWithPoolingAndNoAttention. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If pixel_values is not specified. |
Note
- If output_hidden_states is not provided, it defaults to the value specified in the configuration.
- If return_dict is not provided, it defaults to the value specified in the configuration.
- The returned value may contain the last hidden state, pooled output, and additional encoder outputs.
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
553 554 555 556 557 558 559 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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextPreTrainedModel
¶
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/convnext/modeling_convnext.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextStage
¶
Bases: Module
ConvNeXT stage, consisting of an optional downsampling layer + multiple residual blocks.
PARAMETER | DESCRIPTION |
---|---|
config |
Model configuration class.
TYPE:
|
in_channels |
Number of input channels.
TYPE:
|
out_channels |
Number of output channels.
TYPE:
|
depth |
Number of residual blocks.
TYPE:
|
drop_path_rates(`List[float]`) |
Stochastic depth rates for each layer.
|
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextStage.__init__(config, in_channels, out_channels, kernel_size=2, stride=2, depth=2, drop_path_rates=None)
¶
Initializes a ConvNextStage object with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The ConvNextStage object itself.
TYPE:
|
config |
The configuration settings for the ConvNextStage.
TYPE:
|
in_channels |
The number of input channels.
TYPE:
|
out_channels |
The number of output channels.
TYPE:
|
kernel_size |
The size of the convolutional kernel. Defaults to 2.
TYPE:
|
stride |
The stride of the convolution operation. Defaults to 2.
TYPE:
|
depth |
The depth of the ConvNextStage.
TYPE:
|
drop_path_rates |
A list of dropout rates for each layer in the stage. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If in_channels is not equal to out_channels or stride is greater than 1. |
TypeError
|
If drop_path_rates is not a list. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
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 |
|
mindnlp.transformers.models.convnext.modeling_convnext.ConvNextStage.forward(hidden_states)
¶
Constructs the next stage of a convolutional neural network.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ConvNextStage class.
TYPE:
|
hidden_states |
The input tensor representing the hidden states.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: The tensor representing the output hidden states after the next stage. |
Source code in mindnlp/transformers/models/convnext/modeling_convnext.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
mindnlp.transformers.models.convnext.modeling_convnext.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/convnext/modeling_convnext.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
mindnlp.transformers.models.convnext.image_processing_convnext
¶
Image processor class for ConvNeXT.
mindnlp.transformers.models.convnext.image_processing_convnext.ConvNextImageProcessor
¶
Bases: BaseImageProcessor
Constructs a ConvNeXT image processor.
PARAMETER | DESCRIPTION |
---|---|
do_resize |
Controls whether to resize the image's (height, width) dimensions to the specified
TYPE:
|
size |
Resolution of the output image after
TYPE:
|
crop_pct |
Percentage of the image to crop. Only has an effect if
TYPE:
|
resample |
Resampling filter to use if resizing the image. Can be overriden by
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 overriden by
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/convnext/image_processing_convnext.py
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 |
|
mindnlp.transformers.models.convnext.image_processing_convnext.ConvNextImageProcessor.__init__(do_resize=True, size=None, crop_pct=None, resample=PILImageResampling.BILINEAR, do_rescale=True, rescale_factor=1 / 255, do_normalize=True, image_mean=None, image_std=None, **kwargs)
¶
Initialize a ConvNextImageProcessor object.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ConvNextImageProcessor class.
TYPE:
|
do_resize |
A flag indicating whether to resize the input image. Default is True.
TYPE:
|
size |
A dictionary specifying the size of the output image. Default is {'shortest_edge': 384}.
TYPE:
|
crop_pct |
The percentage of the image to be cropped. Default is 224 / 256.
TYPE:
|
resample |
The resampling method for image resizing. Default is PILImageResampling.BILINEAR.
TYPE:
|
do_rescale |
A flag indicating whether to rescale the image. Default is True.
TYPE:
|
rescale_factor |
The factor by which to rescale the image. Default is 1 / 255.
TYPE:
|
do_normalize |
A flag indicating whether to normalize the image. Default is True.
TYPE:
|
image_mean |
The mean values for image normalization. Default is IMAGENET_STANDARD_MEAN.
TYPE:
|
image_std |
The standard deviation values for image normalization. Default is IMAGENET_STANDARD_STD.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
Source code in mindnlp/transformers/models/convnext/image_processing_convnext.py
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 |
|
mindnlp.transformers.models.convnext.image_processing_convnext.ConvNextImageProcessor.preprocess(images, do_resize=None, size=None, crop_pct=None, resample=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 output image after
TYPE:
|
crop_pct |
Percentage of the image to crop if size < 384.
TYPE:
|
resample |
Resampling filter to use if resizing the image. This can be one of
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/convnext/image_processing_convnext.py
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 |
|
mindnlp.transformers.models.convnext.image_processing_convnext.ConvNextImageProcessor.resize(image, size, crop_pct, resample=PILImageResampling.BICUBIC, data_format=None, input_data_format=None, **kwargs)
¶
Resize an image.
PARAMETER | DESCRIPTION |
---|---|
image |
Image to resize.
TYPE:
|
size |
Dictionary of the form
TYPE:
|
crop_pct |
Percentage of the image to crop. Only has an effect if size < 384.
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 from the input image.
TYPE:
|
Source code in mindnlp/transformers/models/convnext/image_processing_convnext.py
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 |
|