bit
mindnlp.transformers.models.bit.configuration_bit.BitConfig
¶
Bases: BackboneConfigMixin, PretrainedConfig
This is the configuration class to store the configuration of a [BitModel]. It is used to instantiate an BiT
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 BiT
google/bit-50 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:
|
embedding_size
|
Dimensionality (hidden size) for the embedding layer.
TYPE:
|
hidden_sizes
|
Dimensionality (hidden size) at each stage.
TYPE:
|
depths
|
Depth (number of layers) for each stage.
TYPE:
|
layer_type
|
The layer to use, it can be either
TYPE:
|
hidden_act
|
The non-linear activation function in each block. If string,
TYPE:
|
global_padding
|
Padding strategy to use for the convolutional layers. Can be either
TYPE:
|
num_groups
|
Number of groups used for the
TYPE:
|
drop_path_rate
|
The drop path rate for the stochastic depth.
TYPE:
|
embedding_dynamic_padding
|
Whether or not to make use of dynamic padding for the embedding layer.
TYPE:
|
output_stride
|
The output stride of the model.
TYPE:
|
width_factor
|
The width factor for the model.
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 BitConfig, BitModel
...
>>> # Initializing a BiT bit-50 style configuration
>>> configuration = BitConfig()
...
>>> # Initializing a model (with random weights) from the bit-50 style configuration
>>> model = BitModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp\transformers\models\bit\configuration_bit.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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
mindnlp.transformers.models.bit.configuration_bit.BitConfig.__init__(num_channels=3, embedding_size=64, hidden_sizes=[256, 512, 1024, 2048], depths=[3, 4, 6, 3], layer_type='preactivation', hidden_act='relu', global_padding=None, num_groups=32, drop_path_rate=0.0, embedding_dynamic_padding=False, output_stride=32, width_factor=1, out_features=None, out_indices=None, **kwargs)
¶
Initialize the BitConfig class with the provided configuration parameters.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
Reference to the current instance of the class.
|
num_channels
|
Number of input channels for the model. Defaults to 3.
TYPE:
|
embedding_size
|
Dimensionality of the embedding space. Defaults to 64.
TYPE:
|
hidden_sizes
|
List of integers specifying the sizes of hidden layers in the model.
TYPE:
|
depths
|
List of integers representing the depths of each stage in the model.
TYPE:
|
layer_type
|
Type of layer architecture to use in the model.
TYPE:
|
hidden_act
|
Activation function to apply in the hidden layers. Default is 'relu'.
TYPE:
|
global_padding
|
Strategy for padding. Must be one of the supported padding strategies.
TYPE:
|
num_groups
|
Number of groups for group normalization.
TYPE:
|
drop_path_rate
|
Probability of dropping a path during training. Default is 0.0.
TYPE:
|
embedding_dynamic_padding
|
Flag indicating whether dynamic padding should be applied to embeddings.
TYPE:
|
output_stride
|
Stride value for output computation.
TYPE:
|
width_factor
|
Factor to scale the width of the model.
TYPE:
|
out_features
|
List of output features to align with stage names.
TYPE:
|
out_indices
|
List of output indices to align with stage names.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the provided layer_type is not supported. |
ValueError
|
If the global_padding strategy is not supported. |
Source code in mindnlp\transformers\models\bit\configuration_bit.py
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 | |
mindnlp.transformers.models.bit.modeling_bit.BitForImageClassification
¶
Bases: BitPreTrainedModel
Source code in mindnlp\transformers\models\bit\modeling_bit.py
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 | |
mindnlp.transformers.models.bit.modeling_bit.BitForImageClassification.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 classification loss is computed (Cross-Entropy).
Source code in mindnlp\transformers\models\bit\modeling_bit.py
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 | |
mindnlp.transformers.models.bit.modeling_bit.BitModel
¶
Bases: BitPreTrainedModel
Source code in mindnlp\transformers\models\bit\modeling_bit.py
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 715 716 | |
mindnlp.transformers.models.bit.modeling_bit.BitPreTrainedModel
¶
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\bit\modeling_bit.py
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 | |
mindnlp.transformers.models.bit.modeling_bit.BitBackbone
¶
Bases: BitPreTrainedModel, BackboneMixin
Source code in mindnlp\transformers\models\bit\modeling_bit.py
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 | |
mindnlp.transformers.models.bit.modeling_bit.BitBackbone.forward(pixel_values, output_hidden_states=None, return_dict=None)
¶
Examples:
>>> 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("google/bit-50")
>>> model = AutoBackbone.from_pretrained("google/bit-50")
>>> inputs = processor(image, return_tensors="ms")
>>> outputs = model(**inputs)
Source code in mindnlp\transformers\models\bit\modeling_bit.py
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 | |
mindnlp.transformers.models.bit.image_processing_bit.BitImageProcessor
¶
Bases: BaseImageProcessor
Constructs a BiT image processor.
| PARAMETER | DESCRIPTION |
|---|---|
do_resize
|
Whether to resize the image's (height, width) dimensions to the specified
TYPE:
|
size
|
224}
TYPE:
|
resample
|
Resampling filter to use if resizing the image. Can be overridden by
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
TYPE:
|
do_normalize
|
Whether to normalize the image. Can be overridden by
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:
|
do_convert_rgb
|
Whether to convert the image to RGB.
TYPE:
|
Source code in mindnlp\transformers\models\bit\image_processing_bit.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 363 364 365 366 367 368 369 370 371 372 | |
mindnlp.transformers.models.bit.image_processing_bit.BitImageProcessor.__init__(do_resize=True, size=None, resample=PILImageResampling.BICUBIC, do_center_crop=True, crop_size=None, do_rescale=True, rescale_factor=1 / 255, do_normalize=True, image_mean=None, image_std=None, do_convert_rgb=True, **kwargs)
¶
Initializes a BitImageProcessor instance.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The BitImageProcessor instance.
|
do_resize
|
Whether to resize the image. Defaults to True.
TYPE:
|
size
|
The target size of the image. Defaults to None.
TYPE:
|
resample
|
The resampling filter to use when resizing the image. Defaults to PILImageResampling.BICUBIC.
TYPE:
|
do_center_crop
|
Whether to perform center cropping. Defaults to True.
TYPE:
|
crop_size
|
The size for center cropping. Defaults to None.
TYPE:
|
do_rescale
|
Whether to rescale the image. Defaults to True.
TYPE:
|
rescale_factor
|
The rescaling factor. Defaults to 1 / 255.
TYPE:
|
do_normalize
|
Whether to normalize the image. Defaults to True.
TYPE:
|
image_mean
|
The mean value for image normalization. Defaults to None.
TYPE:
|
image_std
|
The standard deviation for image normalization. Defaults to None.
TYPE:
|
do_convert_rgb
|
Whether to convert the image to RGB format. Defaults to True.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None. |
Source code in mindnlp\transformers\models\bit\image_processing_bit.py
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 | |
mindnlp.transformers.models.bit.image_processing_bit.BitImageProcessor.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, do_convert_rgb=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 resizing. Shortest edge of the image is resized to size["shortest_edge"], with the longest edge resized to keep the input aspect ratio.
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 center crop. Only has an effect if
TYPE:
|
do_rescale
|
Whether to rescale the image.
TYPE:
|
rescale_factor
|
Rescale factor to rescale the image by if
TYPE:
|
do_normalize
|
Whether to normalize the image.
TYPE:
|
image_mean
|
Image mean to use for normalization. Only has an effect if
TYPE:
|
image_std
|
Image standard deviation to use for normalization. Only has an effect if
TYPE:
|
do_convert_rgb
|
Whether to convert the image to RGB.
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\bit\image_processing_bit.py
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 | |
mindnlp.transformers.models.bit.image_processing_bit.BitImageProcessor.resize(image, size, resample=PILImageResampling.BICUBIC, data_format=None, input_data_format=None, **kwargs)
¶
Resize an image. The shortest edge of the image is resized to size["shortest_edge"], with the longest edge resized to keep the input aspect ratio.
| PARAMETER | DESCRIPTION |
|---|---|
image
|
Image to resize.
TYPE:
|
size
|
Size of the output image.
TYPE:
|
resample
|
Resampling filter to use when resiizing 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\bit\image_processing_bit.py
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 | |