owlvit
mindnlp.transformers.models.owlvit.configuration_owlvit
¶
OwlViT model configuration
mindnlp.transformers.models.owlvit.configuration_owlvit.OwlViTConfig
¶
Bases: PretrainedConfig
[OwlViTConfig
] is the configuration class to store the configuration of an [OwlViTModel
]. It is used to
instantiate an OWL-ViT model according to the specified arguments, defining the text model and vision model
configs. Instantiating a configuration with the defaults will yield a similar configuration to that of the OWL-ViT
google/owlvit-base-patch32 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 |
---|---|
text_config |
Dictionary of configuration options used to initialize [
TYPE:
|
vision_config |
Dictionary of configuration options used to initialize [
TYPE:
|
projection_dim |
Dimensionality of text and vision projection layers.
TYPE:
|
logit_scale_init_value |
The inital value of the logit_scale parameter. Default is used as per the original OWL-ViT implementation.
TYPE:
|
return_dict |
Whether or not the model should return a dictionary. If
TYPE:
|
kwargs |
Dictionary of keyword arguments.
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/configuration_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.configuration_owlvit.OwlViTConfig.from_text_vision_configs(text_config, vision_config, **kwargs)
classmethod
¶
Instantiate a [OwlViTConfig
] (or a derived class) from owlvit text model configuration and owlvit vision
model configuration.
RETURNS | DESCRIPTION |
---|---|
[ |
Source code in mindnlp/transformers/models/owlvit/configuration_owlvit.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
mindnlp.transformers.models.owlvit.configuration_owlvit.OwlViTTextConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of an [OwlViTTextModel
]. It is used to instantiate an
OwlViT text encoder according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield a similar configuration to that of the OwlViT
google/owlvit-base-patch32 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 OWL-ViT text 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:
|
intermediate_size |
Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
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:
|
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:
|
hidden_act |
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
layer_norm_eps |
The epsilon used by the layer normalization layers.
TYPE:
|
attention_dropout |
The dropout ratio for the attention probabilities.
TYPE:
|
initializer_range |
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
initializer_factor |
A factor for initializing all weight matrices (should be kept to 1, used internally for initialization testing).
TYPE:
|
pad_token_id |
The id of the padding token in the input sequences.
TYPE:
|
bos_token_id |
The id of the beginning-of-sequence token in the input sequences.
TYPE:
|
eos_token_id |
The id of the end-of-sequence token in the input sequences.
TYPE:
|
Example
>>> from transformers import OwlViTTextConfig, OwlViTTextModel
...
>>> # Initializing a OwlViTTextModel with google/owlvit-base-patch32 style configuration
>>> configuration = OwlViTTextConfig()
...
>>> # Initializing a OwlViTTextConfig from the google/owlvit-base-patch32 style configuration
>>> model = OwlViTTextModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/owlvit/configuration_owlvit.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
mindnlp.transformers.models.owlvit.configuration_owlvit.OwlViTVisionConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of an [OwlViTVisionModel
]. It is used to instantiate
an OWL-ViT image encoder according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield a similar configuration to that of the OWL-ViT
google/owlvit-base-patch32 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:
|
intermediate_size |
Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
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:
|
num_channels |
Number of channels in the input images.
TYPE:
|
image_size |
The size (resolution) of each image.
TYPE:
|
patch_size |
The size (resolution) of each patch.
TYPE:
|
hidden_act |
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
layer_norm_eps |
The epsilon used by the layer normalization layers.
TYPE:
|
attention_dropout |
The dropout ratio for the attention probabilities.
TYPE:
|
initializer_range |
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
initializer_factor |
A factor for initializing all weight matrices (should be kept to 1, used internally for initialization testing).
TYPE:
|
Example
>>> from transformers import OwlViTVisionConfig, OwlViTVisionModel
...
>>> # Initializing a OwlViTVisionModel with google/owlvit-base-patch32 style configuration
>>> configuration = OwlViTVisionConfig()
...
>>> # Initializing a OwlViTVisionModel model from the google/owlvit-base-patch32 style configuration
>>> model = OwlViTVisionModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/owlvit/configuration_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.feature_extraction_owlvit
¶
Feature extractor class for OwlViT.
mindnlp.transformers.models.owlvit.image_processing_owlvit
¶
Image processor class for OwlViT
mindnlp.transformers.models.owlvit.image_processing_owlvit.OwlViTImageProcessor
¶
Bases: BaseImageProcessor
Constructs an OWL-ViT image processor.
This image processor inherits from [ImageProcessingMixin
] which contains most of the main methods. Users should
refer to this superclass for more information regarding those methods.
PARAMETER | DESCRIPTION |
---|---|
do_resize |
Whether to resize the shorter edge of the input to a certain
TYPE:
|
size |
768, "width": 768}):
The size to use for resizing the image. Only has an effect if
TYPE:
|
resample |
An optional resampling filter. This can be one of
TYPE:
|
do_center_crop |
Whether to crop the input at the center. If the input size is smaller than
TYPE:
|
crop_size |
The size to use for center cropping the image. Only has an effect if
TYPE:
|
do_rescale |
Whether to rescale the input by a certain factor.
TYPE:
|
rescale_factor |
The factor to use for rescaling the image. Only has an effect if
TYPE:
|
do_normalize |
Whether or not to normalize the input with
TYPE:
|
image_mean |
The sequence of means for each channel, to be used when normalizing images.
TYPE:
|
image_std |
The sequence of standard deviations for each channel, to be used when normalizing images.
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/image_processing_owlvit.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 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 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
|
mindnlp.transformers.models.owlvit.image_processing_owlvit.OwlViTImageProcessor.center_crop(image, crop_size, data_format=None, input_data_format=None, **kwargs)
¶
Center crop an image to a certain size.
PARAMETER | DESCRIPTION |
---|---|
image |
Image to center crop.
TYPE:
|
crop_size |
The size to center crop the image to. Must contain height and width keys.
TYPE:
|
data_format |
The channel dimension format for the output image. If unset, the channel dimension format of the input image is used.
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/owlvit/image_processing_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.image_processing_owlvit.OwlViTImageProcessor.post_process(outputs, target_sizes)
¶
Converts the raw output of [OwlViTForObjectDetection
] into final bounding boxes in (top_left_x, top_left_y,
bottom_right_x, bottom_right_y) format.
PARAMETER | DESCRIPTION |
---|---|
outputs |
Raw outputs of the model.
TYPE:
|
target_sizes |
Tensor containing the size (h, w) of each image of the batch. For evaluation, this must be the original image size (before any data augmentation). For visualization, this should be the image size after data augment, but before padding.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/transformers/models/owlvit/image_processing_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.image_processing_owlvit.OwlViTImageProcessor.post_process_image_guided_detection(outputs, threshold=0.0, nms_threshold=0.3, target_sizes=None)
¶
Converts the output of [OwlViTForObjectDetection.image_guided_detection
] into the format expected by the COCO
api.
PARAMETER | DESCRIPTION |
---|---|
outputs |
Raw outputs of the model.
TYPE:
|
threshold |
Minimum confidence threshold to use to filter out predicted boxes.
TYPE:
|
nms_threshold |
IoU threshold for non-maximum suppression of overlapping boxes.
TYPE:
|
target_sizes |
Tensor of shape (batch_size, 2) where each entry is the (height, width) of the corresponding image in the batch. If set, predicted normalized bounding boxes are rescaled to the target sizes. If left to None, predictions will not be unnormalized.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/transformers/models/owlvit/image_processing_owlvit.py
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 610 611 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 |
|
mindnlp.transformers.models.owlvit.image_processing_owlvit.OwlViTImageProcessor.post_process_object_detection(outputs, threshold=0.1, target_sizes=None)
¶
Converts the raw output of [OwlViTForObjectDetection
] into final bounding boxes in (top_left_x, top_left_y,
bottom_right_x, bottom_right_y) format.
PARAMETER | DESCRIPTION |
---|---|
outputs |
Raw outputs of the model.
TYPE:
|
threshold |
Score threshold to keep object detection predictions.
TYPE:
|
target_sizes |
Tensor of shape
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/transformers/models/owlvit/image_processing_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.image_processing_owlvit.OwlViTImageProcessor.preprocess(images, do_resize=None, size=None, resample=None, do_center_crop=None, crop_size=None, do_rescale=None, rescale_factor=None, do_normalize=None, image_mean=None, image_std=None, return_tensors=None, data_format=ChannelDimension.FIRST, input_data_format=None, **kwargs)
¶
Prepares an image or batch of images for the model.
PARAMETER | DESCRIPTION |
---|---|
images |
The image or batch of images to be prepared. 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 or not to resize the input. If
TYPE:
|
size |
The size to resize the input to. Only has an effect if
TYPE:
|
resample |
The resampling filter to use when resizing the input. Only has an effect if
TYPE:
|
do_center_crop |
Whether or not to center crop the input. If
TYPE:
|
crop_size |
The size to center crop the input to. Only has an effect if
TYPE:
|
do_rescale |
Whether or not to rescale the input. If
TYPE:
|
rescale_factor |
The factor to rescale the input by. Only has an effect if
TYPE:
|
do_normalize |
Whether or not to normalize the input. If
TYPE:
|
image_mean |
The mean to subtract from the input when normalizing. Only has an effect if
TYPE:
|
image_std |
The standard deviation to divide the input by when normalizing. Only has an effect if
TYPE:
|
return_tensors |
The type of tensors to return. Can be one of:
TYPE:
|
data_format |
The channel dimension format for the output image. Can be one of:
TYPE:
|
input_data_format |
The channel dimension format for the input image. If unset, the channel dimension format is inferred from the input image. Can be one of:
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/image_processing_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.image_processing_owlvit.OwlViTImageProcessor.rescale(image, rescale_factor, data_format=None, input_data_format=None)
¶
Rescale the image by the given factor. image = image * rescale_factor.
PARAMETER | DESCRIPTION |
---|---|
image |
Image to rescale.
TYPE:
|
rescale_factor |
The value to use for rescaling.
TYPE:
|
data_format |
The channel dimension format for the output image. If unset, the channel dimension format of the input image is used. Can be one of:
TYPE:
|
input_data_format |
The channel dimension format for the input image. If unset, is inferred from the input image. Can be one of:
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/image_processing_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.image_processing_owlvit.OwlViTImageProcessor.resize(image, size, resample, data_format=None, input_data_format=None, **kwargs)
¶
Resize an image to a certain size.
PARAMETER | DESCRIPTION |
---|---|
image |
Image to resize.
TYPE:
|
size |
The size to resize the image to. Must contain height and width keys.
TYPE:
|
resample |
The resampling filter to use when resizing the input.
TYPE:
|
data_format |
The channel dimension format for the output image. If unset, the channel dimension format of the input image is used.
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/owlvit/image_processing_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.image_processing_owlvit.box_area(boxes)
¶
Computes the area of a set of bounding boxes, which are specified by its (x1, y1, x2, y2) coordinates.
PARAMETER | DESCRIPTION |
---|---|
boxes |
Boxes for which the area will be computed. They are expected to be in (x1, y1, x2, y2) format with
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/transformers/models/owlvit/image_processing_owlvit.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit
¶
MindSpore OwlViT model.
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTAttention
¶
Bases: Module
Multi-headed attention from 'Attention Is All You Need' paper
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
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.owlvit.modeling_owlvit.OwlViTAttention.forward(hidden_states, attention_mask=None, causal_attention_mask=None, output_attentions=False)
¶
Input shape: Batch x Time x Channel
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
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.owlvit.modeling_owlvit.OwlViTEncoder
¶
Bases: Module
Transformer encoder consisting of config.num_hidden_layers
self attention layers. Each layer is a
[OwlViTEncoderLayer
].
PARAMETER | DESCRIPTION |
---|---|
config |
OwlViTConfig
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
704 705 706 707 708 709 710 711 712 713 714 715 716 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 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTEncoder.forward(inputs_embeds, attention_mask=None, causal_attention_mask=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
attention_mask |
Mask to avoid performing attention on padding token indices. Mask values selected in
TYPE:
|
causal_attention_mask |
Causal mask for the text model. Mask values selected in
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers. See
TYPE:
|
output_hidden_states |
Whether or not to return the hidden states of all layers. See
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.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 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTEncoderLayer
¶
Bases: Module
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTEncoderLayer.forward(hidden_states, attention_mask, causal_attention_mask, output_attentions=False)
¶
PARAMETER | DESCRIPTION |
---|---|
hidden_states |
input to the layer of shape
TYPE:
|
attention_mask |
attention mask of size
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers. See
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTForObjectDetection
¶
Bases: OwlViTPreTrainedModel
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTForObjectDetection.box_predictor(image_feats, feature_map)
¶
PARAMETER | DESCRIPTION |
---|---|
image_feats |
Features extracted from the image, returned by the
TYPE:
|
feature_map |
A spatial re-arrangement of image_features, also returned by the
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
pred_boxes
|
List of predicted boxes (cxcywh normalized to 0, 1) nested within a dictionary.
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTForObjectDetection.class_predictor(image_feats, query_embeds=None, query_mask=None)
¶
PARAMETER | DESCRIPTION |
---|---|
image_feats |
Features extracted from the
TYPE:
|
query_embeds |
Text query embeddings.
TYPE:
|
query_mask |
Must be provided with query_embeddings. A mask indicating which query embeddings are valid.
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTForObjectDetection.forward(input_ids, pixel_values, attention_mask=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
OwlViTObjectDetectionOutput
|
|
Example
>>> import requests
>>> from PIL import Image
>>> import torch
>>> from transformers import AutoProcessor, OwlViTForObjectDetection
...
>>> processor = AutoProcessor.from_pretrained("google/owlvit-base-patch32")
>>> model = OwlViTForObjectDetection.from_pretrained("google/owlvit-base-patch32")
...
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> texts = [["a photo of a cat", "a photo of a dog"]]
>>> inputs = processor(text=texts, images=image, return_tensors="pt")
>>> outputs = model(**inputs)
...
>>> # Target image sizes (height, width) to rescale box predictions [batch_size, 2]
>>> target_sizes = ms.Tensor([image.size[::-1]])
>>> # Convert outputs (bounding boxes and class logits) to final bounding boxes and scores
>>> results = processor.post_process_object_detection(
... outputs=outputs, threshold=0.1, target_sizes=target_sizes
... )
...
>>> i = 0 # Retrieve predictions for the first image for the corresponding text queries
>>> text = texts[i]
>>> boxes, scores, labels = results[i]["boxes"], results[i]["scores"], results[i]["labels"]
...
>>> for box, score, label in zip(boxes, scores, labels):
... box = [round(i, 2) for i in box.tolist()]
... print(f"Detected {text[label]} with confidence {round(score.item(), 3)} at location {box}")
Detected a photo of a cat with confidence 0.707 at location [324.97, 20.44, 640.58, 373.29]
Detected a photo of a cat with confidence 0.717 at location [1.46, 55.26, 315.55, 472.17]
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTForObjectDetection.image_guided_detection(pixel_values, query_pixel_values=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
OwlViTImageGuidedObjectDetectionOutput
|
|
Example
>>> import requests
>>> from PIL import Image
>>> import torch
>>> from transformers import AutoProcessor, OwlViTForObjectDetection
...
>>> processor = AutoProcessor.from_pretrained("google/owlvit-base-patch16")
>>> model = OwlViTForObjectDetection.from_pretrained("google/owlvit-base-patch16")
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> query_url = "http://images.cocodataset.org/val2017/000000001675.jpg"
>>> query_image = Image.open(requests.get(query_url, stream=True).raw)
>>> inputs = processor(images=image, query_images=query_image, return_tensors="pt")
>>> with torch.no_grad():
... outputs = model.image_guided_detection(**inputs)
>>> # Target image sizes (height, width) to rescale box predictions [batch_size, 2]
>>> target_sizes = ms.Tensor([image.size[::-1]])
>>> # Convert outputs (bounding boxes and class logits) to Pascal VOC format (xmin, ymin, xmax, ymax)
>>> results = processor.post_process_image_guided_detection(
... outputs=outputs, threshold=0.6, nms_threshold=0.3, target_sizes=target_sizes
... )
>>> i = 0 # Retrieve predictions for the first image
>>> boxes, scores = results[i]["boxes"], results[i]["scores"]
>>> for box, score in zip(boxes, scores):
... box = [round(i, 2) for i in box.tolist()]
... print(f"Detected similar object with confidence {round(score.item(), 3)} at location {box}")
Detected similar object with confidence 0.856 at location [10.94, 50.4, 315.8, 471.39]
Detected similar object with confidence 1.0 at location [334.84, 25.33, 636.16, 374.71]
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTImageGuidedObjectDetectionOutput
dataclass
¶
Bases: ModelOutput
Output type of [OwlViTForObjectDetection.image_guided_detection
].
PARAMETER | DESCRIPTION |
---|---|
logits |
Classification logits (including no-object) for all queries.
TYPE:
|
target_pred_boxes |
Normalized boxes coordinates for all queries, represented as (center_x, center_y, width, height). These
values are normalized in [0, 1], relative to the size of each individual target image in the batch
(disregarding possible padding). You can use [
TYPE:
|
query_pred_boxes |
Normalized boxes coordinates for all queries, represented as (center_x, center_y, width, height). These
values are normalized in [0, 1], relative to the size of each individual query image in the batch
(disregarding possible padding). You can use [
TYPE:
|
image_embeds |
Pooled output of [
TYPE:
|
query_image_embeds |
Pooled output of [
TYPE:
|
class_embeds |
Class embeddings of all image patches. OWL-ViT represents images as a set of image patches where the total number of patches is (image_size / patch_size)**2.
TYPE:
|
text_model_output |
The output of the [
TYPE:
|
vision_model_output |
The output of the [
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTModel
¶
Bases: OwlViTPreTrainedModel
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTModel.forward(input_ids=None, pixel_values=None, attention_mask=None, return_loss=None, output_attentions=None, output_hidden_states=None, return_base_image_embeds=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, OwlViTOutput]
|
|
Example
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, OwlViTModel
...
>>> model = OwlViTModel.from_pretrained("google/owlvit-base-patch32")
>>> processor = AutoProcessor.from_pretrained("google/owlvit-base-patch32")
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> inputs = processor(text=[["a photo of a cat", "a photo of a dog"]], images=image, return_tensors="pt")
>>> outputs = model(**inputs)
>>> logits_per_image = outputs.logits_per_image # this is the image-text similarity score
>>> probs = logits_per_image.softmax(dim=1) # we can take the softmax to get the label probabilities
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTModel.get_image_features(pixel_values=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
image_features
|
The image embeddings obtained by
applying the projection layer to the pooled output of [
TYPE:
|
Example
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, OwlViTModel
...
>>> model = OwlViTModel.from_pretrained("google/owlvit-base-patch32")
>>> processor = AutoProcessor.from_pretrained("google/owlvit-base-patch32")
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> inputs = processor(images=image, return_tensors="pt")
>>> image_features = model.get_image_features(**inputs)
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTModel.get_text_features(input_ids=None, attention_mask=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
text_features
|
The text embeddings obtained by
applying the projection layer to the pooled output of [
TYPE:
|
Example
>>> from transformers import AutoProcessor, OwlViTModel
...
>>> model = OwlViTModel.from_pretrained("google/owlvit-base-patch32")
>>> processor = AutoProcessor.from_pretrained("google/owlvit-base-patch32")
>>> inputs = processor(
... text=[["a photo of a cat", "a photo of a dog"], ["photo of a astranaut"]], return_tensors="pt"
... )
>>> text_features = model.get_text_features(**inputs)
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTObjectDetectionOutput
dataclass
¶
Bases: ModelOutput
Output type of [OwlViTForObjectDetection
].
PARAMETER | DESCRIPTION |
---|---|
loss |
Total loss as a linear combination of a negative log-likehood (cross-entropy) for class prediction and a bounding box loss. The latter is defined as a linear combination of the L1 loss and the generalized scale-invariant IoU loss.
TYPE:
|
loss_dict |
A dictionary containing the individual losses. Useful for logging.
TYPE:
|
logits |
Classification logits (including no-object) for all queries.
TYPE:
|
pred_boxes |
Normalized boxes coordinates for all queries, represented as (center_x, center_y, width, height). These
values are normalized in [0, 1], relative to the size of each individual image in the batch (disregarding
possible padding). You can use [
TYPE:
|
text_embeds |
The text embeddings obtained by applying the projection layer to the pooled output of [
TYPE:
|
image_embeds |
Pooled output of [
TYPE:
|
class_embeds |
Class embeddings of all image patches. OWL-ViT represents images as a set of image patches where the total number of patches is (image_size / patch_size)**2.
TYPE:
|
text_model_output |
The output of the [
TYPE:
|
vision_model_output |
The output of the [
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.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 216 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTOutput
dataclass
¶
Bases: ModelOutput
PARAMETER | DESCRIPTION |
---|---|
loss |
Contrastive loss for image-text similarity.
TYPE:
|
logits_per_image |
The scaled dot product scores between
TYPE:
|
logits_per_text |
The scaled dot product scores between
TYPE:
|
text_embeds |
The text embeddings obtained by applying the projection layer to the pooled output of [
TYPE:
|
image_embeds |
The image embeddings obtained by applying the projection layer to the pooled output of
[
TYPE:
|
text_model_output |
The output of the [
TYPE:
|
vision_model_output |
The output of the [
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTPreTrainedModel
¶
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/owlvit/modeling_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTTextModel
¶
Bases: OwlViTPreTrainedModel
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTTextModel.forward(input_ids, attention_mask=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, BaseModelOutputWithPooling]
|
|
Example
>>> from transformers import AutoProcessor, OwlViTTextModel
...
>>> model = OwlViTTextModel.from_pretrained("google/owlvit-base-patch32")
>>> processor = AutoProcessor.from_pretrained("google/owlvit-base-patch32")
>>> inputs = processor(
... text=[["a photo of a cat", "a photo of a dog"], ["photo of a astranaut"]], return_tensors="pt"
... )
>>> outputs = model(**inputs)
>>> last_hidden_state = outputs.last_hidden_state
>>> pooled_output = outputs.pooler_output # pooled (EOS token) states
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTTextTransformer
¶
Bases: Module
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
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 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTTextTransformer.forward(input_ids, attention_mask=None, position_ids=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, BaseModelOutputWithPooling]
|
|
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
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 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTVisionModel
¶
Bases: OwlViTPreTrainedModel
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTVisionModel.forward(pixel_values=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, BaseModelOutputWithPooling]
|
|
Example
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, OwlViTVisionModel
...
>>> model = OwlViTVisionModel.from_pretrained("google/owlvit-base-patch32")
>>> processor = AutoProcessor.from_pretrained("google/owlvit-base-patch32")
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
...
>>> inputs = processor(images=image, return_tensors="pt")
...
>>> outputs = model(**inputs)
>>> last_hidden_state = outputs.last_hidden_state
>>> pooled_output = outputs.pooler_output # pooled CLS states
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTVisionTransformer
¶
Bases: Module
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.OwlViTVisionTransformer.forward(pixel_values, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, BaseModelOutputWithPooling]
|
|
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.box_area(boxes)
¶
Computes the area of a set of bounding boxes, which are specified by its (x1, y1, x2, y2) coordinates.
PARAMETER | DESCRIPTION |
---|---|
boxes |
Boxes for which the area will be computed. They are expected to be in (x1, y1, x2, y2) format with
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
|
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
mindnlp.transformers.models.owlvit.modeling_owlvit.generalized_box_iou(boxes1, boxes2)
¶
Generalized IoU from https://giou.stanford.edu/. The boxes should be in [x0, y0, x1, y1] (corner) format.
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/transformers/models/owlvit/modeling_owlvit.py
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.owlvit.processing_owlvit
¶
Image/Text processor class for OwlViT
mindnlp.transformers.models.owlvit.processing_owlvit.OwlViTProcessor
¶
Bases: ProcessorMixin
Constructs an OWL-ViT processor which wraps [OwlViTImageProcessor
] and [CLIPTokenizer
]/[CLIPTokenizerFast
]
into a single processor that interits both the image processor and tokenizer functionalities. See the
[~OwlViTProcessor.__call__
] and [~OwlViTProcessor.decode
] for more information.
PARAMETER | DESCRIPTION |
---|---|
image_processor |
The image processor is a required input.
TYPE:
|
tokenizer |
The tokenizer is a required input.
TYPE:
|
Source code in mindnlp/transformers/models/owlvit/processing_owlvit.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 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 |
|
mindnlp.transformers.models.owlvit.processing_owlvit.OwlViTProcessor.__call__(text=None, images=None, query_images=None, padding='max_length', return_tensors='np', **kwargs)
¶
Main method to prepare for the model one or several text(s) and image(s). This method forwards the text
and
kwargs
arguments to CLIPTokenizerFast's [~CLIPTokenizerFast.__call__
] if text
is not None
to encode:
the text. To prepare the image(s), this method forwards the images
and kwrags
arguments to
CLIPImageProcessor's [~CLIPImageProcessor.__call__
] if images
is not None
. Please refer to the doctsring
of the above two methods for more information.
PARAMETER | DESCRIPTION |
---|---|
text |
The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
(pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
TYPE:
|
`List[torch.Tensor]`) |
The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch tensor. Both channels-first and channels-last formats are supported.
|
query_images |
The query image to be prepared, one query image is expected per target image to be queried. Each image can be a PIL image, NumPy array or PyTorch tensor. In case of a NumPy array/PyTorch tensor, each image should be of shape (C, H, W), where C is a number of channels, H and W are image height and width.
TYPE:
|
return_tensors |
If set, will return tensors of a particular framework. Acceptable values are:
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
[
|
Source code in mindnlp/transformers/models/owlvit/processing_owlvit.py
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 |
|
mindnlp.transformers.models.owlvit.processing_owlvit.OwlViTProcessor.batch_decode(*args, **kwargs)
¶
This method forwards all its arguments to CLIPTokenizerFast's [~PreTrainedTokenizer.batch_decode
]. Please
refer to the docstring of this method for more information.
Source code in mindnlp/transformers/models/owlvit/processing_owlvit.py
197 198 199 200 201 202 |
|
mindnlp.transformers.models.owlvit.processing_owlvit.OwlViTProcessor.decode(*args, **kwargs)
¶
This method forwards all its arguments to CLIPTokenizerFast's [~PreTrainedTokenizer.decode
]. Please refer to
the docstring of this method for more information.
Source code in mindnlp/transformers/models/owlvit/processing_owlvit.py
204 205 206 207 208 209 |
|
mindnlp.transformers.models.owlvit.processing_owlvit.OwlViTProcessor.post_process(*args, **kwargs)
¶
This method forwards all its arguments to [OwlViTImageProcessor.post_process
]. Please refer to the docstring
of this method for more information.
Source code in mindnlp/transformers/models/owlvit/processing_owlvit.py
176 177 178 179 180 181 |
|
mindnlp.transformers.models.owlvit.processing_owlvit.OwlViTProcessor.post_process_image_guided_detection(*args, **kwargs)
¶
This method forwards all its arguments to [OwlViTImageProcessor.post_process_one_shot_object_detection
].
Please refer to the docstring of this method for more information.
Source code in mindnlp/transformers/models/owlvit/processing_owlvit.py
190 191 192 193 194 195 |
|
mindnlp.transformers.models.owlvit.processing_owlvit.OwlViTProcessor.post_process_object_detection(*args, **kwargs)
¶
This method forwards all its arguments to [OwlViTImageProcessor.post_process_object_detection
]. Please refer
to the docstring of this method for more information.
Source code in mindnlp/transformers/models/owlvit/processing_owlvit.py
183 184 185 186 187 188 |
|