seggpt
mindnlp.transformers.models.seggpt.configuration_seggpt
¶
SegGpt model configuration
mindnlp.transformers.models.seggpt.configuration_seggpt.SegGptConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [SegGptModel
]. It is used to instantiate a SegGPT
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 SegGPT
BAAI/seggpt-vit-large architecture.
Configuration objects inherit from [PretrainedConfig
] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig
] for more information.
PARAMETER | DESCRIPTION |
---|---|
hidden_size |
Dimensionality of the encoder layers and the pooler layer.
TYPE:
|
num_hidden_layers |
Number of hidden layers in the Transformer encoder.
TYPE:
|
num_attention_heads |
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
hidden_act |
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
hidden_dropout_prob |
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
TYPE:
|
initializer_range |
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
layer_norm_eps |
The epsilon used by the layer normalization layers.
TYPE:
|
image_size |
The size (resolution) of each image.
TYPE:
|
patch_size |
The size (resolution) of each patch.
TYPE:
|
num_channels |
The number of input channels.
TYPE:
|
qkv_bias |
Whether to add a bias to the queries, keys and values.
TYPE:
|
mlp_dim |
The dimensionality of the MLP layer in the Transformer encoder. If unset, defaults to
TYPE:
|
drop_path_rate |
The drop path rate for the dropout layers.
TYPE:
|
pretrain_image_size |
The pretrained size of the absolute position embeddings.
TYPE:
|
decoder_hidden_size |
Hidden size for decoder.
TYPE:
|
use_relative_position_embeddings |
Whether to use relative position embeddings in the attention layers.
TYPE:
|
merge_index |
The index of the encoder layer to merge the embeddings.
TYPE:
|
intermediate_hidden_state_indices |
The indices of the encoder layers which we store as features for the decoder.
TYPE:
|
beta |
Regularization factor for SegGptLoss (smooth-l1 loss).
TYPE:
|
Example
>>> from transformers import SegGptConfig, SegGptModel
...
>>> # Initializing a SegGPT seggpt-vit-large style configuration
>>> configuration = SegGptConfig()
...
>>> # Initializing a model (with random weights) from the seggpt-vit-large style configuration
>>> model = SegGptModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/seggpt/configuration_seggpt.py
20 21 22 23 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 |
|
mindnlp.transformers.models.seggpt.image_processing_seggpt
¶
Image processor class for SegGPT.
mindnlp.transformers.models.seggpt.image_processing_seggpt.SegGptImageProcessor
¶
Bases: BaseImageProcessor
Constructs a SegGpt image processor.
PARAMETER | DESCRIPTION |
---|---|
do_resize |
Whether to resize the image's (height, width) dimensions to the specified
TYPE:
|
size |
Size of the output image after resizing. Can be overridden by the
TYPE:
|
resample |
Resampling filter to use if resizing the image. Can be overridden by the
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 the
TYPE:
|
do_normalize |
Whether to normalize the image. Can be overridden by the
TYPE:
|
image_mean |
Mean to use if normalizing the image. This is a float or list of floats the length of the number of
channels in the image. Can be overridden by the
TYPE:
|
image_std |
Standard deviation to use if normalizing the image. This is a float or list of floats the length of the
number of channels in the image. Can be overridden by the
TYPE:
|
do_convert_rgb |
Whether to convert the prompt mask to RGB format. Can be overridden by the
TYPE:
|
Source code in mindnlp/transformers/models/seggpt/image_processing_seggpt.py
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.seggpt.image_processing_seggpt.SegGptImageProcessor.get_palette(num_labels)
¶
Build a palette to map the prompt mask from a single channel to a 3 channel RGB.
PARAMETER | DESCRIPTION |
---|---|
num_labels |
Number of classes in the segmentation task (excluding the background).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Tuple[int, int]]
|
|
Source code in mindnlp/transformers/models/seggpt/image_processing_seggpt.py
160 161 162 163 164 165 166 167 168 169 170 |
|
mindnlp.transformers.models.seggpt.image_processing_seggpt.SegGptImageProcessor.mask_to_rgb(image, palette=None, data_format=None)
¶
Converts a segmentation map to RGB format.
PARAMETER | DESCRIPTION |
---|---|
image |
Segmentation map with dimensions (height, width) where pixel values represent the class index.
TYPE:
|
palette |
Palette to use to convert the mask to RGB format. If unset, the mask is duplicated across the channel dimension.
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:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
|
Source code in mindnlp/transformers/models/seggpt/image_processing_seggpt.py
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 |
|
mindnlp.transformers.models.seggpt.image_processing_seggpt.SegGptImageProcessor.post_process_semantic_segmentation(outputs, target_sizes=None, num_labels=None)
¶
Converts the output of [SegGptImageSegmentationOutput
] into segmentation maps. Only supports
PyTorch.
PARAMETER | DESCRIPTION |
---|---|
outputs |
Raw outputs of the model.
TYPE:
|
target_sizes |
List of length (batch_size), where each list item (
TYPE:
|
num_labels |
Number of classes in the segmentation task (excluding the background). If specified, a palette will be built, assuming that class_idx 0 is the background, to map prediction masks from RGB values to class indices. This value should be the same used when preprocessing inputs.
TYPE:
|
Source code in mindnlp/transformers/models/seggpt/image_processing_seggpt.py
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.seggpt.image_processing_seggpt.SegGptImageProcessor.preprocess(images=None, prompt_images=None, prompt_masks=None, do_resize=None, size=None, resample=None, do_rescale=None, rescale_factor=None, do_normalize=None, image_mean=None, image_std=None, do_convert_rgb=None, num_labels=None, return_tensors=None, data_format=ChannelDimension.FIRST, input_data_format=None, **kwargs)
¶
Preprocess an image or batch of images.
PARAMETER | DESCRIPTION |
---|---|
images |
Image to _preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set
TYPE:
|
prompt_images |
Prompt 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:
|
prompt_masks |
Prompt mask from prompt image to _preprocess that specify prompt_masks value in the preprocessed output. Can either be in the format of segmentation maps (no channels) or RGB images.
TYPE:
|
do_resize |
Whether to resize the image.
TYPE:
|
size |
Dictionary in the format
TYPE:
|
resample |
TYPE:
|
do_rescale |
Whether to rescale the image values between [0 - 1].
TYPE:
|
rescale_factor |
Rescale factor to rescale the image by if
TYPE:
|
do_normalize |
Whether to normalize the image.
TYPE:
|
image_mean |
Image mean to use if
TYPE:
|
image_std |
Image standard deviation to use if
TYPE:
|
do_convert_rgb |
Whether to convert the prompt mask to RGB format. If
TYPE:
|
num_labels |
(
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/seggpt/image_processing_seggpt.py
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 |
|
mindnlp.transformers.models.seggpt.image_processing_seggpt.SegGptImageProcessor.resize(image, size, resample=PILImageResampling.BICUBIC, data_format=None, input_data_format=None, **kwargs)
¶
Resize an image to (size["height"], size["width"])
.
PARAMETER | DESCRIPTION |
---|---|
image |
Image to resize.
TYPE:
|
size |
Dictionary in the format
TYPE:
|
resample |
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, the channel dimension format is inferred from the input image. Can be one of:
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
|
Source code in mindnlp/transformers/models/seggpt/image_processing_seggpt.py
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 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt
¶
MindSpore SegGpt model.
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptAttention
¶
Bases: Module
Multi-head Attention block with relative position embeddings.
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
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 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptAttention.add_decomposed_rel_pos(attn, query, rel_pos_h, rel_pos_w, q_size, k_size)
¶
Calculate decomposed Relative Positional Embeddings from :paper:mvitv2
.
https://github.com/facebookresearch/mvit/blob/19786631e330df9f3622e5402b4a419a263a2c80/mvit/models/attention.py
PARAMETER | DESCRIPTION |
---|---|
attn |
attention map.
TYPE:
|
query |
query q in the attention layer with shape (batch_size, query_height * query_width, channel).
TYPE:
|
rel_pos_h |
relative position embeddings (Lh, channel) for height axis.
TYPE:
|
rel_pos_w |
relative position embeddings (Lw, channel) for width axis.
TYPE:
|
q_size |
spatial sequence size of query q with (query_height, query_width).
TYPE:
|
k_size |
spatial sequence size of key k with (key_height, key_width).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
attn
|
attention map with added relative positional embeddings.
TYPE:
|
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
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 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptAttention.get_rel_pos(q_size, k_size, rel_pos)
¶
Get relative positional embeddings according to the relative positions of query and key sizes.
PARAMETER | DESCRIPTION |
---|---|
q_size |
size of the query.
TYPE:
|
k_size |
size of key k.
TYPE:
|
rel_pos |
relative position embeddings (L, channel).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Extracted positional embeddings according to relative positions. |
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
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 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptDropPath
¶
Bases: Module
Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
431 432 433 434 435 436 437 438 439 440 441 442 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptEmbeddings
¶
Bases: Module
Construct the embeddings from patch, position embeddings for input and prompt.
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
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.seggpt.modeling_seggpt.SegGptEncoderOutput
dataclass
¶
Bases: ModelOutput
Output type of [SegGptEncoderOutput
].
PARAMETER | DESCRIPTION |
---|---|
last_hidden_state |
Sequence of hidden-states at the output of the last layer of the model.
TYPE:
|
hidden_states |
Tuple of
TYPE:
|
attentions |
Tuple of ms.Tensor (one for each layer) of shape
TYPE:
|
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
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 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptForImageSegmentation
¶
Bases: SegGptPreTrainedModel
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
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 925 926 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 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptForImageSegmentation.forward(pixel_values, prompt_pixel_values, prompt_masks, bool_masked_pos=None, feature_ensemble=None, embedding_type=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Ground truth mask for input images.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, SegGptImageSegmentationOutput]
|
|
Example
>>> from transformers import SegGptImageProcessor, SegGptForImageSegmentation
>>> from PIL import Image
>>> import requests
...
>>> image_input_url = "https://raw.githubusercontent.com/baaivision/Painter/main/SegGPT/SegGPT_inference/examples/hmbb_2.jpg"
>>> image_prompt_url = "https://raw.githubusercontent.com/baaivision/Painter/main/SegGPT/SegGPT_inference/examples/hmbb_1.jpg"
>>> mask_prompt_url = "https://raw.githubusercontent.com/baaivision/Painter/main/SegGPT/SegGPT_inference/examples/hmbb_1_target.png"
...
>>> image_input = Image.open(requests.get(image_input_url, stream=True).raw)
>>> image_prompt = Image.open(requests.get(image_prompt_url, stream=True).raw)
>>> mask_prompt = Image.open(requests.get(mask_prompt_url, stream=True).raw).convert("L")
...
>>> checkpoint = "BAAI/seggpt-vit-large"
>>> model = SegGptForImageSegmentation.from_pretrained(checkpoint)
>>> image_processor = SegGptImageProcessor.from_pretrained(checkpoint)
...
>>> inputs = image_processor(images=image_input, prompt_images=image_prompt, prompt_masks=mask_prompt, return_tensors="pt")
>>> outputs = model(**inputs)
>>> result = image_processor.post_process_semantic_segmentation(outputs, target_sizes=[image_input.size[::-1]])[0]
>>> print(list(result.shape))
[170, 297]
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 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 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptImageSegmentationOutput
dataclass
¶
Bases: ModelOutput
Output type of [SegGptImageSegmentationOutput
].
PARAMETER | DESCRIPTION |
---|---|
loss |
The loss value.
TYPE:
|
pred_masks |
The predicted masks.
TYPE:
|
hidden_states |
Tuple of
TYPE:
|
attentions |
Tuple of
TYPE:
|
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptLayerNorm
¶
Bases: Module
LayerNorm that supports two data formats: channels_last (default) or channels_first. The ordering of the dimensions in the inputs. channels_last corresponds to inputs with shape (batch_size, height, width, channels) while channels_first corresponds to inputs with shape (batch_size, channels, height, width).
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.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 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptLoss
¶
Bases: Module
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptLoss.forward(prompt_masks, pred_masks, labels, bool_masked_pos)
¶
Computes the L1 loss between the predicted masks and the ground truth masks.
PARAMETER | DESCRIPTION |
---|---|
prompt_masks |
Pixel values from mask prompt.
TYPE:
|
pred_masks |
Predicted masks.
TYPE:
|
labels |
Ground truth mask for input images.
TYPE:
|
bool_masked_pos |
Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptModel
¶
Bases: SegGptPreTrainedModel
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
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 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptModel.forward(pixel_values, prompt_pixel_values, prompt_masks, bool_masked_pos=None, feature_ensemble=None, embedding_type=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Ground truth mask for input images.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, SegGptEncoderOutput]
|
|
Example
>>> from transformers import SegGptImageProcessor, SegGptModel
>>> from PIL import Image
>>> import requests
...
>>> image_input_url = "https://raw.githubusercontent.com/baaivision/Painter/main/SegGPT/SegGPT_inference/examples/hmbb_2.jpg"
>>> image_prompt_url = "https://raw.githubusercontent.com/baaivision/Painter/main/SegGPT/SegGPT_inference/examples/hmbb_1.jpg"
>>> mask_prompt_url = "https://raw.githubusercontent.com/baaivision/Painter/main/SegGPT/SegGPT_inference/examples/hmbb_1_target.png"
...
>>> image_input = Image.open(requests.get(image_input_url, stream=True).raw)
>>> image_prompt = Image.open(requests.get(image_prompt_url, stream=True).raw)
>>> mask_prompt = Image.open(requests.get(mask_prompt_url, stream=True).raw).convert("L")
...
>>> checkpoint = "BAAI/seggpt-vit-large"
>>> model = SegGptModel.from_pretrained(checkpoint)
>>> image_processor = SegGptImageProcessor.from_pretrained(checkpoint)
...
>>> inputs = image_processor(images=image_input, prompt_images=image_prompt, prompt_masks=mask_prompt, return_tensors="pt")
...
>>> outputs = model(**inputs)
>>> list(outputs.last_hidden_state.shape)
[1, 56, 28, 1024]
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
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 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptPatchEmbeddings
¶
Bases: Module
This class turns pixel_values
of shape (batch_size, num_channels, height, width)
into the initial
hidden_states
(patch embeddings) of shape (batch_size, seq_length, hidden_size)
to be consumed by a
Transformer.
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.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 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.SegGptPreTrainedModel
¶
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/seggpt/modeling_seggpt.py
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 |
|
mindnlp.transformers.models.seggpt.modeling_seggpt.drop_path(input, drop_prob=0.0, training=False)
¶
Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
Comment by Ross Wightman: This is the same as the DropConnect impl I created for EfficientNet, etc networks, however, the original name is misleading as 'Drop Connect' is a different form of dropout in a separate paper... See discussion: https://github.com/tensorflow/tpu/issues/494#issuecomment-532968956 ... I've opted for changing the layer and argument names to 'drop path' rather than mix DropConnect as a layer name and use 'survival rate' as the argument.
Source code in mindnlp/transformers/models/seggpt/modeling_seggpt.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
|