bridgetower
mindnlp.transformers.models.bridgetower.configuration_bridgetower.BridgeTowerConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [BridgeTowerModel
]. It is used to instantiate a
BridgeTower 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 bridgetower-base
BridgeTower/bridgetower-base 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 |
---|---|
share_cross_modal_transformer_layers |
Whether cross modal transformer layers are shared.
TYPE:
|
hidden_act |
The non-linear activation function (function or string) in the encoder and pooler.
TYPE:
|
hidden_size |
Dimensionality of the encoder layers and the pooler layer.
TYPE:
|
initializer_factor |
A factor for initializing all weight matrices (should be kept to 1, used internally for initialization testing).
TYPE:
|
layer_norm_eps |
The epsilon used by the layer normalization layers.
TYPE:
|
share_link_tower_layers |
Whether the bride/link tower layers are shared.
TYPE:
|
link_tower_type |
Type of the bridge/link layer.
TYPE:
|
num_attention_heads |
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
num_hidden_layers |
Number of hidden layers in the Transformer encoder.
TYPE:
|
tie_word_embeddings |
Whether to tie input and output embeddings.
TYPE:
|
init_layernorm_from_vision_encoder |
Whether to init LayerNorm from the vision encoder.
TYPE:
|
text_config |
Dictionary of configuration options used to initialize [
TYPE:
|
vision_config |
Dictionary of configuration options used to initialize [
TYPE:
|
Example
>>> from transformers import BridgeTowerModel, BridgeTowerConfig
...
>>> # Initializing a BridgeTower BridgeTower/bridgetower-base style configuration
>>> configuration = BridgeTowerConfig()
...
>>> # Initializing a model from the BridgeTower/bridgetower-base style configuration
>>> model = BridgeTowerModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/bridgetower/configuration_bridgetower.py
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 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 |
|
mindnlp.transformers.models.bridgetower.configuration_bridgetower.BridgeTowerConfig.__init__(share_cross_modal_transformer_layers=True, hidden_act='gelu', hidden_size=768, initializer_factor=1, layer_norm_eps=1e-05, share_link_tower_layers=False, link_tower_type='add', num_attention_heads=12, num_hidden_layers=6, tie_word_embeddings=False, init_layernorm_from_vision_encoder=False, text_config=None, vision_config=None, **kwargs)
¶
init
Initializes an instance of the BridgeTowerConfig class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
share_cross_modal_transformer_layers |
Indicates whether to share cross modal transformer layers.
TYPE:
|
hidden_act |
The activation function for the hidden layers.
TYPE:
|
hidden_size |
The size of the hidden layers.
TYPE:
|
initializer_factor |
The factor to initialize the layers.
TYPE:
|
layer_norm_eps |
The epsilon value for layer normalization.
TYPE:
|
share_link_tower_layers |
Indicates whether to share link tower layers.
TYPE:
|
link_tower_type |
The type of link tower.
TYPE:
|
num_attention_heads |
The number of attention heads.
TYPE:
|
num_hidden_layers |
The number of hidden layers.
TYPE:
|
tie_word_embeddings |
Indicates whether word embeddings are tied.
TYPE:
|
init_layernorm_from_vision_encoder |
Indicates whether to initialize layernorm from the vision encoder.
TYPE:
|
text_config |
The configuration for text.
TYPE:
|
vision_config |
The configuration for vision.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the provided input types are invalid. |
Source code in mindnlp/transformers/models/bridgetower/configuration_bridgetower.py
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 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
|
mindnlp.transformers.models.bridgetower.configuration_bridgetower.BridgeTowerConfig.from_text_vision_configs(text_config, vision_config, **kwargs)
classmethod
¶
Instantiate a [BridgeTowerConfig
] (or a derived class) from BridgeTower text model configuration.
RETURNS | DESCRIPTION |
---|---|
[ |
Source code in mindnlp/transformers/models/bridgetower/configuration_bridgetower.py
440 441 442 443 444 445 446 447 448 449 450 |
|
mindnlp.transformers.models.bridgetower.configuration_bridgetower.BridgeTowerTextConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the text configuration of a [BridgeTowerModel
]. The default values here
are copied from RoBERTa. Instantiating a configuration with the defaults will yield a similar configuration to that
of the bridgetower-base BridegTower/bridgetower-base
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 |
---|---|
vocab_size |
Vocabulary size of the text part of the model. Defines the number of different tokens that can be
represented by the
TYPE:
|
hidden_size |
Dimensionality of the encoder layers and the pooler layer.
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 Transformer encoder.
TYPE:
|
intermediate_size |
Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
TYPE:
|
hidden_act |
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
hidden_dropout_prob |
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
TYPE:
|
attention_probs_dropout_prob |
The dropout ratio for the attention probabilities.
TYPE:
|
max_position_embeddings |
The maximum sequence length that this model might ever be used with. Typically set this to something large just in case (e.g., 512 or 1024 or 2048).
TYPE:
|
type_vocab_size |
The vocabulary size of the
TYPE:
|
initializer_factor |
A factor for initializing all weight matrices (should be kept to 1, used internally for initialization testing).
TYPE:
|
layer_norm_eps |
The epsilon used by the layer normalization layers.
TYPE:
|
position_embedding_type |
Type of position embedding. Choose one of
TYPE:
|
is_decoder |
Whether the model is used as a decoder or not. If
TYPE:
|
use_cache |
Whether or not the model should return the last key/values attentions (not used by all models). Only
relevant if
TYPE:
|
Example
>>> from transformers import BridgeTowerTextConfig
...
>>> # Initializing a BridgeTower BridgeTower/bridgetower-base style configuration for the text model
>>> configuration = BridgeTowerTextConfig()
...
>>> # Accessing the configuration
>>> configuration
Source code in mindnlp/transformers/models/bridgetower/configuration_bridgetower.py
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 |
|
mindnlp.transformers.models.bridgetower.configuration_bridgetower.BridgeTowerTextConfig.__init__(vocab_size=50265, hidden_size=768, num_hidden_layers=12, num_attention_heads=12, initializer_factor=1, intermediate_size=3072, hidden_act='gelu', hidden_dropout_prob=0.1, attention_probs_dropout_prob=0.1, max_position_embeddings=514, type_vocab_size=1, layer_norm_eps=1e-05, pad_token_id=1, bos_token_id=0, eos_token_id=2, position_embedding_type='absolute', use_cache=True, **kwargs)
¶
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
vocab_size |
The size of the vocabulary. Defaults to 50265.
TYPE:
|
hidden_size |
The hidden size of the model. Defaults to 768.
TYPE:
|
num_hidden_layers |
The number of hidden layers. Defaults to 12.
TYPE:
|
num_attention_heads |
The number of attention heads. Defaults to 12.
TYPE:
|
initializer_factor |
The factor for weight initialization. Defaults to 1.
TYPE:
|
intermediate_size |
The size of the intermediate layer in the transformer. Defaults to 3072.
TYPE:
|
hidden_act |
The activation function for the hidden layers. Defaults to 'gelu'.
TYPE:
|
hidden_dropout_prob |
The dropout probability for the hidden layers. Defaults to 0.1.
TYPE:
|
attention_probs_dropout_prob |
The dropout probability for the attention probabilities. Defaults to 0.1.
TYPE:
|
max_position_embeddings |
The maximum position for the embeddings. Defaults to 514.
TYPE:
|
type_vocab_size |
The size of the type vocabulary. Defaults to 1.
TYPE:
|
layer_norm_eps |
The epsilon value for layer normalization. Defaults to 1e-05.
TYPE:
|
pad_token_id |
The token id for padding. Defaults to 1.
TYPE:
|
bos_token_id |
The token id for the beginning of sequence. Defaults to 0.
TYPE:
|
eos_token_id |
The token id for the end of sequence. Defaults to 2.
TYPE:
|
position_embedding_type |
The type of position embedding. Defaults to 'absolute'.
TYPE:
|
use_cache |
Whether to use caching. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bridgetower/configuration_bridgetower.py
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 |
|
mindnlp.transformers.models.bridgetower.configuration_bridgetower.BridgeTowerTextConfig.from_pretrained(pretrained_model_name_or_path, **kwargs)
classmethod
¶
This method instantiates a BridgeTowerTextConfig from a pretrained model or a model configuration file.
PARAMETER | DESCRIPTION |
---|---|
cls |
The class object itself.
TYPE:
|
pretrained_model_name_or_path |
The name or path of the pretrained model or model configuration file. It can be a string or a valid os.PathLike object.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
PretrainedConfig
|
An instance of a PretrainedConfig object representing the configuration of the pretrained model.
TYPE:
|
Source code in mindnlp/transformers/models/bridgetower/configuration_bridgetower.py
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 |
|
mindnlp.transformers.models.bridgetower.configuration_bridgetower.BridgeTowerVisionConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the vision configuration of a [BridgeTowerModel
]. Instantiating a
configuration with the defaults will yield a similar configuration to that of the bridgetower-base
BridgeTower/bridgetower-base 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 |
---|---|
hidden_size |
Dimensionality of the encoder layers and the pooler layer.
TYPE:
|
num_hidden_layers |
Number of hidden layers in visual encoder model.
TYPE:
|
patch_size |
The size (resolution) of each patch.
TYPE:
|
image_size |
The size (resolution) of each image.
TYPE:
|
initializer_factor |
A factor for initializing all weight matrices (should be kept to 1, used internally for initialization testing).
TYPE:
|
layer_norm_eps |
The epsilon used by the layer normalization layers.
TYPE:
|
stop_gradient |
Whether to stop gradient for training.
TYPE:
|
share_layernorm |
Whether LayerNorm layers are shared.
TYPE:
|
remove_last_layer |
Whether to remove the last layer from the vision encoder.
TYPE:
|
Example
>>> from transformers import BridgeTowerVisionConfig
...
>>> # Initializing a BridgeTower BridgeTower/bridgetower-base style configuration for the vision model
>>> configuration = BridgeTowerVisionConfig()
...
>>> # Accessing the configuration
>>> configuration
Source code in mindnlp/transformers/models/bridgetower/configuration_bridgetower.py
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 |
|
mindnlp.transformers.models.bridgetower.configuration_bridgetower.BridgeTowerVisionConfig.__init__(hidden_size=768, num_hidden_layers=12, num_channels=3, patch_size=16, image_size=288, initializer_factor=1, layer_norm_eps=1e-05, stop_gradient=False, share_layernorm=True, remove_last_layer=False, **kwargs)
¶
Initializes a BridgeTowerVisionConfig object with the specified configuration parameters.
PARAMETER | DESCRIPTION |
---|---|
hidden_size |
The size of the hidden layers in the vision model.
TYPE:
|
num_hidden_layers |
The number of hidden layers in the vision model.
TYPE:
|
num_channels |
The number of input channels in the image data.
TYPE:
|
patch_size |
The size of the image patches used in the model.
TYPE:
|
image_size |
The size of the input images processed by the model.
TYPE:
|
initializer_factor |
A factor used for weight initialization in the model.
TYPE:
|
layer_norm_eps |
The epsilon value for layer normalization.
TYPE:
|
stop_gradient |
Whether to stop gradients during training.
TYPE:
|
share_layernorm |
Whether to share layer normalization parameters across layers.
TYPE:
|
remove_last_layer |
Whether to remove the last layer of the model.
TYPE:
|
**kwargs |
Additional keyword arguments for customization.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bridgetower/configuration_bridgetower.py
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 |
|
mindnlp.transformers.models.bridgetower.configuration_bridgetower.BridgeTowerVisionConfig.from_pretrained(pretrained_model_name_or_path, **kwargs)
classmethod
¶
This method creates an instance of a 'BridgeTowerVisionConfig' class from a pretrained model or its path.
PARAMETER | DESCRIPTION |
---|---|
cls |
The class reference.
TYPE:
|
pretrained_model_name_or_path |
The name or path of the pretrained model. It can be a string or a path-like object representing the location of the pretrained model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
PretrainedConfig
|
An instance of the 'PretrainedConfig' class representing the configuration of the pretrained model.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input parameters are of incorrect types. |
ValueError
|
If the configuration dictionary obtained from the pretrained model is incomplete or invalid. |
Warning
|
If attempting to instantiate a model of a different type than the specified 'model_type', as this may lead to errors. |
Source code in mindnlp/transformers/models/bridgetower/configuration_bridgetower.py
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 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerForContrastiveLearning
¶
Bases: BridgeTowerPreTrainedModel
Represents a BridgeTower model for contrastive learning.
This class inherits from BridgeTowerPreTrainedModel and includes initialization and forwardion methods for contrastive learning. It contains methods for processing input data, calculating contrastive loss, and returning outputs for text and image embeddings.
The forward
method takes input tensors for text and image data, and optional parameters for attention, token
types, and masks. It returns a BridgeTowerContrastiveOutput object containing the contrastive loss, logits,
text embeddings, image embeddings, cross-modal embeddings, hidden states, and attentions.
The example provided demonstrates the usage of the BridgeTowerForContrastiveLearning class for processing images and texts, calculating contrastive loss, and obtaining model outputs.
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerForContrastiveLearning.__init__(config)
¶
Initializes an instance of the BridgeTowerForContrastiveLearning class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object containing various settings and parameters.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerForContrastiveLearning.forward(input_ids=None, attention_mask=None, token_type_ids=None, pixel_values=None, pixel_mask=None, head_mask=None, inputs_embeds=None, image_embeds=None, output_attentions=None, output_hidden_states=True, return_dict=None, return_loss=None)
¶
PARAMETER | DESCRIPTION |
---|---|
return_loss |
Whether or not to return the contrastive loss.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[BridgeTowerContrastiveOutput, Tuple[Tensor]]
|
Union[BridgeTowerContrastiveOutput, Tuple[mindspore.Tensor]] |
Example
>>> from transformers import BridgeTowerProcessor, BridgeTowerForContrastiveLearning
>>> import requests
>>> from PIL import Image
>>> import torch
...
>>> image_urls = [
... "https://farm4.staticflickr.com/3395/3428278415_81c3e27f15_z.jpg",
... "http://images.cocodataset.org/val2017/000000039769.jpg",
... ]
>>> texts = ["two dogs in a car", "two cats sleeping on a couch"]
>>> images = [Image.open(requests.get(url, stream=True).raw) for url in image_urls]
...
>>> processor = BridgeTowerProcessor.from_pretrained("BridgeTower/bridgetower-large-itm-mlm-itc")
>>> model = BridgeTowerForContrastiveLearning.from_pretrained("BridgeTower/bridgetower-large-itm-mlm-itc")
...
>>> inputs = processor(images, texts, padding=True, return_tensors="pt")
>>> loss = model(**inputs, return_loss=True).loss
...
>>> inputs = processor(images, texts[::-1], padding=True, return_tensors="pt")
>>> loss_swapped = model(**inputs, return_loss=True).loss
...
>>> print("Loss", round(loss.item(), 4))
Loss 0.0019
>>> print("Loss with swapped images", round(loss_swapped.item(), 4))
Loss with swapped images 2.126
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerForImageAndTextRetrieval
¶
Bases: BridgeTowerPreTrainedModel
BridgeTowerForImageAndTextRetrieval is a class for performing image and text retrieval using the BridgeTower model.
This class extends the BridgeTowerPreTrainedModel and provides methods for forwarding the model and computing the image-text matching loss.
PARAMETER | DESCRIPTION |
---|---|
config |
Configuration for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SequenceClassifierOutput or Tuple[mindspore.Tensor]: The output of the model, including the image-text matching loss and the logits. |
Example
>>> from transformers import BridgeTowerProcessor, BridgeTowerForImageAndTextRetrieval
>>> import requests
>>> from PIL import Image
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> texts = ["An image of two cats chilling on a couch", "A football player scoring a goal"]
>>> processor = BridgeTowerProcessor.from_pretrained("BridgeTower/bridgetower-base-itm-mlm")
>>> model = BridgeTowerForImageAndTextRetrieval.from_pretrained("BridgeTower/bridgetower-base-itm-mlm")
>>> scores = dict()
>>> for text in texts:
... encoding = processor(image, text, return_tensors="pt")
... outputs = model(**encoding)
... scores[text] = outputs.logits[0, 1].item()
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerForImageAndTextRetrieval.__init__(config)
¶
Initializes an instance of the BridgeTowerForImageAndTextRetrieval class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class itself.
|
config |
A configuration object containing the necessary parameters for initialization.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerForImageAndTextRetrieval.forward(input_ids=None, attention_mask=None, token_type_ids=None, pixel_values=None, pixel_mask=None, head_mask=None, inputs_embeds=None, image_embeds=None, output_attentions=None, output_hidden_states=None, return_dict=None, labels=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the image-text matching loss. 0 means the pairs don't match and 1 means they match. The pairs with 0 will be skipped for calculation.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[SequenceClassifierOutput, Tuple[Tensor]]
|
Union[SequenceClassifierOutput, Tuple[mindspore.Tensor]] |
Example
>>> from transformers import BridgeTowerProcessor, BridgeTowerForImageAndTextRetrieval
>>> import requests
>>> from PIL import Image
...
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> texts = ["An image of two cats chilling on a couch", "A football player scoring a goal"]
...
>>> processor = BridgeTowerProcessor.from_pretrained("BridgeTower/bridgetower-base-itm-mlm")
>>> model = BridgeTowerForImageAndTextRetrieval.from_pretrained("BridgeTower/bridgetower-base-itm-mlm")
...
>>> # forward pass
>>> scores = dict()
>>> for text in texts:
... # prepare inputs
... encoding = processor(image, text, return_tensors="pt")
... outputs = model(**encoding)
... scores[text] = outputs.logits[0, 1].item()
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerForMaskedLM
¶
Bases: BridgeTowerPreTrainedModel
BridgeTowerForMaskedLM class represents a model for masked language modeling using the BridgeTower architecture. It inherits functionality from the BridgeTowerPreTrainedModel class.
This class includes methods for initializing the model with configuration, getting and setting output embeddings, and forwarding the model for inference. The 'forward' method takes various input tensors such as input_ids, attention_mask, token_type_ids, pixel_values, pixel_mask, etc., and returns masked language modeling outputs. It also supports optional labels for computing the masked language modeling loss.
The class provides an example of how to use the model for masked language modeling tasks using images and text inputs. It showcases the process of preparing inputs, performing a forward pass, decoding model outputs, and printing the results.
The BridgeTowerForMaskedLM class encapsulates the functionality for masked language modeling tasks using the BridgeTower architecture.
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerForMaskedLM.__init__(config)
¶
init
Initializes an instance of the BridgeTowerForMaskedLM class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
config |
The configuration object containing settings and parameters for the BridgeTowerForMaskedLM instance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerForMaskedLM.forward(input_ids=None, attention_mask=None, token_type_ids=None, pixel_values=None, pixel_mask=None, head_mask=None, inputs_embeds=None, image_embeds=None, output_attentions=None, output_hidden_states=None, return_dict=None, labels=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the masked language modeling loss. Indices should be in
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[MaskedLMOutput, Tuple[Tensor]]
|
|
Example
>>> from transformers import BridgeTowerProcessor, BridgeTowerForMaskedLM
>>> from PIL import Image
>>> import requests
...
>>> url = "http://images.cocodataset.org/val2017/000000360943.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
>>> text = "a <mask> looking out of the window"
...
>>> processor = BridgeTowerProcessor.from_pretrained("BridgeTower/bridgetower-base-itm-mlm")
>>> model = BridgeTowerForMaskedLM.from_pretrained("BridgeTower/bridgetower-base-itm-mlm")
...
>>> # prepare inputs
>>> encoding = processor(image, text, return_tensors="pt")
...
>>> # forward pass
>>> outputs = model(**encoding)
...
>>> results = processor.decode(outputs.logits.argmax(dim=-1).squeeze(0).tolist())
...
>>> print(results)
.a cat looking out of the window.
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerForMaskedLM.get_output_embeddings()
¶
This method returns the output embeddings for the Masked Language Model (MLM) decoder.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BridgeTowerForMaskedLM class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns None, as it directly returns the output embeddings without any further processing. |
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerForMaskedLM.set_output_embeddings(new_embeddings)
¶
Sets the output embeddings for the BridgeTowerForMaskedLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BridgeTowerForMaskedLM class.
TYPE:
|
new_embeddings |
The new embeddings to be set as the output embeddings. It should be a tensor of shape (vocab_size, hidden_size).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
This method sets the output embeddings for the BridgeTowerForMaskedLM model by updating the decoder attribute of the mlm_score object. The new_embeddings parameter should be a tensor representing the new embeddings to be used as the output embeddings. The tensor should have a shape of (vocab_size, hidden_size) where vocab_size is the number of tokens in the vocabulary and hidden_size is the size of the hidden state of the model.
Example
>>> model = BridgeTowerForMaskedLM()
>>> new_embeddings = torch.randn(model.vocab_size, model.hidden_size)
>>> model.set_output_embeddings(new_embeddings)
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerModel
¶
Bases: BridgeTowerPreTrainedModel
BridgeTowerModel Represents a BridgeTower model, which is a model for processing multimodal inputs, combining text and image information using cross-modal transformers.
This class inherits from BridgeTowerPreTrainedModel and implements methods for initializing the model, forwarding the model, and getting classification features.
The BridgeTowerModel class includes methods for getting and setting input embeddings, as well as forwarding the model for processing multimodal inputs. It also provides a method for obtaining classification features from the processed multimodal inputs.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
The configuration for the BridgeTowerModel.
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the BridgeTowerModel with the provided configuration. |
get_input_embeddings |
Retrieves the input embeddings from the text model. |
set_input_embeddings |
Sets the input embeddings for the text model. |
forward |
Constructs the model for processing multimodal inputs and returns the model output. |
get_cls_features |
Retrieves the classification features from the processed multimodal inputs. |
Example
>>> from transformers import BridgeTowerProcessor, BridgeTowerModel
>>> from PIL import Image
>>> import requests
...
>>> # prepare image and text
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> text = "hello world"
>>> processor = BridgeTowerProcessor.from_pretrained("BridgeTower/bridgetower-base")
>>> model = BridgeTowerModel.from_pretrained("BridgeTower/bridgetower-base")
...
>>> inputs = processor(image, text, return_tensors="pt")
>>> outputs = model(**inputs)
>>> outputs.keys()
odict_keys(['text_features', 'image_features', 'pooler_output'])
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerModel.__init__(config)
¶
Initializes a BridgeTowerModel instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BridgeTowerModel class.
TYPE:
|
config |
An object containing configuration settings for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerModel.forward(input_ids=None, attention_mask=None, token_type_ids=None, pixel_values=None, pixel_mask=None, head_mask=None, inputs_embeds=None, image_embeds=None, image_token_type_idx=None, output_attentions=None, output_hidden_states=None, return_dict=None, labels=None)
¶
PARAMETER | DESCRIPTION |
---|---|
output_hidden_states |
If set to
TYPE:
|
labels |
Labels are currently not supported.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple[Tensor], BridgeTowerModelOutput]
|
Union[Tuple[mindspore.Tensor], BridgeTowerModelOutput]: |
Example
>>> from transformers import BridgeTowerProcessor, BridgeTowerModel
>>> from PIL import Image
>>> import requests
...
>>> # prepare image and text
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> text = "hello world"
>>> processor = BridgeTowerProcessor.from_pretrained("BridgeTower/bridgetower-base")
>>> model = BridgeTowerModel.from_pretrained("BridgeTower/bridgetower-base")
...
>>> inputs = processor(image, text, return_tensors="pt")
>>> outputs = model(**inputs)
>>> outputs.keys()
odict_keys(['text_features', 'image_features', 'pooler_output'])
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerModel.get_cls_features(text_features, image_features)
¶
This method 'get_cls_features' is defined in the class 'BridgeTowerModel' and is used to obtain the class features by pooling text and image features.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BridgeTowerModel class.
TYPE:
|
text_features |
The input text features to be pooled for obtaining class features.
TYPE:
|
image_features |
The input image features to be pooled for obtaining class features.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns None, as the class features are directly computed and concatenated without any additional processing. |
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerModel.get_input_embeddings()
¶
Retrieves the input embeddings from the BridgeTowerModel's text model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BridgeTowerModel class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
This method retrieves the input embeddings from the underlying text model of the BridgeTowerModel. The input embeddings are representations of the input text that are used for further processing or analysis. By calling this method, you can access the input embeddings that have been generated by the text model.
Note that the text model must be initialized and trained before calling this method. If the text model has not been initialized or trained, this method may not return the expected embeddings or may raise an exception.
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerModel.set_input_embeddings(value)
¶
Sets the input embeddings for the BridgeTowerModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BridgeTowerModel class.
TYPE:
|
value |
The input embeddings to be set for the BridgeTowerModel. It should be of type Tensor or None.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bridgetower/modeling_bridgetower.py
2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 |
|
mindnlp.transformers.models.bridgetower.modeling_bridgetower.BridgeTowerPreTrainedModel
¶
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/bridgetower/modeling_bridgetower.py
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 |
|
mindnlp.transformers.models.bridgetower.image_processing_bridgetower.BridgeTowerImageProcessor
¶
Bases: BaseImageProcessor
Constructs a BridgeTower image processor.
PARAMETER | DESCRIPTION |
---|---|
do_resize |
Whether to resize the image's (height, width) dimensions to the specified
TYPE:
|
size |
288}
TYPE:
|
size_divisor |
The size by which to make sure both the height and width can be divided. Only has an effect if
TYPE:
|
resample |
Resampling filter to use if resizing the image. Only has an effect if
TYPE:
|
do_rescale |
Whether to rescale the image by the specified scale
TYPE:
|
rescale_factor |
Scale factor to use if rescaling the image. Only has an effect if
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:
|
do_center_crop |
Whether to center crop the image. Can be overridden by the
TYPE:
|
crop_size |
Desired output size when applying center-cropping. Only has an effect if
TYPE:
|
do_pad |
Whether to pad the image to the
TYPE:
|
Source code in mindnlp/transformers/models/bridgetower/image_processing_bridgetower.py
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 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 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 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 |
|
mindnlp.transformers.models.bridgetower.image_processing_bridgetower.BridgeTowerImageProcessor.__init__(do_resize=True, size=None, size_divisor=32, resample=PILImageResampling.BICUBIC, do_rescale=True, rescale_factor=1 / 255, do_normalize=True, image_mean=None, image_std=None, do_center_crop=True, crop_size=None, do_pad=True, **kwargs)
¶
Initializes an instance of the BridgeTowerImageProcessor class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class itself.
|
do_resize |
Indicates whether to resize the image. Defaults to True.
TYPE:
|
size |
The desired size of the image. Defaults to {'shortest_edge': 288}.
TYPE:
|
size_divisor |
The divisor to be used during resizing. Defaults to 32.
TYPE:
|
resample |
The resampling method to be used during resizing. Defaults to PILImageResampling.BICUBIC.
TYPE:
|
do_rescale |
Indicates whether to rescale the image. Defaults to True.
TYPE:
|
rescale_factor |
The factor to be used during rescaling. Defaults to 1 / 255.
TYPE:
|
do_normalize |
Indicates whether to normalize the image. Defaults to True.
TYPE:
|
image_mean |
The mean values for image normalization. Defaults to None.
TYPE:
|
image_std |
The standard deviation values for image normalization. Defaults to None.
TYPE:
|
do_center_crop |
Indicates whether to perform center cropping. Defaults to True.
TYPE:
|
crop_size |
The desired size for center cropping. Defaults to None.
TYPE:
|
do_pad |
Indicates whether to pad the image. Defaults to True.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
Source code in mindnlp/transformers/models/bridgetower/image_processing_bridgetower.py
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 |
|
mindnlp.transformers.models.bridgetower.image_processing_bridgetower.BridgeTowerImageProcessor.center_crop(image, size, data_format=None, input_data_format=None, **kwargs)
¶
Center crop an image to (size["height"], size["width"])
. If the input size is smaller than crop_size
along
any edge, the image is padded with 0's and then center cropped.
PARAMETER | DESCRIPTION |
---|---|
image |
Image to center crop.
TYPE:
|
size |
Size of the output image in the form
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/bridgetower/image_processing_bridgetower.py
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 |
|
mindnlp.transformers.models.bridgetower.image_processing_bridgetower.BridgeTowerImageProcessor.pad(images, constant_values=0, return_pixel_mask=True, return_tensors=None, data_format=None, input_data_format=None)
¶
Pads a batch of images to the bottom and right of the image with zeros to the size of largest height and width in the batch and optionally returns their corresponding pixel mask.
PARAMETER | DESCRIPTION |
---|---|
image |
Image to pad.
TYPE:
|
constant_values |
The value to use for the padding if
TYPE:
|
return_pixel_mask |
Whether to return a pixel mask.
TYPE:
|
return_tensors |
The type of tensors to return. Can be one of:
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/bridgetower/image_processing_bridgetower.py
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 422 423 424 425 426 427 428 429 430 |
|
mindnlp.transformers.models.bridgetower.image_processing_bridgetower.BridgeTowerImageProcessor.preprocess(images, do_resize=None, size=None, size_divisor=None, resample=None, do_rescale=None, rescale_factor=None, do_normalize=None, image_mean=None, image_std=None, do_pad=None, do_center_crop=None, crop_size=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 |
Controls the size of the image after
TYPE:
|
size_divisor |
The image is resized to a size that is a multiple of this value.
TYPE:
|
resample |
Resampling filter to use if resizing the image. Only has an effect if
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 to normalize the image by if
TYPE:
|
image_std |
Image standard deviation to normalize the image by if
TYPE:
|
do_pad |
Whether to pad the image to the (max_height, max_width) in the batch. If
TYPE:
|
do_center_crop |
Whether to center crop the image. If the input size is smaller than
TYPE:
|
crop_size |
Size of the image after center crop. If one edge the image is smaller than
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/bridgetower/image_processing_bridgetower.py
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 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 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 |
|
mindnlp.transformers.models.bridgetower.image_processing_bridgetower.BridgeTowerImageProcessor.resize(image, size, size_divisor=32, resample=PILImageResampling.BICUBIC, data_format=None, input_data_format=None, **kwargs)
¶
Resize an image.
Resizes the shorter side of the image to size["shortest_edge"]
while preserving the aspect ratio. If the
longer side is larger than the max size (int(
size["shortest_edge"]* 1333 / 800))
, the longer side is then
resized to the max size while preserving the aspect ratio.
PARAMETER | DESCRIPTION |
---|---|
image |
Image to resize.
TYPE:
|
size |
Controls the size of the output image. Should be of the form
TYPE:
|
size_divisor |
The image is resized to a size that is a multiple of this value.
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/bridgetower/image_processing_bridgetower.py
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 |
|
mindnlp.transformers.models.bridgetower.processing_bridgetower.BridgeTowerProcessor
¶
Bases: ProcessorMixin
Constructs a BridgeTower processor which wraps a Roberta tokenizer and BridgeTower image processor into a single processor.
[BridgeTowerProcessor
] offers all the functionalities of [BridgeTowerImageProcessor
] and
[RobertaTokenizerFast
]. See the docstring of [~BridgeTowerProcessor.__call__
] and
[~BridgeTowerProcessor.decode
] for more information.
PARAMETER | DESCRIPTION |
---|---|
image_processor |
An instance of [
TYPE:
|
tokenizer |
An instance of ['RobertaTokenizerFast`]. The tokenizer is a required input.
TYPE:
|
Source code in mindnlp/transformers/models/bridgetower/processing_bridgetower.py
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 |
|
mindnlp.transformers.models.bridgetower.processing_bridgetower.BridgeTowerProcessor.model_input_names
property
¶
Returns a list of model input names for the 'BridgeTowerProcessor' class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the 'BridgeTowerProcessor' class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list
|
A list containing the model input names for the tokenizer and the image processor. |
mindnlp.transformers.models.bridgetower.processing_bridgetower.BridgeTowerProcessor.__call__(images, text=None, add_special_tokens=True, padding=False, truncation=None, max_length=None, stride=0, pad_to_multiple_of=None, return_token_type_ids=None, return_attention_mask=None, return_overflowing_tokens=False, return_special_tokens_mask=False, return_offsets_mapping=False, return_length=False, verbose=True, return_tensors=None, **kwargs)
¶
This method uses [BridgeTowerImageProcessor.__call__
] method to prepare image(s) for the model, and
[RobertaTokenizerFast.__call__
] to prepare text for the model.
Please refer to the docstring of the above two methods for more information.
Source code in mindnlp/transformers/models/bridgetower/processing_bridgetower.py
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 |
|
mindnlp.transformers.models.bridgetower.processing_bridgetower.BridgeTowerProcessor.__init__(image_processor, tokenizer)
¶
This method initializes an instance of the BridgeTowerProcessor class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BridgeTowerProcessor class.
TYPE:
|
image_processor |
An object representing the image processor to be used for processing images.
TYPE:
|
tokenizer |
An object representing the tokenizer to be used for tokenizing text.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bridgetower/processing_bridgetower.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
mindnlp.transformers.models.bridgetower.processing_bridgetower.BridgeTowerProcessor.batch_decode(*args, **kwargs)
¶
This method forwards all its arguments to RobertaTokenizerFast's [~PreTrainedTokenizer.batch_decode
]. Please
refer to the docstring of this method for more information.
Source code in mindnlp/transformers/models/bridgetower/processing_bridgetower.py
114 115 116 117 118 119 |
|
mindnlp.transformers.models.bridgetower.processing_bridgetower.BridgeTowerProcessor.decode(*args, **kwargs)
¶
This method forwards all its arguments to RobertaTokenizerFast's [~PreTrainedTokenizer.decode
]. Please refer
to the docstring of this method for more information.
Source code in mindnlp/transformers/models/bridgetower/processing_bridgetower.py
121 122 123 124 125 126 |
|