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:
|
Example
>>> 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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
mindnlp.transformers.models.llava_next.configuration_llava_next.LlavaNextConfig.__init__(vision_config=None, text_config=None, ignore_index=-100, image_token_index=32000, projector_hidden_act='gelu', vision_feature_select_strategy='default', vision_feature_layer=-2, image_grid_pinpoints=None, **kwargs)
¶
This method initializes an instance of the LlavaNextConfig class with the provided parameters.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
vision_config |
Configuration settings for the vision model. If not provided, default settings will be used.
TYPE:
|
text_config |
Configuration settings for the text model. If not provided, default settings will be used.
TYPE:
|
ignore_index |
Index to ignore during computation. Default is -100.
TYPE:
|
image_token_index |
Index for image token. Default is 32000.
TYPE:
|
projector_hidden_act |
Activation function for hidden layers in projector. Default is 'gelu'.
TYPE:
|
vision_feature_select_strategy |
Strategy for selecting vision features. Should be one of 'default' or 'full'.
TYPE:
|
vision_feature_layer |
Layer to extract features from in the vision model.
TYPE:
|
image_grid_pinpoints |
Coordinates for image grid pinpoints. Default is [[336, 672], [672, 336], [672, 672], [1008, 336], [336, 1008].
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If vision_feature_select_strategy is not 'default' or 'full'. |
Source code in mindnlp/transformers/models/llava_next/configuration_llava_next.py
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 |
|
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:
|
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
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.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration
¶
Bases: LlavaNextPreTrainedModel
This class represents a model for conditional text generation with multimodal capabilities. It is designed to generate text based on input text prompts along with associated images. The model utilizes a pre-trained language model for text generation and incorporates image features for enhanced context understanding.
The class provides methods for setting and getting input embeddings, output embeddings, decoder, and for tying weights. It also includes functionality for resizing token embeddings and merging input IDs with image features. Additionally, the class offers a 'forward' method for generating text based on input IDs, pixel values, attention masks, and other optional parameters. The 'prepare_inputs_for_generation' method prepares input data for text generation by handling past key values, inputs embeddings, pixel values, and attention masks.
This class inherits from LlavaNextPreTrainedModel and is designed to be used for conditional text generation tasks in a multimodal setting.
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
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 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 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.__init__(config)
¶
Initializes an instance of the LlavaNextForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object that contains the necessary parameters for setting up the instance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
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 |
|
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)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the masked language modeling loss. Indices should either be in
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, LlavaNextCausalLMOutputWithPast]
|
Union[Tuple, LlavaNextCausalLMOutputWithPast] |
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="pt")
...
>>> # 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
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 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.get_decoder()
¶
Retrieve the decoder from the language model for conditional generation.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaNextForConditionalGeneration class. This parameter is automatically passed when calling the method. |
RETURNS | DESCRIPTION |
---|---|
The decoder obtained from the language model. |
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.get_input_embeddings()
¶
Returns the input embeddings of the language model used for conditional generation.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaNextForConditionalGeneration class. |
RETURNS | DESCRIPTION |
---|---|
The input embeddings of the language model. |
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.get_output_embeddings()
¶
Retrieve the output embeddings from the language model for the LlavaNextForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaNextForConditionalGeneration class.
|
RETURNS | DESCRIPTION |
---|---|
The output embeddings from the language model associated with the LlavaNextForConditionalGeneration instance. |
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.prepare_inputs_for_generation(input_ids, past_key_values=None, inputs_embeds=None, pixel_values=None, image_sizes=None, attention_mask=None, **kwargs)
¶
Prepare the inputs for text generation.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaNextForConditionalGeneration class. |
input_ids |
The input token IDs tensor for text generation.
TYPE:
|
past_key_values |
The cached key values from previous generation steps. If Cache object is passed, cache_length is obtained from it, else from the tuple of Tensors. Defaults to None.
TYPE:
|
inputs_embeds |
The input embeddings tensor. Defaults to None.
TYPE:
|
pixel_values |
The pixel values tensor for image inputs. Defaults to None.
TYPE:
|
image_sizes |
The sizes of the input images. Defaults to None.
TYPE:
|
attention_mask |
The attention mask tensor to mask certain tokens during generation. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
model_inputs
|
A dictionary containing the model inputs for text generation, including 'inputs_embeds', 'input_ids', 'position_ids', 'past_key_values', 'use_cache', 'attention_mask', 'pixel_values', and 'image_sizes'.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If past_key_values is not of type Cache or tuple of Tensors. |
IndexError
|
If the attention_mask shape is not compatible with input_ids shape. |
ValueError
|
If there are inconsistencies in handling input token IDs based on cache and attention mask lengths. |
AttributeError
|
If the image token index is missing in the input_ids. |
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.resize_token_embeddings(new_num_tokens=None, pad_to_multiple_of=None)
¶
Resizes the token embeddings for conditional generation in the LlavaNext model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaNextForConditionalGeneration class. |
new_num_tokens |
The desired number of tokens for the resized embeddings. Defaults to None.
TYPE:
|
pad_to_multiple_of |
(Optional[int]): The value to which the embedding size should be padded. Defaults to None.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Embedding
|
nn.Embedding: The resized token embeddings of type nn.Embedding. |
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.set_decoder(decoder)
¶
Sets the decoder for the LlavaNextForConditionalGeneration language model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaNextForConditionalGeneration class. |
decoder |
The decoder to be set for the language model. It should be compatible with the language model for proper functioning.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.set_input_embeddings(value)
¶
Method to set input embeddings for the LlavaNextForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaNextForConditionalGeneration class. |
value |
The input embeddings to be set for the language model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.set_output_embeddings(new_embeddings)
¶
Sets the output embeddings for the LlavaNextForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the LlavaNextForConditionalGeneration class.
|
new_embeddings |
The new embeddings to be set for the language model. It should be of type 'torch.nn.Embedding' or a subclass of it.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextForConditionalGeneration.tie_weights()
¶
Ties the weights of the language model for conditional generation in the LlavaNextForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the LlavaNextForConditionalGeneration class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
This method is responsible for tying the weights of the language model used for conditional generation in the LlavaNextForConditionalGeneration class. Tying the weights refers to sharing the parameters of the language model with other parts of the model, such as the encoder or the decoder. By tying the weights, the model can learn more efficiently and effectively by reducing the number of parameters that need to be learned.
Note
This method internally calls the 'tie_weights' method of the language model to perform the weight tying operation.
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextMultiModalProjector
¶
Bases: Module
This class represents a multi-modal projector for the LlavaNext model. It is used to project image features and text embeddings into a shared hidden space.
Inherits from
nn.Module
ATTRIBUTE | DESCRIPTION |
---|---|
linear_1 |
A fully connected layer that maps image features to the hidden size specified in the configuration.
TYPE:
|
act |
An activation function chosen based on the configuration's specified projector hidden activation.
TYPE:
|
linear_2 |
A fully connected layer that maps the hidden states from linear_1 to the hidden size specified in the configuration.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
forward |
Projects the given image features into the shared hidden space by applying the linear transformations and activation function. |
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
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 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextMultiModalProjector.__init__(config)
¶
Initializes an instance of the LlavaNextMultiModalProjector class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object of type LlavaNextConfig containing configuration settings for the projector. It is used to set up the linear layers and activation function for the projector.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextMultiModalProjector.forward(image_features)
¶
Constructs the hidden states for the LlavaNextMultiModalProjector.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the LlavaNextMultiModalProjector class. |
image_features |
The input image features to be processed.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method modifies the hidden_states attribute of the LlavaNextMultiModalProjector instance. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input image_features is not a Tensor. |
RuntimeError
|
If an error occurs during the linear transformation or activation function application. |
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
mindnlp.transformers.models.llava_next.modeling_llava_next.LlavaNextPreTrainedModel
¶
Bases: PreTrainedModel
Represents a pre-trained model for the LlavaNext model architecture, inheriting from PreTrainedModel.
This class includes methods for initializing weights based on the configuration settings. It initializes weights for different types of cells such as Dense, Conv2d, and Embedding based on the provided standard deviation value. The initialization process handles class embeddings, biases, and padding indices as needed.
Source code in mindnlp/transformers/models/llava_next/modeling_llava_next.py
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 |
|
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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
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
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 |
|
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 |
|