llava_next
mindnlp.transformers.models.llava_next.configuration_llava_next
¶
Llava-NeXT model configuration
mindnlp.transformers.models.llava_next.configuration_llava_next.LlavaNextConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [LlavaNextForConditionalGeneration]. It is used to instantiate an
Llava-NeXT 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 llava-hf/llava-v1.6-mistral-7b-hf
model.
Configuration objects inherit from [PretrainedConfig] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig] for more information.
| PARAMETER | DESCRIPTION |
|---|---|
vision_config
|
The config object or dictionary of the vision backbone.
TYPE:
|
text_config
|
The config object or dictionary of the text backbone.
TYPE:
|
ignore_index
|
The ignore index for the loss function.
TYPE:
|
image_token_index
|
The image token index to encode the image prompt.
TYPE:
|
projector_hidden_act
|
The activation function used by the multimodal projector.
TYPE:
|
vision_feature_select_strategy
|
The feature selection strategy used to select the vision feature from the vision backbone.
Can be one of
TYPE:
|
vision_feature_layer
|
The index of the layer to select the vision feature.
TYPE:
|
image_grid_pinpoints
|
A list of possible resolutions to use for processing high resolution images. Each item in the list should be a tuple or list
of the form
TYPE:
|
tie_word_embeddings
|
Whether the model's input and output word embeddings should be tied.
TYPE:
|
image_seq_length
|
Sequence length of one image embedding.
TYPE:
|
>>> from transformers import LlavaNextForConditionalGeneration, LlavaNextConfig, CLIPVisionConfig, LlamaConfig
>>> # Initializing a CLIP-vision config
>>> vision_config = CLIPVisionConfig()
>>> # Initializing a Llama config
>>> text_config = LlamaConfig()
>>> # Initializing a Llava-Next llava-hf/llava-v1.6-mistral-7b-hf style configuration
>>> configuration = LlavaNextConfig(vision_config, text_config)
>>> # Initializing a model from the llava-hf/llava-v1.6-mistral-7b-hf style configuration
>>> model = LlavaNextForConditionalGeneration(configuration)
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp\transformers\models\llava_next\configuration_llava_next.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 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.llava_next.modeling_llava_next
¶
MindSpore Llava-NeXT model.
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextCausalLMOutputWithPast
dataclass
¶
Bases: ModelOutput
Base class for LlavaNext causal language model (or autoregressive) outputs.
| PARAMETER | DESCRIPTION |
|---|---|
loss
|
Language modeling loss (for next-token prediction).
TYPE:
|
logits
|
Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
TYPE:
|
past_key_values
|
Tuple of Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
TYPE:
|
hidden_states
|
Tuple of Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
TYPE:
|
attentions
|
Tuple of Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads.
TYPE:
|
image_hidden_states
|
Tuple of image_hidden_states of the model produced by the vision encoder, and optionally by the perceiver
TYPE:
|
Source code in mindnlp\transformers\models\llava_next\modeling_llava_next.py
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 | |
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration
¶
Bases: LlavaNextPreTrainedModel
Source code in mindnlp\transformers\models\llava_next\modeling_llava_next.py
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 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 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 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 | |
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.forward(input_ids=None, pixel_values=None, image_sizes=None, attention_mask=None, position_ids=None, past_key_values=None, inputs_embeds=None, vision_feature_layer=None, vision_feature_select_strategy=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None, cache_position=None, num_logits_to_keep=0)
¶
| PARAMETER | DESCRIPTION |
|---|---|
labels
|
Labels for computing the masked language modeling loss. Indices should either be in
TYPE:
|
num_logits_to_keep
|
Calculate logits for the last
TYPE:
|
Example:
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, LlavaNextForConditionalGeneration
>>> model = LlavaNextForConditionalGeneration.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")
>>> processor = AutoProcessor.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")
>>> prompt = "[INST] <image>\nWhat is shown in this image? [/INST]"
>>> url = "https://www.ilankelman.org/stopsigns/australia.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> inputs = processor(text=prompt, images=image, return_tensors="ms")
>>> # Generate
>>> generate_ids = model.generate(**inputs, max_length=30)
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
"[INST] \nWhat is shown in this image? [/INST] The image appears to be a radar chart, which is a type of multi-dimensional plot (...)"
Source code in mindnlp\transformers\models\llava_next\modeling_llava_next.py
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 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 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 796 797 | |
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.pack_image_features(image_features, image_sizes, image_newline=None)
¶
Reshape, unpad and then pack each image_feature into a single image_features tensor containing all visual vectors.
Source code in mindnlp\transformers\models\llava_next\modeling_llava_next.py
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 | |
mindnlp.transformers.models.llava_next.modeling_llava_next.get_anyres_image_grid_shape(image_size, grid_pinpoints, patch_size)
¶
Calculate the shape of the image patch grid after the preprocessing for images of any resolution.
| PARAMETER | DESCRIPTION |
|---|---|
image_size
|
The size of the input image in the format (width, height).
TYPE:
|
grid_pinpoints
|
A list containing possible resolutions. Each item in the list should be a tuple or list
of the form
TYPE:
|
patch_size
|
The size of each image patch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
The shape of the image patch grid in the format (width, height). |
Source code in mindnlp\transformers\models\llava_next\modeling_llava_next.py
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 | |
mindnlp.transformers.models.llava_next.modeling_llava_next.image_size_to_num_patches(image_size, grid_pinpoints, patch_size)
¶
Calculate the number of patches after the preprocessing for images of any resolution.
| PARAMETER | DESCRIPTION |
|---|---|
image_size
|
The size of the input image in the format (height, width). ?
TYPE:
|
grid_pinpoints
|
A list containing possible resolutions. Each item in the list should be a tuple or list
of the form
TYPE:
|
patch_size
|
The size of each image patch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
the number of patches |
Source code in mindnlp\transformers\models\llava_next\modeling_llava_next.py
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 | |
mindnlp.transformers.models.llava_next.modeling_llava_next.unpad_image(tensor, original_size)
¶
Unpads a PyTorch tensor of a padded and resized image.
| PARAMETER | DESCRIPTION |
|---|---|
tensor
|
The image tensor, assumed to be of shape (num_channels, height, width).
TYPE:
|
original_size
|
The original size of the image (height, width).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in mindnlp\transformers\models\llava_next\modeling_llava_next.py
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 | |
mindnlp.transformers.models.llava_next.processing_llava_next
¶
Processor class for LLaVa-NeXT.
mindnlp.transformers.models.llava_next.processing_llava_next.LlavaNextProcessor
¶
Bases: ProcessorMixin
Constructs a LLaVa-NeXT processor which wraps a LLaVa-NeXT image processor and a LLaMa tokenizer into a single processor.
[LlavaNextProcessor] offers all the functionalities of [LlavaNextImageProcessor] and [LlamaTokenizerFast]. See the
[~LlavaNextProcessor.__call__] and [~LlavaNextProcessor.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\llava_next\processing_llava_next.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 | |
mindnlp.transformers.models.llava_next.processing_llava_next.LlavaNextProcessor.model_input_names
property
¶
Returns a list of model input names used by the LlavaNextProcessor.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the LlavaNextProcessor class.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
This method retrieves the model input names from the tokenizer and image processor of the LlavaNextProcessor. It concatenates the tokenizer input names and image processor input names, and removes any duplicate entries using a dictionary conversion. The resulting list of model input names is returned.
mindnlp.transformers.models.llava_next.processing_llava_next.LlavaNextProcessor.__call__(text, images=None, padding=False, truncation=None, max_length=None, return_tensors=None)
¶
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the text
and kwargs arguments to LlamaTokenizerFast's [~LlamaTokenizerFast.__call__] if text is not None to encode
the text. To prepare the image(s), this method forwards the images and kwrags arguments to
LlavaNextImageProcessor's [~LlavaNextImageProcessor.__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:
|
images
|
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.
TYPE:
|
padding
|
Select a strategy to pad the returned sequences (according to the model's padding side and padding index) among:
TYPE:
|
max_length
|
Maximum length of the returned list and optionally padding length (see above).
TYPE:
|
truncation
|
Activates truncation to cut input sequences longer than
TYPE:
|
return_tensors
|
If set, will return tensors of a particular framework. Acceptable values are:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BatchFeature
|
[
|
Source code in mindnlp\transformers\models\llava_next\processing_llava_next.py
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 | |
mindnlp.transformers.models.llava_next.processing_llava_next.LlavaNextProcessor.__init__(image_processor=None, tokenizer=None)
¶
Initializes a new instance of the LlavaNextProcessor class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the class itself.
TYPE:
|
image_processor
|
An image processing object. Defaults to None.
TYPE:
|
tokenizer
|
A tokenizer object. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\llava_next\processing_llava_next.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
mindnlp.transformers.models.llava_next.processing_llava_next.LlavaNextProcessor.batch_decode(*args, **kwargs)
¶
This method forwards all its arguments to LlamaTokenizerFast's [~PreTrainedTokenizer.batch_decode]. Please
refer to the docstring of this method for more information.
Source code in mindnlp\transformers\models\llava_next\processing_llava_next.py
131 132 133 134 135 136 | |
mindnlp.transformers.models.llava_next.processing_llava_next.LlavaNextProcessor.decode(*args, **kwargs)
¶
This method forwards all its arguments to LlamaTokenizerFast's [~PreTrainedTokenizer.decode]. Please refer to
the docstring of this method for more information.
Source code in mindnlp\transformers\models\llava_next\processing_llava_next.py
139 140 141 142 143 144 | |
mindnlp.transformers.models.llava_next.image_processing_llava_next
¶
Image processor class for LLaVa-NeXT.
mindnlp.transformers.models.llava_next.image_processing_llava_next.LlavaNextImageProcessor
¶
Bases: BaseImageProcessor
Constructs a LLaVa-NeXT image processor. Based on [CLIPImageProcessor] with incorporation of additional techniques
for processing high resolution images as explained in the LLaVa paper.
| PARAMETER | DESCRIPTION |
|---|---|
do_resize
|
Whether to resize the image's (height, width) dimensions to the specified
TYPE:
|
size
|
224}
TYPE:
|
image_grid_pinpoints
|
A list of possible resolutions to use for processing high resolution images. The best resolution is selected
based on the original size of the image. Can be overridden by
TYPE:
|
resample
|
Resampling filter to use if resizing the image. Can be overridden by
TYPE:
|
do_center_crop
|
Whether to center crop the image to the specified
TYPE:
|
crop_size
|
Size of the output image after applying
TYPE:
|
do_rescale
|
Whether to rescale the image by the specified scale
TYPE:
|
rescale_factor
|
Scale factor to use if rescaling the image. Can be overridden by
TYPE:
|
do_normalize
|
Whether to normalize the image. Can be overridden by
TYPE:
|
image_mean
|
Mean to use if normalizing the image. This is a float or list of floats the length of the number of
channels in the image. Can be overridden by the
TYPE:
|
image_std
|
Standard deviation to use if normalizing the image. This is a float or list of floats the length of the
number of channels in the image. Can be overridden by the
TYPE:
|
do_convert_rgb
|
Whether to convert the image to RGB.
TYPE:
|
Source code in mindnlp\transformers\models\llava_next\image_processing_llava_next.py
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 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
mindnlp.transformers.models.llava_next.image_processing_llava_next.LlavaNextImageProcessor.__init__(do_resize=True, size=None, image_grid_pinpoints=None, resample=PILImageResampling.BICUBIC, do_center_crop=True, crop_size=None, do_rescale=True, rescale_factor=1 / 255, do_normalize=True, image_mean=None, image_std=None, do_convert_rgb=True, **kwargs)
¶
init
Initializes an instance of the LlavaNextImageProcessor class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the class.
|
do_resize
|
Flag to indicate whether resizing should be performed. Defaults to True.
TYPE:
|
size
|
Dictionary specifying the size of the image. Defaults to None.
TYPE:
|
image_grid_pinpoints
|
List of points for image grid pinpoints. Defaults to None.
TYPE:
|
resample
|
Resampling method for image resizing. Defaults to PILImageResampling.BICUBIC.
TYPE:
|
do_center_crop
|
Flag to indicate whether center cropping should be performed. Defaults to True.
TYPE:
|
crop_size
|
Dictionary specifying the crop size. Defaults to None.
TYPE:
|
do_rescale
|
Flag to indicate whether rescaling should be performed. Defaults to True.
TYPE:
|
rescale_factor
|
Factor used for rescaling the image. Defaults to 1/255.
TYPE:
|
do_normalize
|
Flag to indicate whether normalization should be performed. Defaults to True.
TYPE:
|
image_mean
|
Mean value for image normalization. Defaults to None or OPENAI_CLIP_MEAN.
TYPE:
|
image_std
|
Standard deviation value for image normalization. Defaults to None or OPENAI_CLIP_STD.
TYPE:
|
do_convert_rgb
|
Flag to indicate whether RGB conversion should be performed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If invalid parameters are provided or if the rescale_factor is not a valid number. |
TypeError
|
If the types of input parameters are incorrect. |
Source code in mindnlp\transformers\models\llava_next\image_processing_llava_next.py
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 | |
mindnlp.transformers.models.llava_next.image_processing_llava_next.LlavaNextImageProcessor.get_image_patches(image, grid_pinpoints, size, patch_size, resample, data_format, input_data_format)
¶
Process an image with variable resolutions by dividing it into patches.
| PARAMETER | DESCRIPTION |
|---|---|
image
|
The input image to be processed.
TYPE:
|
grid_pinpoints
|
A string representation of a list of possible resolutions.
TYPE:
|
size
|
Size to resize the original image to.
TYPE:
|
patch_size
|
Size of the patches to divide the image into.
TYPE:
|
resample
|
Resampling filter to use if resizing the image.
TYPE:
|
data_format
|
The channel dimension format for the output image.
TYPE:
|
input_data_format
|
The channel dimension format of the input image.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[array]
|
List[np.array]: A list of NumPy arrays containing the processed image patches. |
Source code in mindnlp\transformers\models\llava_next\image_processing_llava_next.py
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 | |
mindnlp.transformers.models.llava_next.image_processing_llava_next.LlavaNextImageProcessor.preprocess(images, do_resize=None, size=None, image_grid_pinpoints=None, resample=None, do_center_crop=None, crop_size=None, do_rescale=None, rescale_factor=None, do_normalize=None, image_mean=None, image_std=None, do_convert_rgb=None, return_tensors=None, data_format=ChannelDimension.FIRST, input_data_format=None)
¶
| PARAMETER | DESCRIPTION |
|---|---|
images
|
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set
TYPE:
|
do_resize
|
Whether to resize the image.
TYPE:
|
size
|
Size of the image after resizing. Shortest edge of the image is resized to size["shortest_edge"], with the longest edge resized to keep the input aspect ratio.
TYPE:
|
image_grid_pinpoints
|
A list of possible resolutions to use for processing high resolution images. The best resolution is selected based on the original size of the image.
TYPE:
|
resample
|
Resampling filter to use if resizing the image. This can be one of the enum
TYPE:
|
do_center_crop
|
Whether to center crop the image.
TYPE:
|
crop_size
|
Size of the center crop. Only has an effect if
TYPE:
|
do_rescale
|
Whether to rescale the image.
TYPE:
|
rescale_factor
|
Rescale factor to rescale the image by if
TYPE:
|
do_normalize
|
Whether to normalize the image.
TYPE:
|
image_mean
|
Image mean to use for normalization. Only has an effect if
TYPE:
|
image_std
|
Image standard deviation to use for normalization. Only has an effect if
TYPE:
|
do_convert_rgb
|
Whether to convert the image to RGB.
TYPE:
|
return_tensors
|
The type of tensors to return. Can be one of:
TYPE:
|
data_format
|
The channel dimension format for the output image. Can be one of:
TYPE:
|
input_data_format
|
The channel dimension format for the input image. If unset, the channel dimension format is inferred from the input image. Can be one of:
TYPE:
|
Source code in mindnlp\transformers\models\llava_next\image_processing_llava_next.py
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 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
mindnlp.transformers.models.llava_next.image_processing_llava_next.LlavaNextImageProcessor.resize(image, size, resample=PILImageResampling.BICUBIC, data_format=None, input_data_format=None, **kwargs)
¶
Resize an image. The shortest edge of the image is resized to size["shortest_edge"], with the longest edge resized to keep the input aspect ratio.
| PARAMETER | DESCRIPTION |
|---|---|
image
|
Image to resize.
TYPE:
|
size
|
Size of the output image.
TYPE:
|
resample
|
Resampling filter to use when resiizing the image.
TYPE:
|
data_format
|
The channel dimension format of the image. If not provided, it will be the same as the input image.
TYPE:
|
input_data_format
|
The channel dimension format of the input image. If not provided, it will be inferred.
TYPE:
|
Source code in mindnlp\transformers\models\llava_next\image_processing_llava_next.py
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 | |
mindnlp.transformers.models.llava_next.image_processing_llava_next.divide_to_patches(image, patch_size, input_data_format)
¶
Divides an image into patches of a specified size.
| PARAMETER | DESCRIPTION |
|---|---|
image
|
The input image.
TYPE:
|
patch_size
|
The size of each patch.
TYPE:
|
input_data_format
|
The channel dimension format of the input image.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list
|
A list of np.array representing the patches.
TYPE:
|
Source code in mindnlp\transformers\models\llava_next\image_processing_llava_next.py
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 | |
mindnlp.transformers.models.llava_next.image_processing_llava_next.expand_to_square(image, background_color, input_data_format)
¶
Expands an image to a square by adding a background color.
Source code in mindnlp\transformers\models\llava_next\image_processing_llava_next.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |